feat(metrics): added a gauge with version information#2375
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughSummary by CodeRabbit
WalkthroughThe changes introduce a version metrics initialization system to internal/utilities/version.go, which exports the Version variable and InitVersionMetrics function. InitVersionMetrics parses semantic version information into major, minor, patch, and release candidate components, then creates OpenTelemetry gauge metrics for each component with bounds validation. The ConfigureMetrics function in internal/observability/metrics.go now calls InitVersionMetrics during metric setup. Comprehensive tests validate the semantic version parsing across multiple format variations and the complete initialization flow. Sequence DiagramsequenceDiagram
actor ConfigureMetrics as metrics.ConfigureMetrics()
participant InitVersionMetrics as utilities.InitVersionMetrics()
participant ParseVersion as parseSemver()
participant InitMetrics as initMetrics()
participant Gauge as OTLP Gauges
ConfigureMetrics->>InitVersionMetrics: ctx
InitVersionMetrics->>ParseVersion: Version string
alt ParseVersion succeeds
ParseVersion-->>InitVersionMetrics: versionInfo{Major, Minor, Patch, RC}
else ParseVersion fails
ParseVersion-->>InitVersionMetrics: error (use empty versionInfo)
end
InitVersionMetrics->>InitMetrics: ctx, versionInfo
InitMetrics->>Gauge: Create & record major gauge
InitMetrics->>Gauge: Create & record minor gauge
InitMetrics->>Gauge: Create & record patch gauge
InitMetrics->>Gauge: Create & record rc gauge
Gauge-->>InitMetrics: errors (if any)
InitMetrics-->>InitVersionMetrics: aggregated errors
InitVersionMetrics-->>ConfigureMetrics: error
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@cmd/root_cmd.go`:
- Around line 56-59: The call to utilities.InitVersionMetrics(ctx) is ignoring
its returned error when config.Metrics.Enabled is true; capture the error and
handle it instead of discarding it. Update the block that checks
config.Metrics.Enabled to call err := utilities.InitVersionMetrics(ctx), then if
err != nil either return or wrap the error from the enclosing function (or log
it and exit) so failures are visible; reference the symbols
config.Metrics.Enabled and utilities.InitVersionMetrics(ctx) when making the
change.
In `@internal/utilities/version.go`:
- Around line 23-33: initVersionMetrics currently swallows parseSemver errors
and always returns nil, which hides malformed versions; change it to capture the
parse error from parseSemver(ver), still call initMetrics(ctx, vi) using a
zeroed vi when parse fails, and then return the original parse error (or a
wrapped error) if parseSemver returned one while still returning any initMetrics
error if that fails; reference parseSemver, initMetrics, initVersionMetrics, and
versionInfo to locate the changes.
🧹 Nitpick comments (1)
internal/utilities/version_test.go (1)
141-148: Improve the error assertion message for debuggability.The current
t.Fatalf("exp ")is truncated, making failures hard to diagnose.🛠️ Suggested fix
if tc.err != "" { if err == nil { t.Fatal("exp non-nil err") } if exp, got := tc.err, err.Error(); !strings.Contains(got, exp) { - t.Fatalf("exp ") + t.Fatalf("exp error containing %q; got %q", exp, got) } continue }
|
Out of curiosity, why have different gauges for each version number rather than a single label with a version string? |
I chose this because it sets maximum cardinality to 4 and I think it makes for better querying. |
This adds the 4 gauges seen below:
# HELP global_auth_version_major Set to this auth servers major version number.
# TYPE global_auth_version_major gauge
global_auth_version_major{otel_scope_name="gotrue",otel_scope_version=""} 2
# HELP global_auth_version_minor Set to this auth servers minor version number.
# TYPE global_auth_version_minor gauge
global_auth_version_minor{otel_scope_name="gotrue",otel_scope_version=""} 187
# HELP global_auth_version_patch Set to this auth servers patch version number.
# TYPE global_auth_version_patch gauge
global_auth_version_patch{otel_scope_name="gotrue",otel_scope_version=""} 0
# HELP global_auth_version_rc Set to this auth servers rc version number.
# TYPE global_auth_version_rc gauge
global_auth_version_rc{otel_scope_name="gotrue",otel_scope_version=""} 5
f670015 to
024b889
Compare
Pull Request Test Coverage Report for Build 22100400863Details
💛 - Coveralls |
This adds the 4 gauges seen below: