mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
* fix: connection closure metrics and enable all metric groups by default
This commit addresses three issues in the redisotel-native metrics implementation:
1. Fix connection closure metrics not appearing in dashboards
- Root cause: CloseConn() in internal/pool/pool.go was not calling
the metricConnectionClosedCallback when closing stale connections
- Added callback invocation in CloseConn() to record 'stale' closures
2. Verify tracing and metrics compatibility
- Added TestTracingAndMetricsCompatibility to document that
redisotel (tracing via AddHook) and redisotel-native (metrics via
SetOTelRecorder) can coexist without conflicts
3. Enable all metric groups by default
- Changed default MetricGroups from connection-basic+resiliency
to MetricGroupAll for comprehensive observability out of the box
62 lines
2.3 KiB
Go
62 lines
2.3 KiB
Go
package redisotel
|
|
|
|
import "testing"
|
|
|
|
// Expected metric names per OTel semantic conventions.
|
|
// Reference: https://opentelemetry.io/docs/specs/semconv/database/database-metrics/
|
|
const (
|
|
semconvOperationDuration = "db.client.operation.duration"
|
|
semconvConnectionCount = "db.client.connection.count"
|
|
semconvConnectionCreateTime = "db.client.connection.create_time"
|
|
semconvConnectionWaitTime = "db.client.connection.wait_time"
|
|
semconvConnectionPending = "db.client.connection.pending_requests"
|
|
)
|
|
|
|
// TestMetricDefinitionsMatchSemconv verifies metric names match OTel semantic conventions.
|
|
func TestMetricDefinitionsMatchSemconv(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
got string
|
|
expected string
|
|
}{
|
|
{"db.client.operation.duration", MetricOperationDuration, semconvOperationDuration},
|
|
{"db.client.connection.count", MetricConnectionCount, semconvConnectionCount},
|
|
{"db.client.connection.create_time", MetricConnectionCreateTime, semconvConnectionCreateTime},
|
|
{"db.client.connection.wait_time", MetricConnectionWaitTime, semconvConnectionWaitTime},
|
|
{"db.client.connection.pending_requests", MetricConnectionPendingReqs, semconvConnectionPending},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.got != tt.expected {
|
|
t.Errorf("got %q, want %q", tt.got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestSemconvMetricTypes documents expected metric instrument types.
|
|
// Semconv specifies UpDownCounter for connection.count and pending_requests,
|
|
// but this implementation uses ObservableGauge (known deviation, see issue #3730).
|
|
func TestSemconvMetricTypes(t *testing.T) {
|
|
t.Run("connection.count uses Gauge (semconv specifies UpDownCounter)", func(t *testing.T) {
|
|
// Known deviation: using ObservableGauge instead of UpDownCounter
|
|
})
|
|
|
|
t.Run("pending_requests uses Gauge (semconv specifies UpDownCounter)", func(t *testing.T) {
|
|
// Known deviation: using ObservableGauge instead of UpDownCounter
|
|
})
|
|
|
|
t.Run("operation.duration uses Histogram (correct)", func(t *testing.T) {
|
|
// Matches semconv: Float64Histogram
|
|
})
|
|
|
|
t.Run("connection.create_time uses Histogram (correct)", func(t *testing.T) {
|
|
// Matches semconv: Float64Histogram
|
|
})
|
|
|
|
t.Run("connection.wait_time uses Histogram (correct)", func(t *testing.T) {
|
|
// Matches semconv: Float64Histogram
|
|
})
|
|
}
|