Skip to content

Commit 2624564

Browse files
committed
test/postgres: add test instrumentation
Signed-off-by: Hank Donnay <hdonnay@redhat.com> Change-Id: I1c27d409ec9894aae92abfb6d52fd750e73cc755
1 parent dc03410 commit 2624564

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

test/postgres/db_common.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/jackc/pgx/v5/log/testingadapter"
1313
"github.com/jackc/pgx/v5/pgxpool"
1414
"github.com/jackc/pgx/v5/tracelog"
15+
"go.opentelemetry.io/otel/attribute"
16+
"go.opentelemetry.io/otel/trace"
1517

1618
"github.com/quay/claircore/datastore/postgres/migrations"
1719
"github.com/quay/claircore/datastore/postgres/types"
@@ -23,6 +25,8 @@ import (
2325
//
2426
// If any errors are encountered, the test is failed and exited.
2527
func TestMatcherDB(ctx context.Context, t testing.TB) *pgxpool.Pool {
28+
ctx, span := tracer.Start(ctx, "TestMatcherDB")
29+
defer span.End()
2630
return testDB(ctx, t, dbMatcher)
2731
}
2832

@@ -31,6 +35,8 @@ func TestMatcherDB(ctx context.Context, t testing.TB) *pgxpool.Pool {
3135
//
3236
// If any errors are encountered, the test is failed and exited.
3337
func TestIndexerDB(ctx context.Context, t testing.TB) *pgxpool.Pool {
38+
ctx, span := tracer.Start(ctx, "TestIndexerDB")
39+
defer span.End()
3440
return testDB(ctx, t, dbIndexer)
3541
}
3642

@@ -93,6 +99,7 @@ var extraSQL embed.FS
9399
// The "flavor" argument selects which prefix is added onto the file glob.
94100
func loadHelpers(ctx context.Context, t testing.TB, pool *pgxpool.Pool, flavor dbFlavor) {
95101
t.Helper()
102+
span := trace.SpanFromContext(ctx)
96103
logprefix := [...]string{"global", "local"}
97104
var look []fs.FS
98105
if sys, err := fs.Sub(extraSQL, "sql"); err != nil {
@@ -104,6 +111,7 @@ func loadHelpers(ctx context.Context, t testing.TB, pool *pgxpool.Pool, flavor d
104111
// is a helper library, this is different than you may expect.
105112
if sys, err := fs.Sub(os.DirFS("."), "testdata"); err != nil {
106113
t.Log("no testdata directory, skipping local loading")
114+
span.AddEvent(`skip_local`)
107115
} else {
108116
look = append(look, sys)
109117
}
@@ -126,6 +134,7 @@ func loadHelpers(ctx context.Context, t testing.TB, pool *pgxpool.Pool, flavor d
126134
if err != nil {
127135
panic(fmt.Sprintf("programmer error: %v", err))
128136
}
137+
span.AddEvent(`load_sql`, trace.WithAttributes(attribute.StringSlice(`files`, ms)))
129138
for _, f := range ms {
130139
b, err := fs.ReadFile(sys, f)
131140
if err != nil {

test/postgres/instrumentation.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package postgres
2+
3+
import (
4+
"go.opentelemetry.io/otel"
5+
"go.opentelemetry.io/otel/trace"
6+
)
7+
8+
var tracer trace.Tracer
9+
10+
func init() {
11+
tracer = otel.Tracer("github.com/claircore/test/postgres")
12+
}

0 commit comments

Comments
 (0)