-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(storage): add grpc metrics experimental options #10984
Changes from 5 commits
1e00c56
56a21af
45ada59
797cb7d
dde7cbd
f901a2e
aee0bf1
475f37a
28d675f
22d23ee
a898518
2210b54
2bf7e35
243b0a6
154fa54
fa56a51
31dc86b
596199d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// All options in this package are experimental. | ||
|
||
package experimental | ||
|
||
import ( | ||
"time" | ||
|
||
"cloud.google.com/go/storage/internal" | ||
"go.opentelemetry.io/otel/sdk/metric" | ||
"google.golang.org/api/option" | ||
) | ||
|
||
// WithMetricInterval how often to emit metrics when using NewPeriodicReader | ||
// https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric#NewPeriodicReader | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leave an empty line (with a |
||
// https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric#WithInterval | ||
func WithMetricInterval(metricInterval time.Duration) option.ClientOption { | ||
return internal.WithMetricInterval.(func(time.Duration) option.ClientOption)(metricInterval) | ||
} | ||
|
||
// WithMetricExporter provide alternate client-side meterProvider | ||
// to emit metrics through. | ||
// Must implement interface metric.Exporter: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just do [metric.Exporter] and the godoc should autolink. |
||
// https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric#Exporter | ||
func WithMetricExporter(ex *metric.Exporter) option.ClientOption { | ||
return internal.WithMetricInterval.(func(*metric.Exporter) option.ClientOption)(ex) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// All options in this package are experimental. | ||
|
||
package internal | ||
|
||
var ( | ||
// WithMetricInterval how often to emit metrics when using NewPeriodicReader | ||
// https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric#NewPeriodicReader | ||
// https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric#WithInterval | ||
WithMetricInterval any | ||
|
||
// WithMetricExporter provide alternate client-side meterProvider | ||
// to emit metrics through. | ||
// Must implement interface metric.Exporter: | ||
// https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric#Exporter | ||
WithMetricExporter any | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,16 +15,28 @@ | |
package storage | ||
|
||
import ( | ||
"time" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this got moved but it will probably break formatting presubmits |
||
|
||
storageinternal "cloud.google.com/go/storage/internal" | ||
"go.opentelemetry.io/otel/sdk/metric" | ||
"google.golang.org/api/option" | ||
"google.golang.org/api/option/internaloption" | ||
) | ||
|
||
func init() { | ||
// initialize experimental options | ||
storageinternal.WithMetricInterval = withMetricInterval | ||
storageinternal.WithMetricExporter = withMetricExporter | ||
} | ||
|
||
// storageConfig contains the Storage client option configuration that can be | ||
// set through storageClientOptions. | ||
type storageConfig struct { | ||
useJSONforReads bool | ||
readAPIWasSet bool | ||
disableClientMetrics bool | ||
metricExporter *metric.Exporter | ||
metricInterval time.Duration | ||
} | ||
|
||
// newStorageConfig generates a new storageConfig with all the given | ||
|
@@ -108,3 +120,31 @@ func WithDisabledClientMetrics() option.ClientOption { | |
func (w *withDisabledClientMetrics) ApplyStorageOpt(c *storageConfig) { | ||
c.disableClientMetrics = w.disabledClientMetrics | ||
} | ||
|
||
type withMeterOptions struct { | ||
internaloption.EmbeddableAdapter | ||
// set sampling interval | ||
interval time.Duration | ||
} | ||
|
||
func withMetricInterval(interval time.Duration) option.ClientOption { | ||
return &withMeterOptions{interval: interval} | ||
} | ||
|
||
func (w *withMeterOptions) ApplyStorageOpt(c *storageConfig) { | ||
c.metricInterval = w.interval | ||
} | ||
|
||
type withMetricExporterConfig struct { | ||
internaloption.EmbeddableAdapter | ||
// exporter override | ||
metricExporter *metric.Exporter | ||
} | ||
|
||
func withMetricExporter(ex *metric.Exporter) option.ClientOption { | ||
return &withMetricExporterConfig{metricExporter: ex} | ||
} | ||
|
||
func (w *withMetricExporterConfig) ApplyStorageOpt(c *storageConfig) { | ||
c.metricExporter = w.metricExporter | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it clear that these options are supposed to be used with storage.NewClient.