More specific task metrics names (#389)

A prior refactoring had accidentally removed the specific task names
from the metrics labels.

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
pull/394/head
Danno Ferrin 5 years ago committed by GitHub
parent d25297443e
commit 87f4829e23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractEthTask.java
  2. 30
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractEthTaskTest.java

@ -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");
@ -64,7 +65,7 @@ public abstract class AbstractEthTask<T> implements EthTask<T> {
}
};
} else {
return ethTasksTimer.labels(AbstractEthTask.class.getSimpleName());
return ethTasksTimer.labels(taskName);
}
}

@ -19,6 +19,9 @@ import static org.mockito.Mockito.verify;
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;
@ -104,6 +107,33 @@ public class AbstractEthTaskTest {
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;

Loading…
Cancel
Save