Skip to content

Commit 67b8c9c

Browse files
authored
Fix unit suffix duplication in Prometheus metrics (#1153)
1 parent a8e8687 commit 67b8c9c

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

pkg/telemetry/integration_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ func TestTelemetryIntegration_EndToEnd(t *testing.T) {
151151

152152
// If we have custom metrics, verify them
153153
if strings.Contains(metricsBody, "toolhive_mcp") {
154-
assert.Contains(t, metricsBody, "toolhive_mcp_requests_total")
155-
assert.Contains(t, metricsBody, "toolhive_mcp_request_duration_seconds")
154+
assert.Contains(t, metricsBody, "toolhive_mcp_requests")
155+
assert.Contains(t, metricsBody, "toolhive_mcp_request_duration")
156156
assert.Contains(t, metricsBody, "toolhive_mcp_active_connections")
157157
}
158158
} else {
@@ -259,7 +259,7 @@ func TestTelemetryIntegration_WithRealProviders(t *testing.T) {
259259
for _, sm := range rm.ScopeMetrics {
260260
for _, metric := range sm.Metrics {
261261
switch metric.Name {
262-
case "toolhive_mcp_requests_total":
262+
case "toolhive_mcp_requests":
263263
foundRequestCounter = true
264264
// Verify metric has expected attributes
265265
if sum, ok := metric.Data.(metricdata.Sum[int64]); ok {
@@ -281,7 +281,7 @@ func TestTelemetryIntegration_WithRealProviders(t *testing.T) {
281281
assert.True(t, hasMethod, "Request counter should have mcp_method attribute")
282282
}
283283
}
284-
case "toolhive_mcp_request_duration_seconds":
284+
case "toolhive_mcp_request_duration":
285285
foundDurationHistogram = true
286286
case "toolhive_mcp_active_connections":
287287
foundActiveConnections = true
@@ -404,7 +404,7 @@ func TestTelemetryIntegration_ToolSpecificMetrics(t *testing.T) {
404404
var foundToolCounter bool
405405
for _, sm := range rm.ScopeMetrics {
406406
for _, metric := range sm.Metrics {
407-
if metric.Name == "toolhive_mcp_tool_calls_total" {
407+
if metric.Name == "toolhive_mcp_tool_calls" {
408408
foundToolCounter = true
409409
if sum, ok := metric.Data.(metricdata.Sum[int64]); ok {
410410
assert.NotEmpty(t, sum.DataPoints)
@@ -480,6 +480,6 @@ func TestTelemetryIntegration_MultipleRequests(t *testing.T) {
480480

481481
// The exact count format depends on Prometheus exposition format
482482
// We just verify the metrics are present and contain our server name
483-
assert.Contains(t, metricsBody, "toolhive_mcp_requests_total")
483+
assert.Contains(t, metricsBody, "toolhive_mcp_requests")
484484
assert.Contains(t, metricsBody, `server="multi-test"`)
485485
}

pkg/telemetry/middleware.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ func NewHTTPMiddleware(
5353

5454
// Initialize metrics
5555
requestCounter, _ := meter.Int64Counter(
56-
"toolhive_mcp_requests_total",
56+
"toolhive_mcp_requests", // The exporter adds the _total suffix automatically
5757
metric.WithDescription("Total number of MCP requests"),
5858
)
5959

6060
requestDuration, _ := meter.Float64Histogram(
61-
"toolhive_mcp_request_duration_seconds",
61+
"toolhive_mcp_request_duration", // The exporter adds the _seconds suffix automatically
6262
metric.WithDescription("Duration of MCP requests in seconds"),
6363
metric.WithUnit("s"),
6464
)
@@ -449,7 +449,7 @@ func (m *HTTPMiddleware) recordMetrics(ctx context.Context, r *http.Request, rw
449449

450450
// Record tool-specific counter
451451
if toolCounter, err := m.meter.Int64Counter(
452-
"toolhive_mcp_tool_calls_total",
452+
"toolhive_mcp_tool_calls", // The exporter adds the _total suffix automatically
453453
metric.WithDescription("Total number of MCP tool calls"),
454454
); err == nil {
455455
toolCounter.Add(ctx, 1, toolAttrs)

pkg/telemetry/middleware_sse_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestHTTPMiddleware_RecordSSEConnection(t *testing.T) {
118118
meter := meterProvider.Meter(instrumentationName)
119119

120120
requestCounter, _ := meter.Int64Counter(
121-
"toolhive_mcp_requests_total",
121+
"toolhive_mcp_requests",
122122
metric.WithDescription("Total number of MCP requests"),
123123
)
124124

pkg/telemetry/middleware_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ func TestHTTPMiddleware_WithRealMetrics(t *testing.T) {
655655
for _, sm := range rm.ScopeMetrics {
656656
for _, metric := range sm.Metrics {
657657
switch metric.Name {
658-
case "toolhive_mcp_requests_total":
658+
case "toolhive_mcp_requests":
659659
foundCounter = true
660-
case "toolhive_mcp_request_duration_seconds":
660+
case "toolhive_mcp_request_duration":
661661
foundHistogram = true
662662
case "toolhive_mcp_active_connections":
663663
foundGauge = true

0 commit comments

Comments
 (0)