-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
stats_test.go
45 lines (36 loc) · 1013 Bytes
/
stats_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package otelsql_test
import (
"testing"
"time"
"github.com/stretchr/testify/require"
semconv "go.opentelemetry.io/otel/semconv/v1.20.0"
"go.nhat.io/otelsql"
"go.nhat.io/otelsql/internal/test/oteltest"
"go.nhat.io/otelsql/internal/test/sqlmock"
)
func TestRecordStats(t *testing.T) {
t.Parallel()
expectedMetrics := expectedStatsMetric()
oteltest.New(
oteltest.MetricsEqualJSON(expectedMetrics),
oteltest.MockDatabase(func(m sqlmock.Sqlmock) {
m.ExpectPing()
}),
).
Run(t, func(sc oteltest.SuiteContext) {
db, err := newDB(sc.DatabaseDSN())
require.NoError(t, err)
err = otelsql.RecordStats(db,
otelsql.WithMeterProvider(sc.MeterProvider()),
otelsql.WithMinimumReadDBStatsInterval(100*time.Millisecond),
otelsql.WithInstanceName("default"),
otelsql.WithSystem(semconv.DBSystemPostgreSQL),
)
require.NoError(t, err)
err = db.Ping()
require.NoError(t, err)
})
}
func expectedStatsMetric() string {
return expectedMetricsFromFile("stats.json")
}