Skip to content
Draft
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",
],
)
47 changes: 47 additions & 0 deletions stovepipe/controller/issueagemetrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Issue-age metrics

`NewTask` supplies an issue-age collector to the shared [periodic controller](../periodicmetrics/README.md). It reads issue storage and does not depend on source control or queue-health collection.

The reference host registers it on topic `issueagemetrics`, in group `stovepipe-issueagemetrics`, and seeds one recurring delivery per queue. Metrics use the `stovepipe.issueagemetrics` prefix and a `queue` tag.

Each observation scans the queue's open-issue index and validates its entries
against lifecycle summaries. Age starts when the current occurrence opens or
reopens; repeated failure reports do not reset it. An issue remains open until a
resolution is recorded, so its age is not proof of continuous failure or queue
blockage.

| Gauge | Value |
| --- | --- |
| `open_issues` | Total currently open issues |
| `oldest_open_issue_age_seconds` | Maximum open-issue age in seconds; zero for an empty backlog |
| `open_issues_by_age` | Open-issue count in each mutually exclusive `age_bucket` |
| `issue_snapshot_timestamp_seconds` | Completion time of the last successful full scan, in Unix seconds |

The three backlog gauges also have `task_`-prefixed versions tagged by `task`
and `scope` (`task` for task-wide issues, `unit` otherwise). The unprefixed
gauges are queue totals: do not add them to their task breakdowns. Unit labels,
build IDs, and request IDs are not metric dimensions.

Issue-age bands have boundaries at 1m, 5m, 10m, 15m, 30m, 45m, 1h, 2h, 4h,
8h, 12h, 1d, 2d, 7d, 14d, and 30d. Lower bounds are inclusive and
upper bounds exclusive. Labels use Go duration notation, such as
`0s_to_1m0s`, `1m0s_to_5m0s`, and `720h0m0s_plus`. These are snapshot count
gauges, not cumulative histogram observations.

Every successful scan emits all age bands, including zeros. The worker also
keeps emitting zeros for task/scope combinations it previously observed.
After a worker handoff, a disappearing task's old worker series must age out;
dashboards must use fresh samples rather than carrying old worker values
forward or summing replicas' snapshots.

Scans are eventually consistent, not transactional snapshots. All ages use
the scan's start time; concurrent changes can appear in the next observation.
A failed or canceled scan publishes no backlog gauges or success timestamp.
Use the success timestamp to detect stale observations rather than treating
missing data as an empty backlog.

`issue_snapshot.start` counts attempts and `issue_snapshot.finish` records scan
duration and count with `result=success|error|cancel`, following the standard
operation metrics. Storage-factory failures emit `issue_snapshot_storage_errors`
before a scan can start. `issue_timestamp_future` counts opening timestamps
ahead of the sampling clock; their ages are clamped to zero.
Loading