Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into besu-169/auto-log…
Browse files Browse the repository at this point in the history
…-indexing

Signed-off-by: Abdelhamid Bakhta <[email protected]>
  • Loading branch information
AbdelStark committed Feb 12, 2020
2 parents bc65af9 + 87f4829 commit 8a3c988
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ public abstract class AbstractEthTask<T> implements EthTask<T> {
private final Collection<CompletableFuture<?>> subTaskFutures = new ConcurrentLinkedDeque<>();

protected AbstractEthTask(final MetricsSystem metricsSystem) {
this(buildOperationTimer(metricsSystem));
this.taskTimer = buildOperationTimer(metricsSystem, getClass().getSimpleName());
}

protected AbstractEthTask(final OperationTimer taskTimer) {
this.taskTimer = taskTimer;
}

private static OperationTimer buildOperationTimer(final MetricsSystem metricsSystem) {
private static OperationTimer buildOperationTimer(
final MetricsSystem metricsSystem, final String taskName) {
final LabelledMetric<OperationTimer> ethTasksTimer =
metricsSystem.createLabelledTimer(
BesuMetricCategory.SYNCHRONIZER, "task", "Internal processing tasks", "taskName");
Expand All @@ -64,7 +65,7 @@ public double stopTimer() {
}
};
} else {
return ethTasksTimer.labels(AbstractEthTask.class.getSimpleName());
return ethTasksTimer.labels(taskName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import static org.mockito.Mockito.when;

import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;
import org.hyperledger.besu.plugin.services.metrics.MetricCategory;
import org.hyperledger.besu.plugin.services.metrics.OperationTimer;

import java.util.Arrays;
Expand Down Expand Up @@ -104,6 +107,33 @@ protected void executeTask() {}
verify(mockTimingContext).stopTimer();
}

@Test
public void shouldHaveSpecificMetricsLabels() {
// seed with a failing value so that a no-op also trips the failure.
final String[] lastLabelNames = {"AbstractEthTask"};
final MetricsSystem instrumentedLabeler =
new NoOpMetricsSystem() {
@Override
public LabelledMetric<OperationTimer> createLabelledTimer(
final MetricCategory category,
final String name,
final String help,
final String... labelNames) {
return names -> {
lastLabelNames[0] = names[0];
return null;
};
}
};
new AbstractEthTask<>(instrumentedLabeler) {
@Override
protected void executeTask() {
// no-op
}
};
assertThat(lastLabelNames[0]).isNotEqualTo("AbstractEthTask");
}

private class EthTaskWithMultipleSubtasks extends AbstractEthTask<Void> {

private final List<CompletableFuture<?>> subtasks;
Expand Down

0 comments on commit 8a3c988

Please sign in to comment.