feat: add bounded business state observability

This commit is contained in:
2026-09-18 20:44:41 +08:00
parent bea8efa790
commit 5284206731
18 changed files with 450 additions and 12 deletions

View File

@@ -112,6 +112,42 @@ func TestRuntimeObservationDoesNotExposeErrors(t *testing.T) {
disabled.RecordBatch("workflow", time.Now(), nil)
disabled.RecordDatabase(sql.DBStats{})
}
func TestBusinessSnapshotKeepsLastGoodStateOnFailure(t *testing.T) {
r := NewRegistry()
started := time.Now().Add(-25 * time.Millisecond)
r.RecordBusinessSnapshot(BusinessSnapshot{
TaskStates: map[string]uint64{"WAITING": 3},
TaskOldestAgeSeconds: 12.5,
DeliveryStates: map[string]uint64{"PENDING": 2},
DeliveryOldestAgeSeconds: 8.25,
WorkflowStates: map[string]uint64{"RUNNING": 1},
WorkflowOldestAgeSeconds: 4.75,
Truncated: true,
}, started, nil)
first := r.Render()
for _, want := range []string{
`orbit_pulse_tasks_state{state="WAITING"} 3`,
`orbit_result_deliveries_state{state="PENDING"} 2`,
`orbit_weave_workflows_state{state="RUNNING"} 1`,
"orbit_pulse_tasks_oldest_age_seconds 12.5",
"orbit_business_snapshot_truncated 1",
`orbit_business_snapshot_total{outcome="success"} 1`,
} {
if !strings.Contains(first, want) {
t.Fatalf("missing business sample %q", want)
}
}
lastSuccess := r.families["orbit_business_snapshot_last_success_timestamp_seconds"].series[""].value.Load()
r.RecordBusinessSnapshot(BusinessSnapshot{TaskStates: map[string]uint64{"WAITING": 99}}, time.Now(), context.DeadlineExceeded)
second := r.Render()
if !strings.Contains(second, `orbit_business_snapshot_total{outcome="timeout"} 1`) || !strings.Contains(second, `orbit_pulse_tasks_state{state="WAITING"} 3`) {
t.Fatal("failed sample overwrote good state")
}
if got := r.families["orbit_business_snapshot_last_success_timestamp_seconds"].series[""].value.Load(); got != lastSuccess {
t.Fatal("failed sample changed last success timestamp")
}
}
func TestHTTPBoundedLabelsAndPanicPreserved(t *testing.T) {
r := NewRegistry()
h := r.Middleware(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { w.WriteHeader(202) }))