service: CalMetricRecorder.recordCallMetric is deprecated, use CalMetricRecorder.recordRequestCostMetric (#9410)

This commit is contained in:
yifeizhuang 2022-07-25 13:10:29 -07:00 committed by GitHub
parent 1fe3ed9b53
commit 5f1a1d4f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 10 deletions

View File

@ -141,7 +141,7 @@ public class TestServiceImpl extends TestServiceGrpc.TestServiceImplBase {
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());
}
}

View File

@ -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;
@ -92,8 +93,25 @@ public final class CallMetricRecorder {
*
* @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;
}

View File

@ -41,9 +41,9 @@ public class CallMetricRecorderTest {
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);
@ -65,11 +65,11 @@ public class CallMetricRecorderTest {
@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);

View File

@ -90,7 +90,7 @@ public class OrcaMetricReportingServerInterceptorTest {
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);