-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed ydb_go_sdk_ydb_database_sql_conns metric + added integration te…
…st for check metric
- Loading branch information
1 parent
43cd76c
commit 21035c5
Showing
8 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package xslices | ||
|
||
import ( | ||
"cmp" | ||
"slices" | ||
) | ||
|
||
func Keys[Key cmp.Ordered, T any](m map[Key]T) []Key { | ||
keys := make([]Key, 0, len(m)) | ||
|
||
for key := range m { | ||
keys = append(keys, key) | ||
} | ||
|
||
slices.Sort(keys) | ||
|
||
return keys | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package xslices | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestKeys(t *testing.T) { | ||
require.Equal(t, []string{"1", "2"}, Keys(map[string]any{ | ||
"1": nil, | ||
"2": nil, | ||
})) | ||
require.Equal(t, []int{1, 2}, Keys(map[int]any{ | ||
1: nil, | ||
2: nil, | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ydb-platform/ydb-go-sdk/v3" | ||
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xslices" | ||
"github.com/ydb-platform/ydb-go-sdk/v3/metrics" | ||
"github.com/ydb-platform/ydb-go-sdk/v3/trace" | ||
) | ||
|
||
func TestDatabaseSqlMetrics(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
var ( | ||
scope = newScope(t) | ||
registry = ®istryConfig{ | ||
details: trace.DatabaseSQLEvents, | ||
gauges: newVec[gaugeVec](), | ||
counters: newVec[counterVec](), | ||
timers: newVec[timerVec](), | ||
histograms: newVec[histogramVec](), | ||
} | ||
db = scope.SQLDriver(ydb.WithDatabaseSQLTrace(metrics.DatabaseSQL(registry))) | ||
) | ||
|
||
require.Equal(t, | ||
[]string{"database.sql.conns{}", "database.sql.tx{}"}, | ||
xslices.Keys(registry.gauges.data), | ||
) | ||
require.EqualValues(t, 1, registry.gauges.data["database.sql.conns{}"].gauges["database.sql.conns{}"].value) | ||
|
||
cc1, err := db.Conn(ctx) | ||
require.NoError(t, err) | ||
require.NotNil(t, cc1) | ||
require.EqualValues(t, 1, registry.gauges.data["database.sql.conns{}"].gauges["database.sql.conns{}"].value) | ||
require.Empty(t, registry.gauges.data["database.sql.tx{}"].gauges) | ||
|
||
cc2, err := db.Conn(ctx) | ||
require.NoError(t, err) | ||
require.NotNil(t, cc2) | ||
require.EqualValues(t, 2, registry.gauges.data["database.sql.conns{}"].gauges["database.sql.conns{}"].value) | ||
require.Empty(t, registry.gauges.data["database.sql.tx{}"].gauges) | ||
|
||
tx1, err := cc1.BeginTx(ctx, nil) | ||
require.NoError(t, err) | ||
require.NotNil(t, tx1) | ||
require.NotEmpty(t, registry.gauges.data["database.sql.tx{}"].gauges) | ||
require.EqualValues(t, 1, registry.gauges.data["database.sql.tx{}"].gauges["database.sql.tx{}"].value) | ||
|
||
require.NoError(t, tx1.Commit()) | ||
require.EqualValues(t, 0, registry.gauges.data["database.sql.tx{}"].gauges["database.sql.tx{}"].value) | ||
|
||
require.NoError(t, cc1.Close()) | ||
require.EqualValues(t, 2, registry.gauges.data["database.sql.conns{}"].gauges["database.sql.conns{}"].value) | ||
|
||
tx2, err := cc2.BeginTx(ctx, nil) | ||
require.NoError(t, err) | ||
require.NotNil(t, tx2) | ||
require.NotEmpty(t, registry.gauges.data["database.sql.tx{}"].gauges) | ||
require.EqualValues(t, 1, registry.gauges.data["database.sql.tx{}"].gauges["database.sql.tx{}"].value) | ||
|
||
require.NoError(t, tx2.Rollback()) | ||
require.EqualValues(t, 0, registry.gauges.data["database.sql.tx{}"].gauges["database.sql.tx{}"].value) | ||
|
||
require.NoError(t, cc2.Close()) | ||
require.EqualValues(t, 2, registry.gauges.data["database.sql.conns{}"].gauges["database.sql.conns{}"].value) | ||
|
||
require.NoError(t, db.Close()) | ||
require.EqualValues(t, 0, registry.gauges.data["database.sql.conns{}"].gauges["database.sql.conns{}"].value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.