-
Notifications
You must be signed in to change notification settings - Fork 123
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
chore: client metrics #3125
chore: client metrics #3125
Conversation
fcacc2e
to
d1b47e4
Compare
624b891
to
fd4c4d6
Compare
🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use -- conventional-commit-lint bot |
fd4c4d6
to
122ad02
Compare
f23435e
to
b766d20
Compare
b766d20
to
7bc15e5
Compare
7bc15e5
to
e5ee466
Compare
ccc7862
to
d8f5813
Compare
...loud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsProvider.java
Outdated
Show resolved
Hide resolved
...loud-spanner/src/main/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsProvider.java
Outdated
Show resolved
Hide resolved
@@ -1377,6 +1396,19 @@ public Builder setEnableApiTracing(boolean enableApiTracing) { | |||
return this; | |||
} | |||
|
|||
/** Enabling this will enable built in metrics for each individual RPC execution. */ | |||
@VisibleForTesting | |||
public Builder setEnableBuiltInMetrics(boolean enableBuiltInMetrics) { |
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.
If it is only for testing, can we then use the following trick to make this package-private:
- Make this package-private
- Add a public static method to SpannerOptionsTestHelper that takes a
SpannerOptions.Builder
instance as an argument, and that calls thissetEnableBuiltInMetrics(...)
method. - Call the
SpannerOptionsTestHelper
method from the tests that need to set this value.
boolean isDirectPathChannelCreated = | ||
defaultChannelProvider.canUseDirectPath() | ||
&& defaultChannelProvider.isDirectPathXdsEnabled(); |
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.
I think that this should be:
boolean isDirectPathChannelCreated = | |
defaultChannelProvider.canUseDirectPath() | |
&& defaultChannelProvider.isDirectPathXdsEnabled(); | |
boolean isDirectPathChannelCreated = | |
options.getChannelProvider() == null && defaultChannelProvider.canUseDirectPath() | |
&& defaultChannelProvider.isDirectPathXdsEnabled(); |
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
Outdated
Show resolved
Hide resolved
@@ -1630,11 +1655,31 @@ public OpenTelemetry getOpenTelemetry() { | |||
|
|||
@Override | |||
public ApiTracerFactory getApiTracerFactory() { | |||
List<ApiTracerFactory> apiTracerFactories = new ArrayList(); | |||
return createApiTracerFactory(false, false, false); |
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 get-method should preferably not call something that creates a new instance every time it is called. The original implementation of this did create a new list every time it was called, but it did not create any of the elements in the list. Can we make sure that this method still does not create a new instance of ApiTracerFactory each time it is called?
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.
Yes, even the metricstracerfactory getting added is only created once. We are using the static instance of BuiltInOpenTelemetryMetricsProvider
to call getOrCreateOpenTelemetry
. We have a check in this if openTelemetry
is already created, then we do not create it again.
It will create a new MetricsTracerFactory
object with the same openTelemetry
object similar to OpenTelemetryApiTracerFactory
private void addBuiltInMetricAttributes( | ||
CompositeTracer compositeTracer, DatabaseName databaseName) { | ||
// Built in metrics Attributes. | ||
compositeTracer.addAttributes( |
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.
Strictly speaking, we shouldn't add these attributes to the compositeTracer
, but only to the underlying built-in metrics tracer. Now the attributes will also be added to any other MetricsTracer
that is part of the composite tracer, but it only happens if you have built-in tracing enabled.
Meaning that:
- Enabling built-in metrics will obviously enable built-in metrics.
- But it will also have the side-effect that any other metrics-tracer that you had enabled will suddenly get two additional attributes.
Is there any way that we can avoid that side-effect?
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.
I didn't quite get you. We have a check in the CompositeTracer
to pass these attributes further only for MetricsTracer
. We only have one MetricsTracer
public void addAttributes(String key, String value) {
for (ApiTracer child : children) {
if (child instanceof MetricsTracer) {
MetricsTracer metricsTracer = (MetricsTracer) child;
metricsTracer.addAttributes(key, value);
}
}
};
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.
Cannot a user create and add a MetricsTracer
themselves?
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.
MetricsTracer class is decorated with @internalapi annotation . So we don't recommend customers to directly use this class. But even if they use this class to register metricstracerfactory, then yes they would get extra attributes.
...ud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java
Outdated
Show resolved
Hide resolved
...ud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBuiltInMetricsTest.java
Outdated
Show resolved
Hide resolved
Can we add a more descriptive pull request title than If it is something that is not yet GA, but still needs to be merged now, then we should rename the pull request title to |
3117484
to
75f2933
Compare
I have actually removed |
73fe037
to
08da2a7
Compare
da5d07d
to
0cc77ad
Compare
b9c649a
to
830e5e9
Compare
830e5e9
to
b2f9361
Compare
* feat: client metrics * Review comments * Few issues and code optimisations * review comments * directpath_used attribute * removed directpath enabled attribute * removed directpath enabled attribute * lint * bucket boundaries
This PR adds built-in metrics to the Java client library. This will introduce below metrics for the consumers of this library .
This feature is not currently available for customers to use. Once GA'ed consumers of this library will start getting these metrics in the MetricsExplorer