Skip to content

Commit

Permalink
test(storage): run metrics enablement test only once
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennaEpp committed Jan 9, 2025
1 parent 4ec1d66 commit 2692642
Showing 1 changed file with 42 additions and 28 deletions.
70 changes: 42 additions & 28 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,37 +636,51 @@ func TestIntegration_DoNotDetectDirectConnectivityWhenDisabled(t *testing.T) {
}

func TestIntegration_MetricsEnablement(t *testing.T) {
ctx := skipHTTP("grpc only test")
ctx = skipExtraReadAPIs(ctx, "no reads in test")
var (
ctx = context.Background()
prefix = grpcTestPrefix
newBucketName = prefix + uidSpace.New()
)

mr := metric.NewManualReader()
multiTransportTest(ctx, t, func(t *testing.T, ctx context.Context, bucket string, prefix string, client *Client) {
it := client.Bucket(bucket).Objects(ctx, nil)
_, err := it.Next()
if err != iterator.Done {
t.Errorf("Objects.Next: expected iterator.Done got %v", err)
}
rm := metricdata.ResourceMetrics{}
if err := mr.Collect(ctx, &rm); err != nil {
t.Fatalf("ManualReader.Collect: %v", err)
}
metricCheck := map[string]bool{
"grpc.client.attempt.started": false,
"grpc.client.attempt.duration": false,
"grpc.client.attempt.sent_total_compressed_message_size": false,
"grpc.client.attempt.rcvd_total_compressed_message_size": false,
"grpc.client.call.duration": false,
}
for _, sm := range rm.ScopeMetrics {
for _, m := range sm.Metrics {
metricCheck[m.Name] = true
}
client := testConfigGRPC(ctx, t, withTestMetricReader(mr))

b := client.Bucket(newBucketName)

if err := b.Create(ctx, testutil.ProjID(), nil); err != nil {
t.Fatalf("BucketHandle.Create(%q): %v", newBucketName, err)
}

it := b.Objects(ctx, nil)
_, err := it.Next()
if err != iterator.Done {
t.Errorf("Objects.Next: expected iterator.Done got %v", err)
}
rm := metricdata.ResourceMetrics{}
if err := mr.Collect(ctx, &rm); err != nil {
t.Fatalf("ManualReader.Collect: %v", err)
}
metricCheck := map[string]bool{
"grpc.client.attempt.started": false,
"grpc.client.attempt.duration": false,
"grpc.client.attempt.sent_total_compressed_message_size": false,
"grpc.client.attempt.rcvd_total_compressed_message_size": false,
"grpc.client.call.duration": false,
}
for _, sm := range rm.ScopeMetrics {
for _, m := range sm.Metrics {
metricCheck[m.Name] = true
}
for k, v := range metricCheck {
if !v {
t.Errorf("metric %v not found", k)
}
}
for k, v := range metricCheck {
if !v {
t.Errorf("metric %v not found", k)
}
}, withTestMetricReader(mr))
}

if err := mr.Shutdown(ctx); err != nil {
t.Fatalf("manual reader shutdown: %v", err)
}
}

func TestIntegration_MetricsEnablementInGCE(t *testing.T) {
Expand Down

0 comments on commit 2692642

Please sign in to comment.