feat: expose graceful drain state

This commit is contained in:
2026-09-20 20:15:36 +08:00
parent 9153ddf85f
commit 99e2a00fcf
6 changed files with 22 additions and 2 deletions

View File

@@ -29,6 +29,7 @@ func catalog() map[string]descriptor {
"orbit_runtime_batch_last_success_timestamp_seconds": {gauge, "Unix time of last successful background batch, zero before first success", map[string][]string{"component": components}},
"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_process_draining": {gauge, "Whether this process is draining for graceful shutdown", nil},
"orbit_go_goroutines": {gauge, "Current Go goroutine count", nil},
"orbit_build_info": {gauge, "Orbit build and protocol information", map[string][]string{"go_version": {build.GoVersion}, "version": {build.Version}, "revision": {build.Revision}}},
}

View File

@@ -97,6 +97,7 @@ func TestInvalidNumbersAndMonotoneCounters(t *testing.T) {
func TestRuntimeObservationDoesNotExposeErrors(t *testing.T) {
r := NewRegistry()
r.RecordRuntimeConfig(RuntimeConfig{WorkflowTickInterval: time.Second, ScheduleTickInterval: 1500 * time.Millisecond, RecoveryTickInterval: 2 * time.Second, BatchLimit: 37, ShutdownTimeout: 45 * time.Second})
r.RecordDraining(true)
r.RecordBatch("workflow", time.Now().Add(-time.Millisecond), nil)
r.RecordBatch("workflow", time.Now(), errors.New("private-dsn"))
r.RecordBatch("schedule", time.Now(), context.Canceled)
@@ -107,7 +108,7 @@ func TestRuntimeObservationDoesNotExposeErrors(t *testing.T) {
t.Fatal("missing runtime evidence", want)
}
}
for _, want := range []string{`orbit_runtime_tick_interval_seconds{component="workflow"} 1`, `orbit_runtime_tick_interval_seconds{component="schedule"} 1.5`, `orbit_runtime_tick_interval_seconds{component="execution_recovery"} 2`, "orbit_runtime_batch_limit 37\n", "orbit_shutdown_timeout_seconds 45\n"} {
for _, want := range []string{`orbit_runtime_tick_interval_seconds{component="workflow"} 1`, `orbit_runtime_tick_interval_seconds{component="schedule"} 1.5`, `orbit_runtime_tick_interval_seconds{component="execution_recovery"} 2`, "orbit_runtime_batch_limit 37\n", "orbit_shutdown_timeout_seconds 45\n", "orbit_process_draining 1\n"} {
if !strings.Contains(out, want) {
t.Fatal("missing runtime configuration", want)
}

View File

@@ -32,12 +32,26 @@ func (r *Registry) RecordRuntimeConfig(config RuntimeConfig) {
r.SetGauge("orbit_shutdown_timeout_seconds", config.ShutdownTimeout.Seconds(), nil)
}
// RecordDraining records whether this process has entered graceful shutdown.
// The value is a fixed, node-local gauge: 0 means serving and 1 means draining.
func (r *Registry) RecordDraining(draining bool) {
if r == nil {
return
}
value := 0.0
if draining {
value = 1
}
r.SetGauge("orbit_process_draining", value, nil)
}
// initializeProcess is called once by the registry constructor.
func (r *Registry) initializeProcess() {
if r == nil {
return
}
r.SetGauge("orbit_process_start_time_seconds", float64(r.started.Unix()), nil)
r.RecordDraining(false)
build := buildinfo.Current()
r.SetGauge("orbit_build_info", 1, Labels{"go_version": build.GoVersion, "version": build.Version, "revision": build.Revision})
r.RecordProcess()