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

Cosmos: Allowing sampling for diagnostics #34915

Merged

Conversation

FabianMeiswinkel
Copy link
Member

@FabianMeiswinkel FabianMeiswinkel commented May 12, 2023

Description

This PR allows applying sampling for diagnostic capturing in the Cosmos DB SDK. The motivation for adding this capability is to allow tuning the client-side resource consumption overhead that applications allow for diagnostics. Depending on the workload the PCU overhead when enabling diagnostics can be around 15-20 percent - in many workloads it will be significantly lower - but especially for very point-read heavy workloads it can be around 15%. The sampling rate can be modified after Cosmos Client initialization - so the sampling rate can be modified without any restarts being necessary.

CosmosClientTelemetryConfig clientTelemetryCfg = new CosmosClientTelemetryConfig()
    .diagnosticsHandler(CosmosDiagnosticsHandler.DEFAULT_LOGGING_HANDLER)
    .metricsOptions(new CosmosMicrometerMetricsOptions().meterRegistry(meterRegistry));

CosmosClientBuilder builder = this
    .getClientBuilder()
    .clientTelemetryConfig(clientTelemetryCfg);

CosmosContainer container = this.getContainer(builder);
executeTestCase(container);

meterRegistry.clear();
meterRegistry.close();

Set sampling rate to 25%

// change sample rate to 25%
clientTelemetryCfg.sampleDiagnostics(0.25);
executeTestCase(container);

Reduce sample rate to 0 - disable all diagnostics

// reduce sample rate to 0 - disable all diagnostics
clientTelemetryCfg.sampleDiagnostics(0);
executeTestCase(container);

set sample rate to 1 - enable all diagnostics (no sampling anymore)

// set sample rate to 1 - enable all diagnostics (no sampling anymore)
clientTelemetryCfg.sampleDiagnostics(1);
executeTestCase(container);

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-cosmos

FabianMeiswinkel and others added 6 commits May 12, 2023 16:35
…CosmosClientTelemetryConfig.java

Co-authored-by: Abhijeet Mohanty <mabhijeet1995@gmail.com>
…CosmosClientTelemetryConfig.java

Co-authored-by: Abhijeet Mohanty <mabhijeet1995@gmail.com>
…CosmosClientTelemetryConfig.java

Co-authored-by: Abhijeet Mohanty <mabhijeet1995@gmail.com>
…CosmosClientTelemetryConfig.java

Co-authored-by: Abhijeet Mohanty <mabhijeet1995@gmail.com>
Copy link
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one concern on the usage of ThreadLocalRandom

Copy link
Member

@xinlian12 xinlian12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@FabianMeiswinkel
Copy link
Member Author

/check-enforcer override

@FabianMeiswinkel
Copy link
Member Author

Failures are known issues in CI pipeline - overriding status checks

@FabianMeiswinkel
Copy link
Member Author

/check-enforcer override

@FabianMeiswinkel FabianMeiswinkel merged commit 980eeaf into Azure:main May 12, 2023
jairmyree pushed a commit to jairmyree/azure-sdk-for-java that referenced this pull request May 15, 2023
* Allowing sampling for diagnostics

* Updating changelog

* Removing left-over

* Update sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosClientTelemetryConfig.java

Co-authored-by: Abhijeet Mohanty <mabhijeet1995@gmail.com>

* Update sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosClientTelemetryConfig.java

Co-authored-by: Abhijeet Mohanty <mabhijeet1995@gmail.com>

* Update sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosClientTelemetryConfig.java

Co-authored-by: Abhijeet Mohanty <mabhijeet1995@gmail.com>

* Update sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosClientTelemetryConfig.java

Co-authored-by: Abhijeet Mohanty <mabhijeet1995@gmail.com>

* Fixing build analyze

* Code review feedback

---------

Co-authored-by: Abhijeet Mohanty <mabhijeet1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants