-
Notifications
You must be signed in to change notification settings - Fork 133
chore(spanner): add initial setup for built-in metrics #5967
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,9 @@ default = ["default-rustls-provider"] | |
| # TLS and authentication. Applications with specific requirements for | ||
| # cryptography (such as exclusively using the [ring] crate) should disable this | ||
| # default and call `rustls::CryptoProvider::install_default()`. | ||
| default-rustls-provider = ["gaxi/_default-rustls-provider"] | ||
| unstable-stream = ["dep:futures"] | ||
| default-rustls-provider = ["gaxi/_default-rustls-provider"] | ||
| unstable-stream = ["dep:futures"] | ||
| experimental-builtin-metrics = ["dep:google-cloud-monitoring-v3", "dep:opentelemetry", "dep:opentelemetry_sdk"] | ||
|
|
||
| [dependencies] | ||
| async-trait.workspace = true | ||
|
|
@@ -60,6 +61,11 @@ tracing.workspace = true | |
| url.workspace = true | ||
| wkt = { workspace = true, features = ["time"] } | ||
|
|
||
| # Optional dependencies for built-in metrics | ||
| google-cloud-monitoring-v3 = { workspace = true, optional = true } | ||
|
Contributor
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. The new shinny is to use the OpenTelemetry Lightweight Protocol (OTLP). Google Cloud supports the protocol. There are Rust exporters for OTLP, they do lack a connector to inject the auth headers. |
||
| opentelemetry = { workspace = true, optional = true, features = ["metrics"] } | ||
| opentelemetry_sdk = { workspace = true, optional = true, features = ["metrics", "rt-tokio"] } | ||
|
|
||
| [dev-dependencies] | ||
| anyhow.workspace = true | ||
| google-cloud-test-macros.workspace = true | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright 2026 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 | ||
| // | ||
| // https://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. | ||
|
|
||
| use google_cloud_monitoring_v3::client::MetricService; | ||
| use opentelemetry_sdk::error::OTelSdkResult; | ||
| use opentelemetry_sdk::metrics::Temporality; | ||
| use opentelemetry_sdk::metrics::data::ResourceMetrics; | ||
| use opentelemetry_sdk::metrics::exporter::PushMetricExporter; | ||
| use std::sync::Arc; | ||
| use std::time::Duration; | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| pub(crate) struct GcpMonitoringExporter { | ||
| #[allow(dead_code)] | ||
| client: Arc<MetricService>, | ||
| #[allow(dead_code)] | ||
| project_name: String, | ||
| } | ||
|
|
||
| impl GcpMonitoringExporter { | ||
| pub(crate) fn new(client: MetricService, project_id: &str) -> Self { | ||
| Self { | ||
| client: Arc::new(client), | ||
| project_name: format!("projects/{}", project_id), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl PushMetricExporter for GcpMonitoringExporter { | ||
| async fn export(&self, _metrics: &ResourceMetrics) -> OTelSdkResult { | ||
| // TODO: Map ResourceMetrics to CreateTimeSeriesRequest and send via self.client | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn force_flush(&self) -> OTelSdkResult { | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn shutdown(&self) -> OTelSdkResult { | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult { | ||
| self.shutdown() | ||
| } | ||
|
|
||
| fn temporality(&self) -> Temporality { | ||
| Temporality::Cumulative | ||
| } | ||
| } |
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.
A thing we learnt the hard way: removing a public feature is a breaking change. You may want to name this
_experimental-builtin-metricsbecause that makes the feature private (by convention) and then removing it is fine.