Skip to content

Commit

Permalink
service: CalMetricRecorder.recordCallMetric is deprecated, use CalMet…
Browse files Browse the repository at this point in the history
…ricRecorder.recordRequestCostMetric (#9410)
  • Loading branch information
YifeiZhuang committed Jul 28, 2022
1 parent 0c287af commit c7f0965
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Expand Up @@ -141,7 +141,7 @@ private static void echoCallMetricsFromPayload(TestOrcaReport report) {
recorder.recordUtilizationMetric(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Double> entry : report.getRequestCostMap().entrySet()) {
recorder.recordCallMetric(entry.getKey(), entry.getValue());
recorder.recordRequestCostMetric(entry.getKey(), entry.getValue());
}
}

Expand Down
18 changes: 18 additions & 0 deletions services/src/main/java/io/grpc/services/CallMetricRecorder.java
Expand Up @@ -17,6 +17,7 @@
package io.grpc.services;

import com.google.common.annotations.VisibleForTesting;
import com.google.errorprone.annotations.InlineMe;
import io.grpc.Context;
import io.grpc.ExperimentalApi;
import java.util.Collections;
Expand Down Expand Up @@ -92,8 +93,25 @@ public CallMetricRecorder recordUtilizationMetric(String name, double value) {
*
* @return this recorder object
* @since 1.47.0
* @deprecated use {@link #recordRequestCostMetric} instead.
* This method will be removed in the future.
*/
@Deprecated
@InlineMe(replacement = "this.recordRequestCostMetric(name, value)")
public CallMetricRecorder recordCallMetric(String name, double value) {
return recordRequestCostMetric(name, value);
}

/**
* Records a call metric measurement for request cost.
* If RPC has already finished, this method is no-op.
*
* <p>A latter record will overwrite its former name-sakes.
*
* @return this recorder object
* @since 1.48.1
*/
public CallMetricRecorder recordRequestCostMetric(String name, double value) {
if (disabled) {
return this;
}
Expand Down
Expand Up @@ -41,9 +41,9 @@ public void dumpDumpsAllSavedMetricValues() {
recorder.recordUtilizationMetric("util1", 154353.423);
recorder.recordUtilizationMetric("util2", 0.1367);
recorder.recordUtilizationMetric("util3", 1437.34);
recorder.recordCallMetric("cost1", 37465.12);
recorder.recordCallMetric("cost2", 10293.0);
recorder.recordCallMetric("cost3", 1.0);
recorder.recordRequestCostMetric("cost1", 37465.12);
recorder.recordRequestCostMetric("cost2", 10293.0);
recorder.recordRequestCostMetric("cost3", 1.0);
recorder.recordCpuUtilizationMetric(0.1928);
recorder.recordMemoryUtilizationMetric(47.4);

Expand All @@ -65,11 +65,11 @@ public void noMetricsRecordedAfterSnapshot() {

@Test
public void lastValueWinForMetricsWithSameName() {
recorder.recordCallMetric("cost1", 3412.5435);
recorder.recordCallMetric("cost2", 6441.341);
recorder.recordCallMetric("cost1", 6441.341);
recorder.recordCallMetric("cost1", 4654.67);
recorder.recordCallMetric("cost2", 75.83);
recorder.recordRequestCostMetric("cost1", 3412.5435);
recorder.recordRequestCostMetric("cost2", 6441.341);
recorder.recordRequestCostMetric("cost1", 6441.341);
recorder.recordRequestCostMetric("cost1", 4654.67);
recorder.recordRequestCostMetric("cost2", 75.83);
recorder.recordMemoryUtilizationMetric(1.3);
recorder.recordMemoryUtilizationMetric(3.1);
recorder.recordUtilizationMetric("util1", 28374.21);
Expand Down
Expand Up @@ -90,7 +90,7 @@ public void unaryRpc(
entry.getValue());
}
for (Map.Entry<String, Double> entry : applicationCostMetrics.entrySet()) {
CallMetricRecorder.getCurrent().recordCallMetric(entry.getKey(),
CallMetricRecorder.getCurrent().recordRequestCostMetric(entry.getKey(),
entry.getValue());
}
CallMetricRecorder.getCurrent().recordCpuUtilizationMetric(cpuUtilizationMetrics);
Expand Down

0 comments on commit c7f0965

Please sign in to comment.