Skip to content

Commit 911bcd8

Browse files
authored
fix(storage): monitored resource detection (#11197)
* fix(storage): populate monitored resource correctly * refactor with additional integration tests * refactor initialization of metricsContext * remove exporter experimental option and add manual reader for tests * go mod tidy * dependency inject gcp detector for testing * revert removal of metricExporter option * revert changes to metricExporter option tests * use struct embedding * pass in resource correctly to exporter * update test using resource value * add tests checking resource values * add option to disable exporter in unit tests * address feedback * use project-id not project_id...
1 parent a3cb8c4 commit 911bcd8

6 files changed

+404
-198
lines changed

storage/grpc_client.go

+19
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"google.golang.org/api/iterator"
3636
"google.golang.org/api/option"
3737
"google.golang.org/api/option/internaloption"
38+
"google.golang.org/api/transport"
3839
"google.golang.org/grpc"
3940
"google.golang.org/grpc/codes"
4041
"google.golang.org/grpc/encoding"
@@ -118,6 +119,24 @@ type grpcStorageClient struct {
118119
settings *settings
119120
}
120121

122+
func enableClientMetrics(ctx context.Context, s *settings, config storageConfig) (*metricsContext, error) {
123+
var project string
124+
// TODO: use new auth client
125+
c, err := transport.Creds(ctx, s.clientOption...)
126+
if err == nil {
127+
project = c.ProjectID
128+
}
129+
metricsContext, err := newGRPCMetricContext(ctx, metricsConfig{
130+
project: project,
131+
interval: config.metricInterval,
132+
manualReader: config.manualReader},
133+
)
134+
if err != nil {
135+
return nil, fmt.Errorf("gRPC Metrics: %w", err)
136+
}
137+
return metricsContext, nil
138+
}
139+
121140
// newGRPCStorageClient initializes a new storageClient that uses the gRPC
122141
// Storage API.
123142
func newGRPCStorageClient(ctx context.Context, opts ...storageOption) (storageClient, error) {

0 commit comments

Comments
 (0)