feat: label build identity in metrics
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package observability
|
||||
|
||||
import "runtime"
|
||||
import "git.yuntuo.hk/k2safe/orbit/internal/buildinfo"
|
||||
|
||||
var methods = []string{"GET", "POST", "PATCH", "PUT", "DELETE", "HEAD", "OPTIONS", "OTHER"}
|
||||
var routes = []string{"health_live", "health_ready", "worker_connect", "event_connect", "tasks", "queues", "workflows", "workflow_definitions", "schedules", "subscriptions", "application_resources", "other"}
|
||||
@@ -16,6 +16,7 @@ var eventTypes = []string{"task.accepted", "task.started", "task.succeeded", "ta
|
||||
// Adding a metric therefore requires a code review; no user identifier is valid.
|
||||
func catalog() map[string]descriptor {
|
||||
httpLabels := map[string][]string{"method": methods, "route": routes, "status_class": statusClasses}
|
||||
build := buildinfo.Current()
|
||||
c := map[string]descriptor{
|
||||
"orbit_http_requests_total": {counter, "Completed HTTP responses, including successful upgrade handshakes", httpLabels},
|
||||
"orbit_http_request_duration_seconds": {histogram, "HTTP response or upgrade handshake duration in seconds", httpLabels},
|
||||
@@ -29,7 +30,7 @@ func catalog() map[string]descriptor {
|
||||
"orbit_process_start_time_seconds": {gauge, "Unix time when the Orbit metrics registry was started", nil},
|
||||
"orbit_process_uptime_seconds": {gauge, "Monotonic elapsed time since metrics registry startup", nil},
|
||||
"orbit_go_goroutines": {gauge, "Current Go goroutine count", nil},
|
||||
"orbit_build_info": {gauge, "Orbit Go runtime build information", map[string][]string{"go_version": {runtime.Version()}}},
|
||||
"orbit_build_info": {gauge, "Orbit build and protocol information", map[string][]string{"go_version": {build.GoVersion}, "version": {build.Version}, "revision": {build.Revision}}},
|
||||
}
|
||||
for name, help := range map[string]string{
|
||||
"open": "Open MySQL connections", "in_use": "MySQL connections currently in use", "idle": "Idle MySQL connections", "max_open": "Configured maximum open MySQL connections",
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -105,6 +106,9 @@ func TestRuntimeObservationDoesNotExposeErrors(t *testing.T) {
|
||||
t.Fatal("missing runtime evidence", want)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(out, `orbit_build_info{go_version="`+runtime.Version()+`",revision="unknown",version="dev"} 1`) {
|
||||
t.Fatal("missing build identity")
|
||||
}
|
||||
if strings.Contains(out, "private-dsn") {
|
||||
t.Fatal("error data leaked")
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"errors"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"git.yuntuo.hk/k2safe/orbit/internal/buildinfo"
|
||||
)
|
||||
|
||||
// initializeProcess is called once by the registry constructor.
|
||||
@@ -14,7 +16,8 @@ func (r *Registry) initializeProcess() {
|
||||
return
|
||||
}
|
||||
r.SetGauge("orbit_process_start_time_seconds", float64(r.started.Unix()), nil)
|
||||
r.SetGauge("orbit_build_info", 1, Labels{"go_version": runtime.Version()})
|
||||
build := buildinfo.Current()
|
||||
r.SetGauge("orbit_build_info", 1, Labels{"go_version": build.GoVersion, "version": build.Version, "revision": build.Revision})
|
||||
r.RecordProcess()
|
||||
for _, component := range components {
|
||||
labels := Labels{"component": component}
|
||||
|
||||
Reference in New Issue
Block a user