Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul2393 committed Nov 12, 2024
1 parent 8aa36ea commit 02f989c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 1 addition & 2 deletions spanner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,7 @@ func newClientWithConfig(ctx context.Context, database string, config ClientConf
metricsProvider = noop.NewMeterProvider()
}

// Create a OpenTelemetry metrics configuration
metricsTracerFactory, err := newBuiltinMetricsTracerFactory(ctx, database, metricsProvider, opts...)
metricsTracerFactory, err := newBuiltinMetricsTracerFactory(ctx, database, metricsProvider, config.Compression, opts...)
if err != nil {
return nil, err
}
Expand Down
12 changes: 8 additions & 4 deletions spanner/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import (
"errors"
"fmt"
"hash/fnv"
"strings"

"log"
"os"
"strconv"
"strings"
"time"

"github.com/google/uuid"
Expand All @@ -36,7 +35,9 @@ import (
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
"google.golang.org/api/option"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/status"

"cloud.google.com/go/spanner/internal"
Expand Down Expand Up @@ -198,7 +199,7 @@ type builtinMetricsTracerFactory struct {
attemptCount metric.Int64Counter // Counter for the number of attempts.
}

func newBuiltinMetricsTracerFactory(ctx context.Context, dbpath string, metricsProvider metric.MeterProvider, opts ...option.ClientOption) (*builtinMetricsTracerFactory, error) {
func newBuiltinMetricsTracerFactory(ctx context.Context, dbpath string, metricsProvider metric.MeterProvider, compression string, opts ...option.ClientOption) (*builtinMetricsTracerFactory, error) {
clientUID, err := generateClientUID()
if err != nil {
log.Printf("built-in metrics: generateClientUID failed: %v. Using empty string in the %v metric atteribute", err, metricLabelKeyClientUID)
Expand All @@ -223,7 +224,10 @@ func newBuiltinMetricsTracerFactory(ctx context.Context, dbpath string, metricsP
},
shutdown: func() {},
}

if compression == gzip.Name {
opts = append(opts, option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
grpc.UseCompressor(gzip.Name))))
}
tracerFactory.isDirectPathEnabled = false
tracerFactory.enabled = false
var meterProvider *sdkmetric.MeterProvider
Expand Down
2 changes: 1 addition & 1 deletion spanner/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ func TestIteratorStopEarly(t *testing.T) {
}

func TestIteratorWithError(t *testing.T) {
metricsTracerFactory, err := newBuiltinMetricsTracerFactory(context.Background(), "projects/my-project/instances/my-instance/databases/my-database", noop.NewMeterProvider())
metricsTracerFactory, err := newBuiltinMetricsTracerFactory(context.Background(), "projects/my-project/instances/my-instance/databases/my-database", noop.NewMeterProvider(), "identity")
if err != nil {
t.Fatalf("failed to create metrics tracer factory: %v", err)
}
Expand Down

0 comments on commit 02f989c

Please sign in to comment.