-
Notifications
You must be signed in to change notification settings - Fork 106
feat: add custom attempt latency metric #2882
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...va/com/google/cloud/bigtable/data/v2/internal/csm/exporter/BigtableFilteringExporter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.internal.csm.exporter; | ||
|
|
||
| import io.opentelemetry.sdk.common.CompletableResultCode; | ||
| import io.opentelemetry.sdk.metrics.InstrumentType; | ||
| import io.opentelemetry.sdk.metrics.data.AggregationTemporality; | ||
| import io.opentelemetry.sdk.metrics.data.MetricData; | ||
| import io.opentelemetry.sdk.metrics.export.MetricExporter; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class BigtableFilteringExporter implements MetricExporter { | ||
|
|
||
| private MetricExporter delegate; | ||
| private Predicate<MetricData> filter; | ||
|
|
||
| public BigtableFilteringExporter(MetricExporter exporter, Predicate<MetricData> filter) { | ||
| this.delegate = exporter; | ||
| this.filter = filter; | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableResultCode export(Collection<MetricData> metrics) { | ||
| List<MetricData> filtered = metrics.stream().filter(filter).collect(Collectors.toList()); | ||
| return delegate.export(filtered); | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableResultCode flush() { | ||
| return delegate.flush(); | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableResultCode shutdown() { | ||
| return delegate.shutdown(); | ||
| } | ||
|
|
||
| public void prepareForShutdown() { | ||
| if (delegate instanceof BigtableCloudMonitoringExporter) { | ||
| ((BigtableCloudMonitoringExporter) delegate).prepareForShutdown(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType) { | ||
| return delegate.getAggregationTemporality(instrumentType); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ain/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/CustomAttemptLatency.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.internal.csm.metrics; | ||
|
|
||
| import com.google.bigtable.v2.ClusterInformation; | ||
| import com.google.bigtable.v2.PeerInfo; | ||
| import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo; | ||
| import com.google.cloud.bigtable.data.v2.internal.csm.attributes.MethodInfo; | ||
| import com.google.cloud.bigtable.data.v2.internal.csm.attributes.Util; | ||
| import com.google.cloud.bigtable.data.v2.internal.csm.schema.CustomSchema; | ||
| import io.grpc.Status; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.metrics.DoubleHistogram; | ||
| import io.opentelemetry.api.metrics.Meter; | ||
| import java.time.Duration; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Custom attempt latencies with afe id metric label. This metric is high cardinality and is | ||
| * exported as a custom metric. | ||
| */ | ||
| public class CustomAttemptLatency extends MetricWrapper<CustomSchema> { | ||
| private static final String NAME = "bigtable.custom.attempt_latencies"; | ||
|
|
||
| public CustomAttemptLatency() { | ||
| super(CustomSchema.INSTANCE, NAME); | ||
| } | ||
|
|
||
| public Recorder newRecorder(Meter meter) { | ||
| return new Recorder(meter); | ||
| } | ||
|
|
||
| public static class Recorder { | ||
| private final DoubleHistogram instrument; | ||
|
|
||
| private Recorder(Meter meter) { | ||
| instrument = | ||
| meter | ||
| .histogramBuilder(NAME) | ||
| .setDescription("Client observed latency per RPC attempt.") | ||
| .setUnit(Constants.Units.MILLISECOND) | ||
| .setExplicitBucketBoundariesAdvice( | ||
| Constants.Buckets.AGGREGATION_WITH_MILLIS_HISTOGRAM) | ||
| .build(); | ||
| } | ||
|
|
||
| public void record( | ||
| ClientInfo clientInfo, | ||
| String tableId, | ||
| @Nullable PeerInfo peerInfo, | ||
| @Nullable ClusterInformation clusterInfo, | ||
| MethodInfo methodInfo, | ||
| Status.Code code, | ||
| Duration latency) { | ||
|
|
||
| Attributes attributes = | ||
| Attributes.builder() | ||
| .put( | ||
| Constants.MetricLabels.BIGTABLE_PROJECT_ID_KEY, | ||
| clientInfo.getInstanceName().getProjectId()) | ||
| .put( | ||
| Constants.MetricLabels.INSTANCE_ID_KEY, | ||
| clientInfo.getInstanceName().getInstanceId()) | ||
| .put("table", tableId) | ||
| .put(Constants.MetricLabels.APP_PROFILE_KEY, clientInfo.getAppProfileId()) | ||
| .put("cluster", Util.formatClusterIdMetricLabel(clusterInfo)) | ||
| .put("zone", Util.formatZoneIdMetricLabel(clusterInfo)) | ||
| .put(Constants.MetricLabels.STATUS_KEY, code.name()) | ||
| .put(Constants.MetricLabels.METHOD_KEY, methodInfo.getName()) | ||
| .put("afe_id", Util.formatAfeId(peerInfo)) | ||
| .build(); | ||
|
|
||
| instrument.record(toMillis(latency), attributes); | ||
| } | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...ble/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/schema/CustomSchema.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package com.google.cloud.bigtable.data.v2.internal.csm.schema; | ||
|
|
||
| import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo; | ||
| import com.google.cloud.bigtable.data.v2.internal.csm.attributes.EnvInfo; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.monitoring.v3.ProjectName; | ||
| import io.opentelemetry.api.common.Attributes; | ||
|
|
||
| /** Placeholder schema for exporting custom metrics */ | ||
| public class CustomSchema extends Schema { | ||
| private CustomSchema() { | ||
| super("custom_schema", ImmutableList.of()); | ||
| } | ||
|
|
||
| public static final CustomSchema INSTANCE = new CustomSchema(); | ||
|
|
||
| @Override | ||
| public ProjectName extractProjectName(Attributes attrs, EnvInfo envInfo, ClientInfo clientInfo) { | ||
| return ProjectName.of(clientInfo.getInstanceName().getProjectId()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.