Skip to content

Commit

Permalink
Added optional tags/dimensions for PartitionId/ReplicaId as addition/… (
Browse files Browse the repository at this point in the history
#35164)

* Added optional tags/dimensions for PartitionId/ReplicaId as addition/alternative to ServiceAddress for rntbd/request-level metrics

* Update CHANGELOG.md

* Update Metrics.md

* Update ClientTelemetryMetrics.java
  • Loading branch information
FabianMeiswinkel committed May 30, 2023
1 parent 1a310ce commit eb4b160
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,21 @@ public void beforeTest(CosmosMetricCategory... metricCategories) {
beforeTest(null, metricCategories);
}

public void beforeTest(CosmosDiagnosticsThresholds thresholds, CosmosMetricCategory... metricCategories) {
public void beforeTest(
CosmosDiagnosticsThresholds thresholds,
CosmosMetricCategory... metricCategories) {
assertThat(this.client).isNull();
assertThat(this.meterRegistry).isNull();

this.meterRegistry = ConsoleLoggingRegistryFactory.create(1);

this.inputMetricsOptions = new CosmosMicrometerMetricsOptions()
.meterRegistry(this.meterRegistry)
.setMetricCategories(metricCategories);
.setMetricCategories(metricCategories)
.configureDefaultTagNames(
CosmosMetricTagName.DEFAULT,
CosmosMetricTagName.PARTITION_ID,
CosmosMetricTagName.REPLICA_ID);

this.inputClientTelemetryConfig = new CosmosClientTelemetryConfig()
.metricsOptions(this.inputMetricsOptions);
Expand Down Expand Up @@ -234,13 +240,31 @@ public void createItem() throws Exception {
this.assertMetrics("cosmos.client.op.calls", true, expectedOperationTag);

if (!disableLatencyMeter) {
Tag expectedRequestTag = Tag.of(TagName.RequestStatusCode.toString(), "201/0");
this.validateMetrics(
expectedOperationTag,
Tag.of(TagName.RequestStatusCode.toString(), "201/0"),
expectedRequestTag,
1,
300
);

// also ensure the replicaId dimension is populated for DIRECT mode
if (this.client.asyncClient().getConnectionPolicy().getConnectionMode() == ConnectionMode.DIRECT) {
Meter foundMeter = this.assertMetrics(
"cosmos.client.req.rntbd.latency",
true,
expectedRequestTag);
assertThat(foundMeter).isNotNull();
boolean replicaIdDimensionExists = foundMeter
.getId()
.getTags()
.stream()
.anyMatch(tag -> tag.getKey().equals(TagName.ReplicaId.toString()) &&
!tag.getValue().equals("NONE"));
assertThat(replicaIdDimensionExists)
.isEqualTo(true);
}

this.validateMetrics(
Tag.of(
TagName.Operation.toString(), "Document/Create"),
Expand Down Expand Up @@ -1095,6 +1119,11 @@ public void meterTagNameFromStringConversion() {
.isSameAs(CosmosMetricTagName.SERVICE_ADDRESS);
assertThat(CosmosMetricTagName.fromString("serviceEndpoint"))
.isSameAs(CosmosMetricTagName.SERVICE_ENDPOINT);
assertThat(CosmosMetricTagName.fromString("partitionID"))
.isSameAs(CosmosMetricTagName.PARTITION_ID);
assertThat(CosmosMetricTagName.fromString("REPLICAid"))
.isSameAs(CosmosMetricTagName.REPLICA_ID);

}

@Test(groups = {"simple"}, timeOut = TIMEOUT)
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#### Features Added
* Added the capability to filter request-level metrics based on diagnostic thresholds. Request-level metrics usually are used to capture metrics per backend endpoint/replica - a high cardinality dimension. Filtering by diagnostic thresholds reduces the overhead - but also means request-level metrics can only be used for debugging purposes - not for monitoring purposes. So, it is important to use the unfiltered operation-level metrics for health monitoring in this case. - See [PR 35114](https://github.com/Azure/azure-sdk-for-java/pull/35114)

* Added optional tags/dimensions for PartitionId/ReplicaId as alternative to ServiceAddress for direct-mode (rntbd) request-level metrics. - See [PR 35164](https://github.com/Azure/azure-sdk-for-java/pull/35164)
#### Breaking Changes

#### Bugs Fixed
Expand Down
Loading

0 comments on commit eb4b160

Please sign in to comment.