Skip to content

fix: Initialize peer metrics on startup to fix restart gap#2

Open
KA-ROM wants to merge 1 commit intomainfrom
fix/init_metrics_peers
Open

fix: Initialize peer metrics on startup to fix restart gap#2
KA-ROM wants to merge 1 commit intomainfrom
fix/init_metrics_peers

Conversation

@KA-ROM
Copy link

@KA-ROM KA-ROM commented Feb 10, 2026

Overview

After service restarts, peer count metrics are empty until the first successful monitoring tick. This causes empty gaps in observability despite bmonitor being healthy. This PR fixes that by initializing peer metrics to 0 for all configured builder × peer label combinations on startup.

@KA-ROM KA-ROM requested a review from Copilot February 10, 2026 13:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Initializes peer-count metrics at server startup so dashboards don’t show empty gaps after a restart (before the first monitoring tick).

Changes:

  • Adds a startup hook to pre-record PeersCount = 0 for each configured builder and peer label.
  • Introduces OTel metric attribute imports used for metric initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +193 to +201
attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)},
attribute.KeyValue{Key: "type", Value: attribute.StringValue(typ)},
))
}
for _, label := range s.peers {
metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes(
attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)},
attribute.KeyValue{Key: "type", Value: attribute.StringValue("labelled")},
attribute.KeyValue{Key: "label", Value: attribute.StringValue(label)},
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer the typed helpers (e.g., attribute.String(\"builder\", builder)) over manually constructing attribute.KeyValue with attribute.StringValue(...). It reads clearer and avoids potential subtle inconsistencies in how attributes are constructed across the codebase.

Suggested change
attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)},
attribute.KeyValue{Key: "type", Value: attribute.StringValue(typ)},
))
}
for _, label := range s.peers {
metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes(
attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)},
attribute.KeyValue{Key: "type", Value: attribute.StringValue("labelled")},
attribute.KeyValue{Key: "label", Value: attribute.StringValue(label)},
attribute.String("builder", builder),
attribute.String("type", typ),
))
}
for _, label := range s.peers {
metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes(
attribute.String("builder", builder),
attribute.String("type", "labelled"),
attribute.String("label", label),

Copilot uses AI. Check for mistakes.
Comment on lines +191 to +196
for _, typ := range []string{"loopback", "internal", "external"} {
metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes(
attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)},
attribute.KeyValue{Key: "type", Value: attribute.StringValue(typ)},
))
}
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces several magic strings for attribute keys/values (\"builder\", \"type\", \"label\", \"loopback\", \"internal\", \"external\", \"labelled\"). Consider centralizing these as constants (or reusing existing constants/enums if the repo has them) to prevent drift/typos and make it easier to change label conventions later.

Copilot uses AI. Check for mistakes.
for _, label := range s.peers {
metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes(
attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)},
attribute.KeyValue{Key: "type", Value: attribute.StringValue("labelled")},
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces several magic strings for attribute keys/values (\"builder\", \"type\", \"label\", \"loopback\", \"internal\", \"external\", \"labelled\"). Consider centralizing these as constants (or reusing existing constants/enums if the repo has them) to prevent drift/typos and make it easier to change label conventions later.

Copilot uses AI. Check for mistakes.
@KA-ROM KA-ROM requested a review from 0x416e746f6e February 10, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant