Skip to content

Commit 624736d

Browse files
committed
Add metrics test
1 parent d1e9a3f commit 624736d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package integration
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/ydb-platform/ydb-go-sdk/v3"
8+
"github.com/ydb-platform/ydb-go-sdk/v3/metrics"
9+
"github.com/ydb-platform/ydb-go-sdk/v3/query"
10+
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
11+
)
12+
13+
func TestYDBConnMetrics(t *testing.T) {
14+
var (
15+
scope = newScope(t)
16+
registry = &registryConfig{
17+
details: trace.DriverConnEvents,
18+
gauges: newVec[gaugeVec](),
19+
counters: newVec[counterVec](),
20+
timers: newVec[timerVec](),
21+
histograms: newVec[histogramVec](),
22+
}
23+
)
24+
25+
db, err := ydb.Open(scope.Ctx, "grpc://localhost:2136/local", metrics.WithTraces(registry))
26+
scope.Require.NoError(err)
27+
defer db.Close(scope.Ctx) // cleanup resources
28+
29+
db.Query().Do(scope.Ctx, func(ctx context.Context, s query.Session) error {
30+
return s.Exec(ctx, "SELECT 42")
31+
})
32+
33+
metric := "ydb.driver.conns"
34+
labelsNames := []string{"endpoint", "node_id"}
35+
labels := map[string]string{"endpoint": "localhost:2136", "node_id": "1"}
36+
37+
gauges := registry.gauges.data[nameLabelNamesToString(metric, labelsNames)]
38+
scope.Require.NotNil(gauges)
39+
40+
labeledGauges := gauges.gauges[nameLabelValuesToString(metric, labels)]
41+
scope.Require.NotNil(labeledGauges)
42+
43+
scope.Require.EqualValues(1, labeledGauges.value)
44+
}

0 commit comments

Comments
 (0)