Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions service/stovepipe/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ go_library(
"//stovepipe/controller/buildsignal:go_default_library",
"//stovepipe/controller/dlq:go_default_library",
"//stovepipe/controller/fix:go_default_library",
"//stovepipe/controller/issueagemetrics:go_default_library",
"//stovepipe/controller/issuetrack:go_default_library",
"//stovepipe/controller/periodicmetrics:go_default_library",
"//stovepipe/controller/process:go_default_library",
Expand Down
29 changes: 27 additions & 2 deletions service/stovepipe/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"github.com/uber/submitqueue/stovepipe/controller/buildsignal"
"github.com/uber/submitqueue/stovepipe/controller/dlq"
"github.com/uber/submitqueue/stovepipe/controller/fix"
"github.com/uber/submitqueue/stovepipe/controller/issueagemetrics"
"github.com/uber/submitqueue/stovepipe/controller/issuetrack"
"github.com/uber/submitqueue/stovepipe/controller/periodicmetrics"
"github.com/uber/submitqueue/stovepipe/controller/process"
Expand Down Expand Up @@ -368,8 +369,10 @@ func seedPeriodicMetrics(ctx context.Context, registry consumer.TopicRegistry, t
defer cancel()

for _, queue := range tenants {
if err := periodicmetrics.Schedule(ctx, registry, stovepipemq.TopicKeyQueueHealthMetrics, queue); err != nil {
return fmt.Errorf("schedule metrics for queue %q: %w", queue, err)
for _, key := range []consumer.TopicKey{stovepipemq.TopicKeyQueueHealthMetrics, stovepipemq.TopicKeyIssueAgeMetrics} {
if err := periodicmetrics.Schedule(ctx, registry, key, queue); err != nil {
return fmt.Errorf("schedule %s for queue %q: %w", key, queue, err)
}
}
}
return nil
Expand Down Expand Up @@ -400,6 +403,15 @@ func registerPrimaryControllers(
}
count++

issueAgeController := periodicmetrics.NewController(
logger, issueagemetrics.NewTask(scope, store),
stovepipemq.TopicKeyIssueAgeMetrics, "stovepipe-issueagemetrics",
)
if err := c.Register(issueAgeController); err != nil {
return count, fmt.Errorf("failed to register issue age metrics controller: %w", err)
}
count++

processController := process.NewController(
logger,
scope,
Expand Down Expand Up @@ -543,13 +555,26 @@ func newTopicRegistry(q extqueue.Queue, subscriberName string) (consumer.TopicRe
// The recurring task must survive crashes and failed postponements indefinitely.
metricsSubscription.Retry.MaxAttempts = 0
metricsSubscription.DLQ.Enabled = false

issueAgeSubscription := extqueue.SingleMessageSubscriptionConfig(
subscriberName, "stovepipe-issueagemetrics",
)
issueAgeSubscription.Retry.MaxAttempts = 0
issueAgeSubscription.DLQ.Enabled = false

return consumer.NewTopicRegistry([]consumer.TopicConfig{
{
Key: stovepipemq.TopicKeyQueueHealthMetrics,
Name: "queuehealthmetrics",
Queue: q,
Subscription: metricsSubscription,
},
{
Key: stovepipemq.TopicKeyIssueAgeMetrics,
Name: "issueagemetrics",
Queue: q,
Subscription: issueAgeSubscription,
},
{
Key: stovepipemq.TopicKeyProcess,
Name: "process",
Expand Down
100 changes: 65 additions & 35 deletions service/stovepipe/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestValidationStagesHaveRecovery(t *testing.T) {
_, primary, deadLetter := registeredControllers(t)
recoveryKeys := topicKeys(deadLetter)
for _, controller := range primary {
if controller.TopicKey() == stovepipemq.TopicKeyQueueHealthMetrics {
if controller.TopicKey() == stovepipemq.TopicKeyQueueHealthMetrics || controller.TopicKey() == stovepipemq.TopicKeyIssueAgeMetrics {
continue
}
t.Run(controller.Name(), func(t *testing.T) {
Expand All @@ -135,46 +135,54 @@ func TestValidationStagesHaveRecovery(t *testing.T) {

func TestMetricsWorkersShareRecurringTask(t *testing.T) {
registry, primary, _ := registeredControllers(t)
assert.Contains(t, topicKeys(primary), stovepipemq.TopicKeyQueueHealthMetrics)
topic, ok := registry.TopicName(stovepipemq.TopicKeyQueueHealthMetrics)
require.True(t, ok)
assert.Equal(t, "queuehealthmetrics", topic)

for _, controller := range primary {
if controller.TopicKey() == stovepipemq.TopicKeyQueueHealthMetrics {
assert.Equal(t, "queuehealthmetrics", controller.Name())
}
}

first, ok := registry.SubscriptionConfig(stovepipemq.TopicKeyQueueHealthMetrics, "stovepipe-queuehealthmetrics")
require.True(t, ok)
otherRegistry, err := newTopicRegistry(nil, "other-worker")
require.NoError(t, err)
second, ok := otherRegistry.SubscriptionConfig(stovepipemq.TopicKeyQueueHealthMetrics, "stovepipe-queuehealthmetrics")
require.True(t, ok)
assert.Equal(t, first.ConsumerGroup, second.ConsumerGroup)
assert.NotEqual(t, first.SubscriberName, second.SubscriberName)
assert.Zero(t, first.Retry.MaxAttempts)
assert.False(t, first.DLQ.Enabled)
assert.Equal(t, 1, first.BatchSize)
for _, key := range []consumer.TopicKey{stovepipemq.TopicKeyQueueHealthMetrics, stovepipemq.TopicKeyIssueAgeMetrics} {
t.Run(key.String(), func(t *testing.T) {
assert.Contains(t, topicKeys(primary), key)
name, ok := registry.TopicName(key)
require.True(t, ok)
assert.Equal(t, key.String(), name)

group := "stovepipe-" + key.String()
first, ok := registry.SubscriptionConfig(key, group)
require.True(t, ok)
second, ok := otherRegistry.SubscriptionConfig(key, group)
require.True(t, ok)
assert.Equal(t, first.ConsumerGroup, second.ConsumerGroup)
assert.NotEqual(t, first.SubscriberName, second.SubscriberName)
assert.Zero(t, first.Retry.MaxAttempts)
assert.False(t, first.DLQ.Enabled)
assert.Equal(t, 1, first.BatchSize)
})
}
}

func TestSeedPeriodicMetricsReturnsWhenQueuePublishStalls(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
ctrl := gomock.NewController(t)
queue := queuemock.NewMockQueue(ctrl)
publisher := queuemock.NewMockPublisher(ctrl)
queue.EXPECT().Publisher().Return(publisher)
publisher.EXPECT().Publish(gomock.Any(), "queuehealthmetrics", gomock.Any()).
DoAndReturn(func(ctx context.Context, _ string, _ entityqueue.Message) error {
<-ctx.Done()
return ctx.Err()
for _, topic := range []string{"queuehealthmetrics", "issueagemetrics"} {
t.Run(topic, func(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
ctrl := gomock.NewController(t)
queue := queuemock.NewMockQueue(ctrl)
publisher := queuemock.NewMockPublisher(ctrl)
calls := 1
if topic == "issueagemetrics" {
calls++
publisher.EXPECT().Publish(gomock.Any(), "queuehealthmetrics", gomock.Any()).Return(nil)
}
queue.EXPECT().Publisher().Return(publisher).Times(calls)
publisher.EXPECT().Publish(gomock.Any(), topic, gomock.Any()).
DoAndReturn(func(ctx context.Context, _ string, _ entityqueue.Message) error {
<-ctx.Done()
return ctx.Err()
})
registry, err := newTopicRegistry(queue, "subscriber")
require.NoError(t, err)

require.ErrorIs(t, seedPeriodicMetrics(context.Background(), registry, []string{"monorepo/main"}), context.DeadlineExceeded)
})
registry, err := newTopicRegistry(queue, "subscriber")
require.NoError(t, err)

require.ErrorIs(t, seedPeriodicMetrics(context.Background(), registry, []string{"monorepo/main"}), context.DeadlineExceeded)
})
})
}
}

func TestFixRegistration(t *testing.T) {
Expand Down Expand Up @@ -403,3 +411,25 @@ func TestFakeSourceControlFactorySharesPromotionPerQueue(t *testing.T) {
require.NoError(t, err)
assert.Empty(t, current)
}

func TestSeedPeriodicMetricsSchedulesBothTasksForEveryQueue(t *testing.T) {
ctrl := gomock.NewController(t)
queue := queuemock.NewMockQueue(ctrl)
publisher := queuemock.NewMockPublisher(ctrl)
queue.EXPECT().Publisher().Return(publisher).Times(4)
for _, topic := range []string{"queuehealthmetrics", "issueagemetrics"} {
for _, tenant := range []string{"first-queue", "second-queue"} {
publisher.EXPECT().Publish(gomock.Any(), topic, gomock.Any()).
DoAndReturn(func(_ context.Context, _ string, message entityqueue.Message) error {
assert.Equal(t, tenant, message.Tenant)
assert.Equal(t, tenant, message.PartitionKey)
assert.Equal(t, topic, message.ID)
return nil
})
}
}
registry, err := newTopicRegistry(queue, "subscriber")
require.NoError(t, err)

require.NoError(t, seedPeriodicMetrics(context.Background(), registry, []string{"first-queue", "second-queue"}))
}
30 changes: 30 additions & 0 deletions stovepipe/controller/issueagemetrics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
load("@rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["issueagemetrics.go"],
importpath = "github.com/uber/submitqueue/stovepipe/controller/issueagemetrics",
visibility = ["//visibility:public"],
deps = [
"//platform/metrics:go_default_library",
"//stovepipe/controller/periodicmetrics:go_default_library",
"//stovepipe/entity:go_default_library",
"//stovepipe/extension/storage:go_default_library",
"@com_github_uber_go_tally//:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = ["issueagemetrics_test.go"],
embed = [":go_default_library"],
deps = [
"//stovepipe/entity:go_default_library",
"//stovepipe/extension/storage:go_default_library",
"//stovepipe/extension/storage/mock:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
"@com_github_uber_go_tally//:go_default_library",
"@org_uber_go_mock//gomock:go_default_library",
],
)
27 changes: 27 additions & 0 deletions stovepipe/controller/issueagemetrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Issue-age metrics

Collects queue-wide snapshots through the shared
[periodic controller](../periodicmetrics/README.md). Metrics use the
`stovepipe.issueagemetrics` prefix and a `queue` tag.

| Gauge | Value |
| --- | --- |
| `open_issues` | Number of open issues |
| `oldest_open_issue_age_seconds` | Oldest open-issue age; zero when none are open |
| `open_issues_by_age` | Count per mutually exclusive `age_bucket` |
| `issue_snapshot_timestamp_seconds` | Last successful scan completion, in Unix seconds |

Age starts at the current opening or reopening; repeated reports do not reset it.
The collector checks open-index entries against lifecycle summaries. Reads are
not transactional; concurrent changes may appear in the next snapshot.
Failed or canceled scans publish no backlog gauges or success timestamp.

Age boundaries: **1m, 5m, 10m, 15m, 30m, 45m, 1h, 2h, 4h, 8h, 12h,
1d, 2d, 7d, 14d, 30d**. Bounds are lower-inclusive and upper-exclusive,
with an overflow band. Labels use Go durations, such as `0s_to_1m0s` and
`720h0m0s_plus`. Every successful scan emits all bands, including zeros.

Collection health uses standard `issue_snapshot.start` and
`issue_snapshot.finish` operation metrics. Storage setup failures increment
`issue_snapshot_storage_errors`; future opening timestamps increment
`issue_timestamp_future` and contribute age zero.
Loading
Loading