Skip to content

Commit a2b7d56

Browse files
CopilotAli Poursamadi
authored andcommitted
[fast-client] Add metric for batchGet requests routed to single-GET lookups
Add a new fast-client metric, batch_get_routed_to_single_get_request_count (OccurrenceRate on the MULTI_GET_STREAMING stats), recorded at the single-key short-circuit choke point (InternalAvroStoreClient#streamingBatchGetForSingleKey) so it counts every 1-key batchGet/streamingBatchGet served via a single-GET lookup, regardless of which layer (Retriable or Dispatching) triggered the short-circuit. Extend testSingleKeyStreamingBatchGetUsesSingleGet to assert the metric is recorded.
1 parent 8d2b240 commit a2b7d56

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

clients/venice-client/src/main/java/com/linkedin/venice/fastclient/InternalAvroStoreClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.linkedin.venice.client.store.streaming.VeniceResponseMap;
99
import com.linkedin.venice.client.store.streaming.VeniceResponseMapImpl;
1010
import com.linkedin.venice.compute.ComputeRequestWrapper;
11+
import com.linkedin.venice.read.RequestType;
1112
import com.linkedin.venice.utils.concurrent.VeniceConcurrentHashMap;
1213
import java.util.Map;
1314
import java.util.Optional;
@@ -52,6 +53,7 @@ public CompletableFuture<V> get(K key) throws VeniceClientException {
5253
* long-tail retry on 1-key batch gets.
5354
*/
5455
protected final void streamingBatchGetForSingleKey(K key, StreamingCallback<K, V> callback) {
56+
getClientConfig().getStats(RequestType.MULTI_GET_STREAMING).recordBatchGetRoutedToSingleGetRequest();
5557
get(key).whenComplete((value, throwable) -> {
5658
if (throwable != null) {
5759
callback.onCompletion(Optional.of(toException(throwable)));

clients/venice-client/src/main/java/com/linkedin/venice/fastclient/stats/FastClientStats.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class FastClientStats extends ClientStats {
5050
private final Sensor dualReadThinClientFastClientLatencyDeltaSensor;
5151

5252
private final Sensor leakedRequestCountSensor;
53+
/** Counts batch-get requests that contained a single key and were therefore served via a single-GET lookup. */
54+
private final Sensor batchGetRoutedToSingleGetRequestCountSensor;
5355
private volatile MetricEntityStateOneEnum<RejectionReason> rejectionRatio;
5456

5557
// OTel metrics
@@ -98,6 +100,8 @@ private FastClientStats(MetricsRepository metricsRepository, String storeName, R
98100
this.dualReadThinClientFastClientLatencyDeltaSensor =
99101
registerSensorWithDetailedPercentiles("dual_read_thinclient_fastclient_latency_delta", new Max(), new Avg());
100102
this.leakedRequestCountSensor = registerSensor("leaked_request_count", new OccurrenceRate());
103+
this.batchGetRoutedToSingleGetRequestCountSensor =
104+
registerSensor("batch_get_routed_to_single_get_request_count", new OccurrenceRate());
101105
}
102106

103107
/**
@@ -270,6 +274,14 @@ public void recordRejectionRatio(double rejectionRatio) {
270274
this.rejectionRatio.record(rejectionRatio, RejectionReason.THROTTLED_BY_LOAD_CONTROLLER);
271275
}
272276

277+
/**
278+
* Records a batch-get/streaming-batch-get request that contained a single key and was therefore short-circuited
279+
* to a single-GET lookup (see {@code InternalAvroStoreClient#streamingBatchGetForSingleKey}).
280+
*/
281+
public void recordBatchGetRoutedToSingleGetRequest() {
282+
batchGetRoutedToSingleGetRequestCountSensor.record();
283+
}
284+
273285
/**
274286
* This method is a utility method to build concise summaries useful in tests
275287
* and for logging. It generates a single string for all metrics for a sensor

clients/venice-client/src/test/java/com/linkedin/venice/fastclient/BatchGetAvroStoreClientUnitTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ public void testSingleKeyStreamingBatchGetUsesSingleGet()
8989
client.getSimulatorCompleteFuture());
9090

9191
validateMetrics(client, 1, 1, 0, 0);
92+
93+
// The single-key batch-get should be counted as routed to a single-GET lookup.
94+
Map<String, ? extends Metric> metrics = getStats(client.getClientConfig());
95+
assertTrue(
96+
metrics
97+
.get(
98+
"." + client.UNIT_TEST_STORE_NAME
99+
+ "--multiget_streaming_batch_get_routed_to_single_get_request_count.OccurrenceRate")
100+
.value() > 0);
92101
}
93102

94103
/**

0 commit comments

Comments
 (0)