Skip to content

Commit 0cd0346

Browse files
authored
feat(orchestrator): add self-reported status gauge with version label (#2667)
Adds an 'orchestrator.status' observable gauge that emits 1 on each collection cycle labelled with status, version, and commit, so each orchestrator's health and build can be tracked individually in metrics.
1 parent ecc10ab commit 0cd0346

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

packages/orchestrator/pkg/server/main.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/jellydator/ttlcache/v3"
12+
"go.opentelemetry.io/otel/attribute"
1213
"go.opentelemetry.io/otel/metric"
1314
"go.uber.org/zap"
1415

@@ -124,6 +125,25 @@ func New(ctx context.Context, cfg ServiceConfig) (*Server, error) {
124125
return nil, fmt.Errorf("failed to register sandbox count metric: %w", err)
125126
}
126127

128+
statusGauge, err := telemetry.GetGaugeInt(meter, telemetry.OrchestratorStatusGaugeName)
129+
if err != nil {
130+
return nil, fmt.Errorf("failed to create orchestrator status gauge: %w", err)
131+
}
132+
133+
_, err = meter.RegisterCallback(
134+
func(_ context.Context, obs metric.Observer) error {
135+
obs.ObserveInt64(statusGauge, 1, metric.WithAttributes(
136+
attribute.String("status", server.info.GetStatus().String()),
137+
attribute.String("version", server.info.SourceVersion),
138+
attribute.String("commit", server.info.SourceCommit),
139+
))
140+
141+
return nil
142+
}, statusGauge)
143+
if err != nil {
144+
return nil, fmt.Errorf("failed to register orchestrator status gauge: %w", err)
145+
}
146+
127147
go server.refreshStartingSandboxesLimit(ctx)
128148

129149
return server, nil

packages/shared/pkg/telemetry/meters.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ const (
129129

130130
const (
131131
ApiOrchestratorCountMeterName GaugeIntType = "api.orchestrator.status"
132+
OrchestratorStatusGaugeName GaugeIntType = "orchestrator.status"
132133

133134
// Sandbox metrics
134135
SandboxRamUsedGaugeName GaugeIntType = "e2b.sandbox.ram.used"
@@ -243,6 +244,7 @@ var gaugeFloatUnits = map[GaugeFloatType]string{
243244

244245
var gaugeIntDesc = map[GaugeIntType]string{
245246
ApiOrchestratorCountMeterName: "Counter of running orchestrators.",
247+
OrchestratorStatusGaugeName: "Self-reported orchestrator status (always 1, labelled with status and version).",
246248
SandboxRamUsedGaugeName: "Amount of RAM used by the sandbox.",
247249
SandboxRamTotalGaugeName: "Amount of RAM available to the sandbox.",
248250
SandboxRamCacheGaugeName: "Amount of RAM used by the page cache in the sandbox.",
@@ -255,6 +257,7 @@ var gaugeIntDesc = map[GaugeIntType]string{
255257

256258
var gaugeIntUnits = map[GaugeIntType]string{
257259
ApiOrchestratorCountMeterName: "{orchestrator}",
260+
OrchestratorStatusGaugeName: "{orchestrator}",
258261
SandboxRamUsedGaugeName: "{By}",
259262
SandboxRamTotalGaugeName: "{By}",
260263
SandboxRamCacheGaugeName: "{By}",

0 commit comments

Comments
 (0)