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

fix: fix first response latencies #2382

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ public void onRequest(int requestCount) {

@Override
public void responseReceived() {
if (firstResponsePerOpTimer.isRunning()) {
firstResponsePerOpTimer.stop();
}
// When auto flow control is enabled, server latency is measured between afterResponse and
// responseReceived.
// When auto flow control is disabled, server latency is measured between onRequest and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_NAME_KEY;
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLUSTER_ID_KEY;
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CONNECTIVITY_ERROR_COUNT_NAME;
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.FIRST_RESPONSE_LATENCIES_NAME;
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.METHOD_KEY;
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.OPERATION_LATENCIES_NAME;
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.RETRY_COUNT_NAME;
Expand Down Expand Up @@ -122,6 +123,7 @@ public class BuiltinMetricsTracerTest {
private static final String TABLE = "fake-table";

private static final String BAD_TABLE_ID = "non-exist-table";
private static final String FIRST_RESPONSE_TABLE_ID = "first-response";
private static final String ZONE = "us-west-1";
private static final String CLUSTER = "cluster-0";
private static final long FAKE_SERVER_TIMING = 50;
Expand Down Expand Up @@ -327,6 +329,51 @@ public void testReadRowsOperationLatenciesOnAuthorizedView() {
assertThat(value).isIn(Range.closed(SERVER_LATENCY, elapsed));
}

@Test
public void testFirstResponseLatencies() {
Stopwatch firstResponseTimer = Stopwatch.createStarted();
stub.readRowsCallable()
.call(
Query.create(FIRST_RESPONSE_TABLE_ID),
new ResponseObserver<Row>() {
@Override
public void onStart(StreamController controller) {}

@Override
public void onResponse(Row response) {
if (firstResponseTimer.isRunning()) {
firstResponseTimer.stop();
}
try {
igorbernstein2 marked this conversation as resolved.
Show resolved Hide resolved
Thread.sleep(100);
} catch (InterruptedException e) {
}
}

@Override
public void onError(Throwable t) {}

@Override
public void onComplete() {}
});

Attributes expectedAttributes =
baseAttributes
.toBuilder()
.put(STATUS_KEY, "OK")
.put(TABLE_ID_KEY, FIRST_RESPONSE_TABLE_ID)
.put(ZONE_ID_KEY, ZONE)
.put(CLUSTER_ID_KEY, CLUSTER)
.put(METHOD_KEY, "Bigtable.ReadRows")
.put(CLIENT_NAME_KEY, CLIENT_NAME)
.build();

MetricData metricData = getMetricData(metricReader, FIRST_RESPONSE_LATENCIES_NAME);

long value = getAggregatedValue(metricData, expectedAttributes);
assertThat(value).isLessThan(firstResponseTimer.elapsed(TimeUnit.MILLISECONDS));
}

@Test
public void testGfeMetrics() {
Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE)));
Expand Down Expand Up @@ -755,6 +802,12 @@ static List<ReadRowsResponse> createFakeResponse() {
@Override
public void readRows(
ReadRowsRequest request, StreamObserver<ReadRowsResponse> responseObserver) {
if (request.getTableName().contains(FIRST_RESPONSE_TABLE_ID)) {
responseObserver.onNext(source.next());
responseObserver.onNext(source.next());
responseObserver.onCompleted();
return;
}
if (request.getTableName().contains(BAD_TABLE_ID)) {
responseObserver.onError(new StatusRuntimeException(Status.NOT_FOUND));
return;
Expand Down
Loading