Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Add labels to Pipelined tasks metrics (#1057)
Browse files Browse the repository at this point in the history
Add the taskName labels to the Pipelined Task metrics.
  • Loading branch information
shemnon authored Mar 8, 2019
1 parent 1966f48 commit a5fe6b8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,21 @@ protected AbstractPipelinedTask(
outboundQueue = new LinkedBlockingQueue<>(outboundBacklogSize);
results = new ArrayList<>();
this.inboundQueueCounter =
metricsSystem.createCounter(
MetricCategory.SYNCHRONIZER,
"inboundQueueCounter",
"count of queue items that started processing");
metricsSystem
.createLabelledCounter(
MetricCategory.SYNCHRONIZER,
"inboundQueueCounter",
"count of queue items that started processing",
"taskName")
.labels(getClass().getSimpleName());
this.outboundQueueCounter =
metricsSystem.createCounter(
MetricCategory.SYNCHRONIZER,
"outboundQueueCounter",
"count of queue items that finished processing");
metricsSystem
.createLabelledCounter(
MetricCategory.SYNCHRONIZER,
"outboundQueueCounter",
"count of queue items that finished processing",
"taskName")
.labels(getClass().getSimpleName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.PrometheusMetricsSystem;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.assertj.core.util.Lists;
import org.junit.Test;

public class IncrementerTest {
Expand Down Expand Up @@ -95,12 +96,43 @@ public void parallelDownloadPipelineCounterShouldIncrement() {

final List<Observation> metrics =
metricsSystem.getMetrics(MetricCategory.SYNCHRONIZER).collect(Collectors.toList());
final Observation inboundObservation =
new Observation(MetricCategory.SYNCHRONIZER, "inboundQueueCounter", 6.0, Lists.emptyList());
final Observation outboundObservation =

// the first iteration gets the genesis block, which results in no data
// being passed downstream. So observed value is 2.
final Observation headerInboundObservation =
new Observation(
MetricCategory.SYNCHRONIZER,
"inboundQueueCounter",
2.0,
Collections.singletonList("ParallelDownloadHeadersTask"));
final Observation headerOutboundObservation =
new Observation(
MetricCategory.SYNCHRONIZER, "outboundQueueCounter", 5.0, Lists.emptyList());
assertThat(metrics).contains(inboundObservation, outboundObservation);
MetricCategory.SYNCHRONIZER,
"outboundQueueCounter",
1.0,
Collections.singletonList("ParallelDownloadHeadersTask"));
assertThat(metrics).contains(headerInboundObservation, headerOutboundObservation);

for (final String label :
Arrays.asList(
"ParallelValidateHeadersTask",
"ParallelDownloadBodiesTask",
"ParallelExtractTxSignaturesTask",
"ParallelValidateAndImportBodiesTask")) {
final Observation inboundObservation =
new Observation(
MetricCategory.SYNCHRONIZER,
"inboundQueueCounter",
1.0,
Collections.singletonList(label));
final Observation outboundObservation =
new Observation(
MetricCategory.SYNCHRONIZER,
"outboundQueueCounter",
1.0,
Collections.singletonList(label));
assertThat(metrics).contains(inboundObservation, outboundObservation);
}
}

private FullSyncDownloader<?> downloader(final SynchronizerConfiguration syncConfig) {
Expand Down

0 comments on commit a5fe6b8

Please sign in to comment.