Skip to content
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

Merged
merged 9 commits into from
Sep 19, 2024
Merged

Conversation

surbhigarg92
Copy link
Contributor

@surbhigarg92 surbhigarg92 commented May 24, 2024

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



Attempt Latency The latency of an RPC attempt. Useful for monitoring the general health of the applicationWith attributes like “Token Expiry”, “Status” etc, this metric can help us troubleshoot a wide range of issues.
Attempt Count The count of RPC attempts Useful for monitoring trafficUseful for deriving “Error Rate” with status attributes
Operation Latency The total end-to-end latency across all request attempts, including retries. Useful for monitoring the general health of the applicationThe combination of this metric and Attempt Latency can help us troubleshoot connectivity issues.
Operation Count The count of operations Useful for monitoring trafficUseful for deriving “Error Rate” with status labelThe combination of this metric and Attempt Count can be used for deriving Retry Count

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: spanner Issues related to the googleapis/java-spanner API. labels May 24, 2024
@surbhigarg92 surbhigarg92 force-pushed the client_builtin_metrics branch 3 times, most recently from fcacc2e to d1b47e4 Compare June 10, 2024 12:16
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Jun 10, 2024
@surbhigarg92 surbhigarg92 force-pushed the client_builtin_metrics branch 6 times, most recently from 624b891 to fd4c4d6 Compare June 19, 2024 10:05
Copy link

conventional-commit-lint-gcf bot commented Jun 19, 2024

🤖 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 automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: xl Pull request size is extra large. labels Jun 19, 2024
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Jun 20, 2024
@surbhigarg92 surbhigarg92 force-pushed the client_builtin_metrics branch 2 times, most recently from f23435e to b766d20 Compare June 24, 2024 08:32
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: xl Pull request size is extra large. labels Jul 3, 2024
@surbhigarg92 surbhigarg92 force-pushed the client_builtin_metrics branch 4 times, most recently from ccc7862 to d8f5813 Compare July 19, 2024 09:56
@surbhigarg92 surbhigarg92 marked this pull request as ready for review July 22, 2024 04:16
@@ -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) {
Copy link
Collaborator

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:

  1. Make this package-private
  2. Add a public static method to SpannerOptionsTestHelper that takes a SpannerOptions.Builder instance as an argument, and that calls this setEnableBuiltInMetrics(...) method.
  3. Call the SpannerOptionsTestHelper method from the tests that need to set this value.

Comment on lines 375 to 377
boolean isDirectPathChannelCreated =
defaultChannelProvider.canUseDirectPath()
&& defaultChannelProvider.isDirectPathXdsEnabled();
Copy link
Collaborator

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:

Suggested change
boolean isDirectPathChannelCreated =
defaultChannelProvider.canUseDirectPath()
&& defaultChannelProvider.isDirectPathXdsEnabled();
boolean isDirectPathChannelCreated =
options.getChannelProvider() == null && defaultChannelProvider.canUseDirectPath()
&& defaultChannelProvider.isDirectPathXdsEnabled();

@@ -1630,11 +1655,31 @@ public OpenTelemetry getOpenTelemetry() {

@Override
public ApiTracerFactory getApiTracerFactory() {
List<ApiTracerFactory> apiTracerFactories = new ArrayList();
return createApiTracerFactory(false, false, false);
Copy link
Collaborator

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?

Copy link
Contributor Author

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(
Copy link
Collaborator

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:

  1. Enabling built-in metrics will obviously enable built-in metrics.
  2. 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?

Copy link
Contributor Author

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);
      }
    }
  };

Copy link
Collaborator

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?

Copy link
Contributor Author

@surbhigarg92 surbhigarg92 Aug 16, 2024

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.

@olavloite
Copy link
Collaborator

Can we add a more descriptive pull request title than client metrics, and also add a description to the pull request? That will improve the release notes that are generated from this change.

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 chore:....

@surbhigarg92 surbhigarg92 changed the title feat: client metrics chore: client metrics Aug 16, 2024
@surbhigarg92
Copy link
Contributor Author

surbhigarg92 commented Aug 16, 2024

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 this setEnableBuiltInMetrics(...) method.
Call the SpannerOptionsTestHelper method from the tests that need to set this value.

I have actually removed public from setEnableBuiltInMetrics . It was only required for ITBuiltinMetricsTest which we are not enabling right now anyway. Lets not give an option to customers to enable it till the time we actually GA our feature.

@surbhigarg92 surbhigarg92 added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Aug 16, 2024
@surbhigarg92 surbhigarg92 force-pushed the client_builtin_metrics branch 3 times, most recently from 73fe037 to 08da2a7 Compare August 26, 2024 05:12
@surbhigarg92 surbhigarg92 force-pushed the client_builtin_metrics branch 3 times, most recently from da5d07d to 0cc77ad Compare September 5, 2024 08:40
@surbhigarg92 surbhigarg92 added kokoro:run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. and removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. labels Sep 19, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 19, 2024
@rahul2393 rahul2393 merged commit facbb3f into googleapis:main Sep 19, 2024
31 of 32 checks passed
lqiu96 pushed a commit that referenced this pull request Sep 19, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. kokoro:run Add this label to force Kokoro to re-run the tests. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants