Skip to content

Commit

Permalink
Add metrics to expose the pivot block and number of times a pivot blo…
Browse files Browse the repository at this point in the history
…ck has been selected. (PegaSysEng#1537)
  • Loading branch information
ajsutton authored and iikirilov committed Jun 8, 2019
1 parent e511d37 commit 74468fb
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration;
import tech.pegasys.pantheon.ethereum.eth.sync.state.SyncState;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.metrics.Counter;
import tech.pegasys.pantheon.metrics.MetricCategory;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.util.ExceptionUtils;

import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -44,6 +47,8 @@ public class FastSyncActions<C> {
private final EthContext ethContext;
private final SyncState syncState;
private final MetricsSystem metricsSystem;
private final Counter pivotBlockSelectionCounter;
private final AtomicLong pivotBlockGauge = new AtomicLong(0);

public FastSyncActions(
final SynchronizerConfiguration syncConfig,
Expand All @@ -58,6 +63,17 @@ public FastSyncActions(
this.ethContext = ethContext;
this.syncState = syncState;
this.metricsSystem = metricsSystem;

pivotBlockSelectionCounter =
metricsSystem.createCounter(
MetricCategory.SYNCHRONIZER,
"fast_sync_pivot_block_selected_count",
"Number of times a fast sync pivot block has been selected");
metricsSystem.createLongGauge(
MetricCategory.SYNCHRONIZER,
"fast_sync_pivot_block_current",
"The current fast sync pivot block",
pivotBlockGauge::get);
}

public CompletableFuture<FastSyncState> waitForSuitablePeers(final FastSyncState fastSyncState) {
Expand Down Expand Up @@ -108,6 +124,8 @@ private CompletableFuture<FastSyncState> selectPivotBlockFromPeers() {
throw new FastSyncException(CHAIN_TOO_SHORT);
} else {
LOG.info("Selecting block number {} as fast sync pivot block.", pivotBlockNumber);
pivotBlockSelectionCounter.inc();
pivotBlockGauge.set(pivotBlockNumber);
return completedFuture(new FastSyncState(pivotBlockNumber));
}
})
Expand Down

0 comments on commit 74468fb

Please sign in to comment.