feat: label build identity in metrics
This commit is contained in:
@@ -67,7 +67,7 @@ curl -fsS http://127.0.0.1:9090/metrics
|
||||
| `orbit_business_snapshot_truncated` | gauge | 任一固定状态达到10000上限时为1,否则为0 |
|
||||
| `orbit_process_start_time_seconds` / `orbit_process_uptime_seconds` | gauge | 本次指标注册器初始化Unix时间/单调时钟经过的秒数;初始化发生在数据库启动校验之后 |
|
||||
| `orbit_go_goroutines` | gauge | Go协程数,按5秒采样 |
|
||||
| `orbit_build_info` | gauge | 恒为1,go_version仅取当前编译运行时版本;不是Orbit发布版本 |
|
||||
| `orbit_build_info{go_version,version,revision}` | gauge | 恒为1,导出当前Go版本、发布版本和源码提交;构建时间及完整协议身份通过 `/version` 获取 |
|
||||
| `orbit_observability_rejected_samples_total` | counter | 内部不合法指标更新次数,正常运行应为0 |
|
||||
|
||||
HTTP方法为GET/POST/PATCH/PUT/DELETE/HEAD/OPTIONS/OTHER;路由为health_live、health_ready、worker_connect、event_connect、tasks、queues、workflows、workflow_definitions、schedules、subscriptions、application_resources、other;状态为1xx–5xx及other。路径值不会进入标签;分类不表示路由存在或授权通过。独立采集请求不混入业务HTTP计数。
|
||||
|
||||
@@ -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