feat: sample recent business events
This commit is contained in:
@@ -23,6 +23,8 @@ type BusinessSnapshot struct {
|
||||
WorkflowOldestAgeSeconds float64
|
||||
// Truncated 是否至少有一类状态达到采样上限。
|
||||
Truncated bool
|
||||
// RecentEvents 固定事件类别在最近窗口内的有界数量。
|
||||
RecentEvents map[string]uint64
|
||||
}
|
||||
|
||||
// RecordBusinessSnapshot records one bounded database sample. A failed sample
|
||||
@@ -53,6 +55,9 @@ func (r *Registry) RecordBusinessSnapshot(snapshot BusinessSnapshot, started tim
|
||||
for _, state := range workflowStates {
|
||||
r.SetGauge("orbit_weave_workflows_state", float64(snapshot.WorkflowStates[state]), Labels{"state": state})
|
||||
}
|
||||
for _, eventType := range eventTypes {
|
||||
r.SetGauge("orbit_business_events_recent", float64(snapshot.RecentEvents[eventType]), Labels{"event": eventType})
|
||||
}
|
||||
r.SetGauge("orbit_pulse_tasks_oldest_age_seconds", snapshot.TaskOldestAgeSeconds, nil)
|
||||
r.SetGauge("orbit_result_delivery_oldest_age_seconds", snapshot.DeliveryOldestAgeSeconds, nil)
|
||||
r.SetGauge("orbit_weave_workflow_oldest_age_seconds", snapshot.WorkflowOldestAgeSeconds, nil)
|
||||
|
||||
@@ -9,6 +9,7 @@ var components = []string{"workflow", "schedule", "execution_recovery"}
|
||||
var taskStates = []string{"WAITING", "LEASED", "RUNNING", "NEEDS_REVIEW", "SUCCEEDED", "FAILED", "CANCELLED"}
|
||||
var deliveryStates = []string{"PENDING", "LEASED", "ACKED", "EXPIRED"}
|
||||
var workflowStates = []string{"RUNNING", "WAITING", "CANCELLING", "NEEDS_REVIEW", "SUCCEEDED", "FAILED", "CANCELLED"}
|
||||
var eventTypes = []string{"task.accepted", "task.started", "task.succeeded", "task.failed", "task.needs_review", "task.requeued", "workflow.started", "workflow.advanced", "workflow.recovered", "workflow.blocked", "workflow.stopped"}
|
||||
|
||||
// Every exported family is declared here, including each allowed label value.
|
||||
// Adding a metric therefore requires a code review; no user identifier is valid.
|
||||
@@ -42,6 +43,7 @@ func catalog() map[string]descriptor {
|
||||
c["orbit_result_delivery_oldest_age_seconds"] = descriptor{gauge, "Age of the oldest sampled pending result delivery", nil}
|
||||
c["orbit_weave_workflows_state"] = descriptor{gauge, "Bounded count of Weave instances by durable state", map[string][]string{"state": workflowStates}}
|
||||
c["orbit_weave_workflow_oldest_age_seconds"] = descriptor{gauge, "Age of the oldest sampled unfinished Weave instance", nil}
|
||||
c["orbit_business_events_recent"] = descriptor{gauge, "Bounded count of fixed event categories in the recent window", map[string][]string{"event": eventTypes}}
|
||||
c["orbit_business_snapshot_total"] = descriptor{counter, "Completed bounded business-state snapshots by outcome", map[string][]string{"outcome": {"success", "error", "timeout"}}}
|
||||
c["orbit_business_snapshot_duration_seconds"] = descriptor{histogram, "Bounded business-state snapshot duration in seconds", nil}
|
||||
c["orbit_business_snapshot_last_success_timestamp_seconds"] = descriptor{gauge, "Unix time of the last successful bounded business-state snapshot", nil}
|
||||
|
||||
@@ -123,6 +123,7 @@ func TestBusinessSnapshotKeepsLastGoodStateOnFailure(t *testing.T) {
|
||||
DeliveryOldestAgeSeconds: 8.25,
|
||||
WorkflowStates: map[string]uint64{"RUNNING": 1},
|
||||
WorkflowOldestAgeSeconds: 4.75,
|
||||
RecentEvents: map[string]uint64{"task.accepted": 5},
|
||||
Truncated: true,
|
||||
}, started, nil)
|
||||
first := r.Render()
|
||||
@@ -130,6 +131,7 @@ func TestBusinessSnapshotKeepsLastGoodStateOnFailure(t *testing.T) {
|
||||
`orbit_pulse_tasks_state{state="WAITING"} 3`,
|
||||
`orbit_result_deliveries_state{state="PENDING"} 2`,
|
||||
`orbit_weave_workflows_state{state="RUNNING"} 1`,
|
||||
`orbit_business_events_recent{event="task.accepted"} 5`,
|
||||
"orbit_pulse_tasks_oldest_age_seconds 12.5",
|
||||
"orbit_business_snapshot_truncated 1",
|
||||
`orbit_business_snapshot_total{outcome="success"} 1`,
|
||||
|
||||
Reference in New Issue
Block a user