Skip to content

Commit 678f5b5

Browse files
committed
feat(stovepipe): Add open issue age metrics
## Summary **What**: - Report open-issue counts, oldest age, and age distributions per queue. - Run issue-age collection through the shared periodic controller, with independent scheduling, snapshot freshness, and collection-health reporting. **Why**: - Expose unresolved failures that are aging while a queue is idle; existing queue-health metrics do not show the size or age of the issue backlog. - Keep queue-health observations timely when issue scans are slow or fail, and distinguish empty backlogs from stale or incomplete observations. ## Test Plan - [x] Add unit tests. ## Revert Plan - Revert this PR to stop issue-age collection; existing queue-health tasks retain their identities and behavior. ## Issue Links - [CODEM-689](https://linear.app/uber/issue/CODEM-689/figure-out-implement-metrics-to-manage-issue-age)
1 parent 9b13220 commit 678f5b5

14 files changed

Lines changed: 772 additions & 39 deletions

File tree

‎service/stovepipe/server/BUILD.bazel‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ go_library(
3131
"//stovepipe/controller/buildsignal:go_default_library",
3232
"//stovepipe/controller/dlq:go_default_library",
3333
"//stovepipe/controller/fix:go_default_library",
34+
"//stovepipe/controller/issueagemetrics:go_default_library",
3435
"//stovepipe/controller/issuetrack:go_default_library",
3536
"//stovepipe/controller/periodicmetrics:go_default_library",
3637
"//stovepipe/controller/process:go_default_library",

‎service/stovepipe/server/main.go‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import (
5353
"github.com/uber/submitqueue/stovepipe/controller/buildsignal"
5454
"github.com/uber/submitqueue/stovepipe/controller/dlq"
5555
"github.com/uber/submitqueue/stovepipe/controller/fix"
56+
"github.com/uber/submitqueue/stovepipe/controller/issueagemetrics"
5657
"github.com/uber/submitqueue/stovepipe/controller/issuetrack"
5758
"github.com/uber/submitqueue/stovepipe/controller/periodicmetrics"
5859
"github.com/uber/submitqueue/stovepipe/controller/process"
@@ -368,8 +369,10 @@ func seedPeriodicMetrics(ctx context.Context, registry consumer.TopicRegistry, t
368369
defer cancel()
369370

370371
for _, queue := range tenants {
371-
if err := periodicmetrics.Schedule(ctx, registry, stovepipemq.TopicKeyQueueHealthMetrics, queue); err != nil {
372-
return fmt.Errorf("schedule metrics for queue %q: %w", queue, err)
372+
for _, key := range []consumer.TopicKey{stovepipemq.TopicKeyQueueHealthMetrics, stovepipemq.TopicKeyIssueAgeMetrics} {
373+
if err := periodicmetrics.Schedule(ctx, registry, key, queue); err != nil {
374+
return fmt.Errorf("schedule %s for queue %q: %w", key, queue, err)
375+
}
373376
}
374377
}
375378
return nil
@@ -400,6 +403,15 @@ func registerPrimaryControllers(
400403
}
401404
count++
402405

406+
issueAgeController := periodicmetrics.NewController(
407+
logger, issueagemetrics.NewTask(scope, store),
408+
stovepipemq.TopicKeyIssueAgeMetrics, "stovepipe-issueagemetrics",
409+
)
410+
if err := c.Register(issueAgeController); err != nil {
411+
return count, fmt.Errorf("failed to register issue age metrics controller: %w", err)
412+
}
413+
count++
414+
403415
processController := process.NewController(
404416
logger,
405417
scope,
@@ -543,13 +555,26 @@ func newTopicRegistry(q extqueue.Queue, subscriberName string) (consumer.TopicRe
543555
// The recurring task must survive crashes and failed postponements indefinitely.
544556
metricsSubscription.Retry.MaxAttempts = 0
545557
metricsSubscription.DLQ.Enabled = false
558+
559+
issueAgeSubscription := extqueue.SingleMessageSubscriptionConfig(
560+
subscriberName, "stovepipe-issueagemetrics",
561+
)
562+
issueAgeSubscription.Retry.MaxAttempts = 0
563+
issueAgeSubscription.DLQ.Enabled = false
564+
546565
return consumer.NewTopicRegistry([]consumer.TopicConfig{
547566
{
548567
Key: stovepipemq.TopicKeyQueueHealthMetrics,
549568
Name: "queuehealthmetrics",
550569
Queue: q,
551570
Subscription: metricsSubscription,
552571
},
572+
{
573+
Key: stovepipemq.TopicKeyIssueAgeMetrics,
574+
Name: "issueagemetrics",
575+
Queue: q,
576+
Subscription: issueAgeSubscription,
577+
},
553578
{
554579
Key: stovepipemq.TopicKeyProcess,
555580
Name: "process",

‎service/stovepipe/server/main_test.go‎

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestValidationStagesHaveRecovery(t *testing.T) {
124124
_, primary, deadLetter := registeredControllers(t)
125125
recoveryKeys := topicKeys(deadLetter)
126126
for _, controller := range primary {
127-
if controller.TopicKey() == stovepipemq.TopicKeyQueueHealthMetrics {
127+
if controller.TopicKey() == stovepipemq.TopicKeyQueueHealthMetrics || controller.TopicKey() == stovepipemq.TopicKeyIssueAgeMetrics {
128128
continue
129129
}
130130
t.Run(controller.Name(), func(t *testing.T) {
@@ -135,46 +135,54 @@ func TestValidationStagesHaveRecovery(t *testing.T) {
135135

136136
func TestMetricsWorkersShareRecurringTask(t *testing.T) {
137137
registry, primary, _ := registeredControllers(t)
138-
assert.Contains(t, topicKeys(primary), stovepipemq.TopicKeyQueueHealthMetrics)
139-
topic, ok := registry.TopicName(stovepipemq.TopicKeyQueueHealthMetrics)
140-
require.True(t, ok)
141-
assert.Equal(t, "queuehealthmetrics", topic)
142-
143-
for _, controller := range primary {
144-
if controller.TopicKey() == stovepipemq.TopicKeyQueueHealthMetrics {
145-
assert.Equal(t, "queuehealthmetrics", controller.Name())
146-
}
147-
}
148-
149-
first, ok := registry.SubscriptionConfig(stovepipemq.TopicKeyQueueHealthMetrics, "stovepipe-queuehealthmetrics")
150-
require.True(t, ok)
151138
otherRegistry, err := newTopicRegistry(nil, "other-worker")
152139
require.NoError(t, err)
153-
second, ok := otherRegistry.SubscriptionConfig(stovepipemq.TopicKeyQueueHealthMetrics, "stovepipe-queuehealthmetrics")
154-
require.True(t, ok)
155-
assert.Equal(t, first.ConsumerGroup, second.ConsumerGroup)
156-
assert.NotEqual(t, first.SubscriberName, second.SubscriberName)
157-
assert.Zero(t, first.Retry.MaxAttempts)
158-
assert.False(t, first.DLQ.Enabled)
159-
assert.Equal(t, 1, first.BatchSize)
140+
for _, key := range []consumer.TopicKey{stovepipemq.TopicKeyQueueHealthMetrics, stovepipemq.TopicKeyIssueAgeMetrics} {
141+
t.Run(key.String(), func(t *testing.T) {
142+
assert.Contains(t, topicKeys(primary), key)
143+
name, ok := registry.TopicName(key)
144+
require.True(t, ok)
145+
assert.Equal(t, key.String(), name)
146+
147+
group := "stovepipe-" + key.String()
148+
first, ok := registry.SubscriptionConfig(key, group)
149+
require.True(t, ok)
150+
second, ok := otherRegistry.SubscriptionConfig(key, group)
151+
require.True(t, ok)
152+
assert.Equal(t, first.ConsumerGroup, second.ConsumerGroup)
153+
assert.NotEqual(t, first.SubscriberName, second.SubscriberName)
154+
assert.Zero(t, first.Retry.MaxAttempts)
155+
assert.False(t, first.DLQ.Enabled)
156+
assert.Equal(t, 1, first.BatchSize)
157+
})
158+
}
160159
}
161160

162161
func TestSeedPeriodicMetricsReturnsWhenQueuePublishStalls(t *testing.T) {
163-
synctest.Test(t, func(t *testing.T) {
164-
ctrl := gomock.NewController(t)
165-
queue := queuemock.NewMockQueue(ctrl)
166-
publisher := queuemock.NewMockPublisher(ctrl)
167-
queue.EXPECT().Publisher().Return(publisher)
168-
publisher.EXPECT().Publish(gomock.Any(), "queuehealthmetrics", gomock.Any()).
169-
DoAndReturn(func(ctx context.Context, _ string, _ entityqueue.Message) error {
170-
<-ctx.Done()
171-
return ctx.Err()
162+
for _, topic := range []string{"queuehealthmetrics", "issueagemetrics"} {
163+
t.Run(topic, func(t *testing.T) {
164+
synctest.Test(t, func(t *testing.T) {
165+
ctrl := gomock.NewController(t)
166+
queue := queuemock.NewMockQueue(ctrl)
167+
publisher := queuemock.NewMockPublisher(ctrl)
168+
calls := 1
169+
if topic == "issueagemetrics" {
170+
calls++
171+
publisher.EXPECT().Publish(gomock.Any(), "queuehealthmetrics", gomock.Any()).Return(nil)
172+
}
173+
queue.EXPECT().Publisher().Return(publisher).Times(calls)
174+
publisher.EXPECT().Publish(gomock.Any(), topic, gomock.Any()).
175+
DoAndReturn(func(ctx context.Context, _ string, _ entityqueue.Message) error {
176+
<-ctx.Done()
177+
return ctx.Err()
178+
})
179+
registry, err := newTopicRegistry(queue, "subscriber")
180+
require.NoError(t, err)
181+
182+
require.ErrorIs(t, seedPeriodicMetrics(context.Background(), registry, []string{"monorepo/main"}), context.DeadlineExceeded)
172183
})
173-
registry, err := newTopicRegistry(queue, "subscriber")
174-
require.NoError(t, err)
175-
176-
require.ErrorIs(t, seedPeriodicMetrics(context.Background(), registry, []string{"monorepo/main"}), context.DeadlineExceeded)
177-
})
184+
})
185+
}
178186
}
179187

180188
func TestFixRegistration(t *testing.T) {
@@ -403,3 +411,25 @@ func TestFakeSourceControlFactorySharesPromotionPerQueue(t *testing.T) {
403411
require.NoError(t, err)
404412
assert.Empty(t, current)
405413
}
414+
415+
func TestSeedPeriodicMetricsSchedulesBothTasksForEveryQueue(t *testing.T) {
416+
ctrl := gomock.NewController(t)
417+
queue := queuemock.NewMockQueue(ctrl)
418+
publisher := queuemock.NewMockPublisher(ctrl)
419+
queue.EXPECT().Publisher().Return(publisher).Times(4)
420+
for _, topic := range []string{"queuehealthmetrics", "issueagemetrics"} {
421+
for _, tenant := range []string{"first-queue", "second-queue"} {
422+
publisher.EXPECT().Publish(gomock.Any(), topic, gomock.Any()).
423+
DoAndReturn(func(_ context.Context, _ string, message entityqueue.Message) error {
424+
assert.Equal(t, tenant, message.Tenant)
425+
assert.Equal(t, tenant, message.PartitionKey)
426+
assert.Equal(t, topic, message.ID)
427+
return nil
428+
})
429+
}
430+
}
431+
registry, err := newTopicRegistry(queue, "subscriber")
432+
require.NoError(t, err)
433+
434+
require.NoError(t, seedPeriodicMetrics(context.Background(), registry, []string{"first-queue", "second-queue"}))
435+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
load("@rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["issueagemetrics.go"],
6+
importpath = "github.com/uber/submitqueue/stovepipe/controller/issueagemetrics",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//platform/metrics:go_default_library",
10+
"//stovepipe/controller/periodicmetrics:go_default_library",
11+
"//stovepipe/entity:go_default_library",
12+
"//stovepipe/extension/storage:go_default_library",
13+
"@com_github_uber_go_tally//:go_default_library",
14+
],
15+
)
16+
17+
go_test(
18+
name = "go_default_test",
19+
srcs = ["issueagemetrics_test.go"],
20+
embed = [":go_default_library"],
21+
deps = [
22+
"//stovepipe/entity:go_default_library",
23+
"//stovepipe/extension/storage:go_default_library",
24+
"//stovepipe/extension/storage/mock:go_default_library",
25+
"@com_github_stretchr_testify//assert:go_default_library",
26+
"@com_github_stretchr_testify//require:go_default_library",
27+
"@com_github_uber_go_tally//:go_default_library",
28+
"@org_uber_go_mock//gomock:go_default_library",
29+
],
30+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Issue-age metrics
2+
3+
Collects queue-wide snapshots through the shared
4+
[periodic controller](../periodicmetrics/README.md). Metrics use the
5+
`stovepipe.issueagemetrics` prefix and a `queue` tag.
6+
7+
| Gauge | Value |
8+
| --- | --- |
9+
| `open_issues` | Number of open issues |
10+
| `oldest_open_issue_age_seconds` | Oldest open-issue age; zero when none are open |
11+
| `open_issues_by_age` | Count per mutually exclusive `age_bucket` |
12+
| `issue_snapshot_timestamp_seconds` | Last successful scan completion, in Unix seconds |
13+
14+
Age starts at the current opening or reopening; repeated reports do not reset it.
15+
The collector checks open-index entries against lifecycle summaries. Reads are
16+
not transactional; concurrent changes may appear in the next snapshot.
17+
Failed or canceled scans publish no backlog gauges or success timestamp.
18+
19+
Age boundaries: **1m, 5m, 10m, 15m, 30m, 45m, 1h, 2h, 4h, 8h, 12h,
20+
1d, 2d, 7d, 14d, 30d**. Bounds are lower-inclusive and upper-exclusive,
21+
with an overflow band. Labels use Go durations, such as `0s_to_1m0s` and
22+
`720h0m0s_plus`. Every successful scan emits all bands, including zeros.
23+
24+
Collection health uses standard `issue_snapshot.start` and
25+
`issue_snapshot.finish` operation metrics. Storage setup failures increment
26+
`issue_snapshot_storage_errors`; future opening timestamps increment
27+
`issue_timestamp_future` and contribute age zero.

0 commit comments

Comments
 (0)