mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-09 22:07:59 -05:00
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>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user