Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed May 10, 2022
1 parent efdb0a4 commit 24cd525
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public class BuiltinMetricsRecorder {
private final SpanName spanName;
private final Map<String, String> statsAttributes;

private MeasureMap attemptLevelNoStatus;
private MeasureMap attemptLevelWithStatus;
private MeasureMap operationLevelNoStatus;
private MeasureMap operationLevelWithStatus;
private MeasureMap attemptLevelNoStreaming;
private MeasureMap attemptLevelWithStreaming;
private MeasureMap operationLevelNoStreaming;
private MeasureMap operationLevelWithStreaming;

public BuiltinMetricsRecorder(
OperationType operationType,
Expand All @@ -57,22 +57,22 @@ public BuiltinMetricsRecorder(
this.parentContext = tagger.getCurrentTagContext();
this.statsAttributes = statsAttributes;

this.attemptLevelNoStatus = statsRecorder.newMeasureMap();
this.attemptLevelWithStatus = statsRecorder.newMeasureMap();
this.operationLevelNoStatus = statsRecorder.newMeasureMap();
this.operationLevelWithStatus = statsRecorder.newMeasureMap();
this.attemptLevelNoStreaming = statsRecorder.newMeasureMap();
this.attemptLevelWithStreaming = statsRecorder.newMeasureMap();
this.operationLevelNoStreaming = statsRecorder.newMeasureMap();
this.operationLevelWithStreaming = statsRecorder.newMeasureMap();
}

public void recordAttemptLevelWithoutStatus(
public void recordAttemptLevelWithoutStreaming(
String status, String tableId, String zone, String cluster) {
TagContextBuilder tagCtx =
newTagContextBuilder(tableId, zone, cluster)
.putLocal(BuiltinMeasureConstants.STATUS, TagValue.create(status));

attemptLevelNoStatus.record(tagCtx.build());
attemptLevelNoStreaming.record(tagCtx.build());
}

public void recordAttemptLevelWithStatus(
public void recordAttemptLevelWithStreaming(
String status, String tableId, String zone, String cluster) {
TagContextBuilder tagCtx =
newTagContextBuilder(tableId, zone, cluster)
Expand All @@ -85,19 +85,19 @@ public void recordAttemptLevelWithStatus(
tagCtx.putLocal(BuiltinMeasureConstants.STREAMING, TagValue.create("false"));
}

attemptLevelWithStatus.record(tagCtx.build());
attemptLevelWithStreaming.record(tagCtx.build());
}

public void recordOperationLevelWithoutStatus(
public void recordOperationLevelWithoutStreaming(
String status, String tableId, String zone, String cluster) {
TagContextBuilder tagCtx =
newTagContextBuilder(tableId, zone, cluster)
.putLocal(BuiltinMeasureConstants.STATUS, TagValue.create(status));

operationLevelNoStatus.record(tagCtx.build());
operationLevelNoStreaming.record(tagCtx.build());
}

public void recordOperationLevelWithStatus(
public void recordOperationLevelWithStreaming(
String status, String tableId, String zone, String cluster) {
TagContextBuilder tagCtx =
newTagContextBuilder(tableId, zone, cluster)
Expand All @@ -110,36 +110,38 @@ public void recordOperationLevelWithStatus(
tagCtx.putLocal(BuiltinMeasureConstants.STREAMING, TagValue.create("false"));
}

operationLevelWithStatus.record(tagCtx.build());
operationLevelWithStreaming.record(tagCtx.build());
}

public void recordOperationLatencies(long operationLatency) {
operationLevelWithStatus.put(BuiltinMeasureConstants.OPERATION_LATENCIES, operationLatency);
operationLevelWithStreaming.put(BuiltinMeasureConstants.OPERATION_LATENCIES, operationLatency);
}

public void recordAttemptLatency(long attemptLatency) {
attemptLevelWithStatus.put(BuiltinMeasureConstants.ATTEMPT_LATENCIES, attemptLatency);
attemptLevelWithStreaming.put(BuiltinMeasureConstants.ATTEMPT_LATENCIES, attemptLatency);
}

public void recordRetryCount(int attemptCount) {
operationLevelNoStatus.put(BuiltinMeasureConstants.RETRY_COUNT, attemptCount);
operationLevelNoStreaming.put(BuiltinMeasureConstants.RETRY_COUNT, attemptCount);
}

public void recordApplicationLatency(long applicationLatency) {
operationLevelWithStatus.put(BuiltinMeasureConstants.APPLICATION_LATENCIES, applicationLatency);
operationLevelWithStreaming.put(
BuiltinMeasureConstants.APPLICATION_LATENCIES, applicationLatency);
}

public void recordFirstResponseLatency(long firstResponseLatency) {
operationLevelNoStatus.put(
operationLevelNoStreaming.put(
BuiltinMeasureConstants.FIRST_RESPONSE_LATENCIES, firstResponseLatency);
}

public void recordGfeLatencies(long serverLatency) {
attemptLevelWithStatus.put(BuiltinMeasureConstants.SERVER_LATENCIES, serverLatency);
attemptLevelWithStreaming.put(BuiltinMeasureConstants.SERVER_LATENCIES, serverLatency);
}

public void recordGfeMissingHeaders(long connectivityErrors) {
attemptLevelNoStatus.put(BuiltinMeasureConstants.CONNECTIVITY_ERROR_COUNT, connectivityErrors);
attemptLevelNoStreaming.put(
BuiltinMeasureConstants.CONNECTIVITY_ERROR_COUNT, connectivityErrors);
}

public void recordBatchRequestThrottled(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ public void testStreamingOperation() throws InterruptedException {
tracer.recordFirstResponseLatency(firstResponseLatency);
tracer.recordBatchRequestThrottled(throttlingLatency, TABLE_ID, ZONE, CLUSTER);

tracer.recordAttemptLevelWithoutStatus(Status.UNAVAILABLE.toString(), TABLE_ID, ZONE, CLUSTER);
tracer.recordAttemptLevelWithStatus(Status.ABORTED.toString(), TABLE_ID, ZONE, CLUSTER);
tracer.recordOperationLevelWithoutStatus("OK", TABLE_ID, ZONE, CLUSTER);
tracer.recordOperationLevelWithStatus("OK", TABLE_ID, ZONE, CLUSTER);
tracer.recordAttemptLevelWithoutStreaming(
Status.UNAVAILABLE.toString(), TABLE_ID, ZONE, CLUSTER);
tracer.recordAttemptLevelWithStreaming(Status.ABORTED.toString(), TABLE_ID, ZONE, CLUSTER);
tracer.recordOperationLevelWithoutStreaming("OK", TABLE_ID, ZONE, CLUSTER);
tracer.recordOperationLevelWithStreaming("OK", TABLE_ID, ZONE, CLUSTER);

Thread.sleep(100);

Expand Down Expand Up @@ -266,10 +267,11 @@ public void testUnaryOperations() throws InterruptedException {
tracer.recordFirstResponseLatency(firstResponseLatency);
tracer.recordBatchRequestThrottled(throttlingLatency, TABLE_ID, ZONE, CLUSTER);

tracer.recordOperationLevelWithStatus("OK", TABLE_ID, ZONE, CLUSTER);
tracer.recordOperationLevelWithoutStatus("OK", TABLE_ID, ZONE, CLUSTER);
tracer.recordAttemptLevelWithoutStatus(Status.UNAVAILABLE.toString(), TABLE_ID, ZONE, CLUSTER);
tracer.recordAttemptLevelWithStatus(Status.ABORTED.toString(), TABLE_ID, ZONE, CLUSTER);
tracer.recordOperationLevelWithStreaming("OK", TABLE_ID, ZONE, CLUSTER);
tracer.recordOperationLevelWithoutStreaming("OK", TABLE_ID, ZONE, CLUSTER);
tracer.recordAttemptLevelWithoutStreaming(
Status.UNAVAILABLE.toString(), TABLE_ID, ZONE, CLUSTER);
tracer.recordAttemptLevelWithStreaming(Status.ABORTED.toString(), TABLE_ID, ZONE, CLUSTER);

Thread.sleep(100);

Expand Down

0 comments on commit 24cd525

Please sign in to comment.