Skip to content

Commit

Permalink
Clean up ValidatorDutyMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Oct 25, 2023
1 parent b87290b commit cfddb9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,17 @@ public SafeFuture<DutyResult> performDuty() {
}

public SafeFuture<DutyResult> produceBlock(final ForkInfo forkInfo) {
final String dutyType = getType().getType();
return createRandaoReveal(forkInfo)
.thenCompose(
signature ->
validatorDutyMetrics.record(
() -> createUnsignedBlock(signature), dutyType, "create"))
validatorDutyMetrics.record(() -> createUnsignedBlock(signature), this, "create"))
.thenCompose(
unsignedBlock ->
validatorDutyMetrics.record(
() -> signBlockContainer(forkInfo, unsignedBlock), dutyType, "sign"))
() -> signBlockContainer(forkInfo, unsignedBlock), this, "sign"))
.thenCompose(
signedBlockContainer ->
validatorDutyMetrics.record(
() -> sendBlock(signedBlockContainer), dutyType, "send"))
validatorDutyMetrics.record(() -> sendBlock(signedBlockContainer), this, "send"))
.exceptionally(error -> DutyResult.forError(validator.getPublicKey(), error));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public SafeFuture<DutyResult> performDutyWithMetrics(final Duty duty) {
return duty.performDuty().alwaysRun(context::stopTimer);
}

public <T> SafeFuture<T> record(
final Supplier<SafeFuture<T>> dutyStepFutureSupplier, final Duty duty, final String step) {
final OperationTimer.TimingContext context = startTimer(getDutyType(duty), step);
return dutyStepFutureSupplier.get().alwaysRun(context::stopTimer);
}

private OperationTimer.TimingContext startTimer(final String dutyType, final String step) {
final OperationTimer timer = dutyMetric.labels(dutyType, step);
return timer.startTimer();
Expand All @@ -51,10 +57,4 @@ private OperationTimer.TimingContext startTimer(final String dutyType, final Str
private static String getDutyType(final Duty duty) {
return duty.getType().getType();
}

public <T> SafeFuture<T> record(
final Supplier<SafeFuture<T>> supplier, final String dutyType, final String step) {
final OperationTimer.TimingContext context = startTimer(dutyType, step);
return supplier.get().alwaysRun(context::stopTimer);
}
}

0 comments on commit cfddb9a

Please sign in to comment.