-
Notifications
You must be signed in to change notification settings - Fork 75
Feat: client side metrics #1840
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 1 commit
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
30a7011
enable 4 metrics from GAX
milaGGL ed85413
format
milaGGL 57084c4
add default otel
milaGGL 571c095
format
milaGGL f4b8416
move constants out
milaGGL da0fe82
format
milaGGL 61432eb
add additional attributes
milaGGL b5bfe5c
Merge branch 'main' into mila/client-side-metrics-demo
milaGGL f0a029d
add attributes to gax metrics
milaGGL 5456038
Update BuiltinMetricsConstants.java
milaGGL 5efaba6
remove current metrics implementation
milaGGL c0b4cc1
add custom exporter, add latency recorder
milaGGL 3979331
use 2 otel instances
milaGGL a9d08b5
set custom apiTracerFactory to gax
milaGGL 029bd8c
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL 50e05fb
fix opentelemtry dependency version conflict issue
milaGGL 53cd48a
use enabled/disabled style
milaGGL 7adb9d6
modify access modifiers
milaGGL 690e4ee
format
milaGGL e6f8ba6
rename boolean
milaGGL c4ca4ae
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL 887221d
chore: generate libraries at Fri Sep 27 19:25:02 UTC 2024
cloud-java-bot a2c715a
Update pom.xml
milaGGL ed78182
resolve comments from proto
milaGGL e0d46be
e2E latency for runTransaction
milaGGL a72a685
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL 92c83c1
chore: generate libraries at Fri Oct 4 14:44:19 UTC 2024
cloud-java-bot c5137c1
remove noise
milaGGL 63b5bd3
reformat code
milaGGL ac424a6
re-format code
milaGGL 52f428f
add documentations/comments
milaGGL c06b2cb
remove logger.info
milaGGL daf9fbe
record AggregationQuery firstResponseLatency
milaGGL 1999ff7
Update BuiltinMetricsProvider.java
milaGGL 81e349b
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL f4e36d9
resolve comments
milaGGL 05e8efb
Update pom.xml
milaGGL b0b1687
remove duplicated tracing dependency
milaGGL 4abbcf0
add opentelemetry-sdk-metrics dependency
milaGGL 328855d
adjust end-to-end latency in streaming queries
milaGGL 5e1fb4b
fix clirr error
milaGGL 4fa8874
add exportBuiltinMetricsToGoogleCloudMonitoring flag
milaGGL 7deb0d6
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL 637f878
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL 8480fa8
Update clirr-ignored-differences.xml
milaGGL ef9baa8
add internalStream clirr change back
milaGGL 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
move constants out
- Loading branch information
commit f4b8416aed326d3290aaf6db01cd6cda920440c6
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
...firestore/src/main/java/com/google/cloud/firestore/telemetry/BuiltinMetricsConstants.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,139 @@ | ||
| package com.google.cloud.firestore.telemetry; | ||
|
|
||
| import com.google.api.gax.tracing.OpenTelemetryMetricsRecorder; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.sdk.metrics.InstrumentSelector; | ||
| import io.opentelemetry.sdk.metrics.View; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class BuiltinMetricsConstants { | ||
|
|
||
| static final String FIRESTORE_METER_NAME = "firestore_java"; | ||
|
|
||
| // TODO: change to firestore.googleapis.com | ||
| public static final String METER_NAME = "custom.googleapis.com/internal/client"; | ||
| public static final String GAX_METER_NAME = OpenTelemetryMetricsRecorder.GAX_METER_NAME; | ||
|
|
||
| // Metric attribute keys for monitored resource | ||
| static final AttributeKey<String> PROJECT_ID_KEY = AttributeKey.stringKey("project_id"); | ||
| // public static final AttributeKey<String> INSTANCE_ID_KEY = AttributeKey.stringKey("instance"); | ||
|
|
||
| // Metric attribute keys for labels | ||
| // static final AttributeKey<String> LANGUAGE_KEY = AttributeKey.stringKey("language"); | ||
| static final AttributeKey<String> METHOD_NAME_KEY = AttributeKey.stringKey("method_name"); | ||
| static final AttributeKey<String> STATUS_KEY = AttributeKey.stringKey("status"); | ||
| public static final AttributeKey<String> DATABASE_ID_KEY = AttributeKey.stringKey("database_id"); | ||
| static final AttributeKey<String> CLIENT_LIBRARY_KEY = AttributeKey.stringKey("client_library"); | ||
| static final AttributeKey<String> LIBRARY_VERSION_KEY = AttributeKey.stringKey("library_version"); | ||
| static final AttributeKey<String> CLIENT_UID_KEY = AttributeKey.stringKey("client_uid"); | ||
|
|
||
| static final AttributeKey<String> Language_KEY = AttributeKey.stringKey("language"); | ||
| public static final AttributeKey<String> SERVICE_NAME = AttributeKey.stringKey("service.name"); | ||
| // Metric | ||
| static final String OPERATION_LATENCY_NAME = "operation_latency"; | ||
| static final String OPERATION_COUNT_NAME = "operation_count"; | ||
| static final String ATTEMPT_LATENCY_NAME = "attempt_latency"; | ||
| static final String ATTEMPT_COUNT_NAME = "attempt_count"; | ||
| static final String FIRST_RESPONSE_LATENCY_NAME = "first_response_latency"; | ||
| static final String END_TO_END_LATENCY_NAME = "end_to_end_latency"; | ||
| static final String TRANSACTION_LATENCY_NAME = "transaction_latency"; | ||
| static final String TRANSACTION_ATTEMPT_COUNT_NAME = "transaction_attempt_count"; | ||
|
|
||
| static final String MILLISECOND_UNIT = "ms"; | ||
|
|
||
| public static final String ENABLE_METRICS_ENV_VAR = "FIRESTORE_ENABLE_TRACING"; | ||
|
|
||
| public static final Set<AttributeKey> COMMON_ATTRIBUTES = | ||
| ImmutableSet.of( | ||
| PROJECT_ID_KEY, | ||
| DATABASE_ID_KEY, | ||
| CLIENT_UID_KEY, | ||
| CLIENT_LIBRARY_KEY, | ||
| LIBRARY_VERSION_KEY, | ||
| STATUS_KEY); | ||
|
|
||
| public static final Set<String> BUILTIN_METRICS = | ||
| ImmutableSet.of( | ||
| OPERATION_LATENCY_NAME, | ||
| ATTEMPT_LATENCY_NAME, | ||
| OPERATION_COUNT_NAME, | ||
| ATTEMPT_COUNT_NAME, | ||
| FIRST_RESPONSE_LATENCY_NAME, | ||
| END_TO_END_LATENCY_NAME, | ||
| TRANSACTION_LATENCY_NAME, | ||
| TRANSACTION_ATTEMPT_COUNT_NAME) | ||
| .stream() | ||
| .map(m -> METER_NAME + '/' + m) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| static void defineView( | ||
| ImmutableMap.Builder<InstrumentSelector, View> viewMap, | ||
| String id, | ||
| Set<AttributeKey> attributes) { | ||
| InstrumentSelector selector = | ||
| InstrumentSelector.builder().setName(METER_NAME + "/" + id).build(); | ||
| Set<String> attributesFilter = | ||
| ImmutableSet.<String>builder() | ||
| .addAll(attributes.stream().map(AttributeKey::getKey).collect(Collectors.toSet())) | ||
| .build(); | ||
| View view = View.builder().setAttributeFilter(attributesFilter).build(); | ||
|
|
||
| viewMap.put(selector, view); | ||
| } | ||
|
|
||
| public static Map<InstrumentSelector, View> getAllViews() { | ||
| ImmutableMap.Builder<InstrumentSelector, View> views = ImmutableMap.builder(); | ||
|
|
||
| defineView( | ||
| views, | ||
| OPERATION_LATENCY_NAME, | ||
| ImmutableSet.<AttributeKey>builder() | ||
| .addAll(COMMON_ATTRIBUTES) | ||
| .add(METHOD_NAME_KEY) | ||
| .build()); | ||
| defineView( | ||
| views, | ||
| ATTEMPT_LATENCY_NAME, | ||
| ImmutableSet.<AttributeKey>builder() | ||
| .addAll(COMMON_ATTRIBUTES) | ||
| .add(METHOD_NAME_KEY) | ||
| .build()); | ||
|
|
||
| defineView( | ||
| views, | ||
| OPERATION_COUNT_NAME, | ||
| ImmutableSet.<AttributeKey>builder() | ||
| .addAll(COMMON_ATTRIBUTES) | ||
| .add(METHOD_NAME_KEY) | ||
| .build()); | ||
|
|
||
| defineView( | ||
| views, | ||
| ATTEMPT_COUNT_NAME, | ||
| ImmutableSet.<AttributeKey>builder() | ||
| .addAll(COMMON_ATTRIBUTES) | ||
| .add(METHOD_NAME_KEY) | ||
| .build()); | ||
|
|
||
| defineView( | ||
| views, | ||
| FIRST_RESPONSE_LATENCY_NAME, | ||
| ImmutableSet.<AttributeKey>builder() | ||
| .addAll(COMMON_ATTRIBUTES) | ||
| .add(METHOD_NAME_KEY) | ||
| .build()); | ||
|
|
||
| defineView( | ||
| views, | ||
| END_TO_END_LATENCY_NAME, | ||
| ImmutableSet.<AttributeKey>builder() | ||
| .addAll(COMMON_ATTRIBUTES) | ||
| .add(METHOD_NAME_KEY) | ||
| .build()); | ||
| return views.build(); | ||
| } | ||
| } | ||
56 changes: 56 additions & 0 deletions
56
...loud-firestore/src/main/java/com/google/cloud/firestore/telemetry/BuiltinMetricsView.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,56 @@ | ||
| package com.google.cloud.firestore.telemetry; | ||
|
|
||
| /* | ||
| * Copyright 2023 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. | ||
| */ | ||
|
|
||
| import static com.google.cloud.firestore.telemetry.BuiltinMetricsConstants.*; | ||
|
|
||
| import com.google.cloud.opentelemetry.metric.GoogleCloudMetricExporter; | ||
| import com.google.cloud.opentelemetry.metric.MetricConfiguration; | ||
| import io.opentelemetry.sdk.metrics.InstrumentSelector; | ||
| import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; | ||
| import io.opentelemetry.sdk.metrics.View; | ||
| import io.opentelemetry.sdk.metrics.export.MetricExporter; | ||
| import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; | ||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| public class BuiltinMetricsView { | ||
|
|
||
| private BuiltinMetricsView() {} | ||
|
|
||
| /** Register built-in metrics on the {@link SdkMeterProviderBuilder} with credentials. */ | ||
| public static void registerBuiltinMetrics(String projectId, SdkMeterProviderBuilder builder) | ||
| throws IOException { | ||
|
|
||
| // Attach built-in exporter | ||
| MetricExporter metricExporter = | ||
| GoogleCloudMetricExporter.createWithConfiguration( | ||
| MetricConfiguration.builder().setProjectId(projectId).build()); | ||
|
|
||
| builder.registerMetricReader(PeriodicMetricReader.builder(metricExporter).build()); | ||
|
|
||
| // Add static attributes to resource | ||
| // Package pkg = this.getClass().getPackage(); | ||
|
|
||
| // Filter out attributes that are not defined | ||
| for (Map.Entry<InstrumentSelector, View> entry : getAllViews().entrySet()) { | ||
| builder.registerView(entry.getKey(), entry.getValue()); | ||
| } | ||
|
|
||
| builder.registerMetricReader(PeriodicMetricReader.create(metricExporter)); | ||
| } | ||
| } |
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.
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.
Opentelemetry uses dot separation in metrics naming, while monarch uses slash separation. exporting the built-in metrics to other backends might raise naming conflict.
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.
we could have named the metrics with dot seperation, use view to reformat it with slash separation in the default OTEL instance for monarch. But the metrics from Gax uses slash already, using dot separation inside firestore doesn't solves the problem.