Skip to content

Commit

Permalink
upgrade prometheus and fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Fukushima <[email protected]>
  • Loading branch information
gfukushima committed Dec 3, 2024
1 parent 5aa4bd8 commit 960092f
Show file tree
Hide file tree
Showing 35 changed files with 381 additions and 479 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class Eth1DataCache {
static final String CACHE_SIZE_METRIC_NAME = "eth1_block_cache_size";
static final String VOTES_MAX_METRIC_NAME = "eth1_current_period_votes_max";
static final String VOTES_TOTAL_METRIC_NAME = "eth1_current_period_votes_total";
static final String VOTES_TOTAL_METRIC_NAME = "eth1_current_period_votes";
static final String VOTES_UNKNOWN_METRIC_NAME = "eth1_current_period_votes_unknown";
static final String VOTES_CURRENT_METRIC_NAME = "eth1_current_period_votes_current";
static final String VOTES_BEST_METRIC_NAME = "eth1_current_period_votes_best";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public long getGossipBytesTotalReceived() {
}

private void storeObservationIfNeeded(final Observation observation) {
MetricCategory category = observation.getCategory();
MetricCategory category = observation.category();
if (category.equals(PROCESS)) {
readProcessCategoryItem(observation);
} else if (category.equals(VALIDATOR)) {
Expand All @@ -113,37 +113,37 @@ private void storeObservationIfNeeded(final Observation observation) {

private void readBeaconCategoryItem(final Observation observation) {
isBeaconNodePresent = true;
switch (observation.getMetricName()) {
switch (observation.metricName()) {
case "head_slot":
headSlot = getLongValue(observation.getValue());
headSlot = getLongValue(observation.value());
break;
case "eth1_request_queue_size":
isEth1Connected = true;
break;
case "peer_count":
peerCount = getIntValue(observation.getValue());
peerCount = getIntValue(observation.value());
break;
case "node_syncing_active":
isEth2Synced = getIntValue(observation.getValue()) == 0;
isEth2Synced = getIntValue(observation.value()) == 0;
break;
}
}

private void readProcessCategoryItem(final Observation observation) {
if ("cpu_seconds_total".equals(observation.getMetricName())) {
cpuSecondsTotal = getLongValue(observation.getValue());
if ("cpu_seconds_total".equals(observation.metricName())) {
cpuSecondsTotal = getLongValue(observation.value());
}
}

private void readJvmCategoryItem(final Observation observation) {
if ("memory_pool_bytes_used".equals(observation.getMetricName())) {
addToMemoryPoolBytesUsed((Double) observation.getValue());
if ("memory_pool_bytes_used".equals(observation.metricName())) {
addToMemoryPoolBytesUsed((Double) observation.value());
}
}

private void readValidatorCategoryItem(final Observation observation) {
if ("local_validator_counts".equals(observation.getMetricName())) {
addToLocalValidators(observation.getLabels(), (Double) observation.getValue());
if ("local_validator_counts".equals(observation.metricName())) {
addToLocalValidators(observation.labels(), (Double) observation.value());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import java.util.stream.Stream;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.LabelledGauge;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;
import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric;
import tech.pegasys.teku.infrastructure.async.AsyncRunner;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.collections.LimitedMap;
Expand Down Expand Up @@ -88,8 +88,8 @@ public static <K, V> CachingTaskQueue<K, V> create(
}

public void startMetrics() {
final LabelledGauge taskQueueMetrics =
metricsSystem.createLabelledGauge(
final LabelledSuppliedMetric taskQueueMetrics =
metricsSystem.createLabelledSuppliedGauge(
TekuMetricCategory.STORAGE,
metricsPrefix + "_tasks",
"Labelled task queue metrics",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,33 +272,29 @@ private void assertCacheSizeMetric(final int expectedSize) {

private void assertCacheHitCount(final int expectedCount) {
final double value =
metricsSystem
.getCounter(TekuMetricCategory.STORAGE, METRICS_PREFIX + "_tasks_total")
.getValue("cached");
metricsSystem.getCounterValue(
TekuMetricCategory.STORAGE, METRICS_PREFIX + "_tasks_total", "cached");
assertThat(value).isEqualTo(expectedCount);
}

private void assertNewTaskCount(final int expectedCount) {
final double value =
metricsSystem
.getCounter(TekuMetricCategory.STORAGE, METRICS_PREFIX + "_tasks_total")
.getValue("new");
metricsSystem.getCounterValue(
TekuMetricCategory.STORAGE, METRICS_PREFIX + "_tasks_total", "new");
assertThat(value).isEqualTo(expectedCount);
}

private void assertDuplicateTaskCount(final int expectedCount) {
final double value =
metricsSystem
.getCounter(TekuMetricCategory.STORAGE, METRICS_PREFIX + "_tasks_total")
.getValue("duplicate");
metricsSystem.getCounterValue(
TekuMetricCategory.STORAGE, METRICS_PREFIX + "_tasks_total", "duplicate");
assertThat(value).isEqualTo(expectedCount);
}

private void assertRebasedTaskCount(final int expectedCount) {
final double value =
metricsSystem
.getCounter(TekuMetricCategory.STORAGE, METRICS_PREFIX + "_tasks_total")
.getValue("rebase");
metricsSystem.getCounterValue(
TekuMetricCategory.STORAGE, METRICS_PREFIX + "_tasks_total", "rebase");
assertThat(value).isEqualTo(expectedCount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,11 @@ private void verifyEngineCalled(

private void verifySourceCounter(final Source source, final FallbackReason reason) {
final long actualCount =
stubMetricsSystem
.getCounter(TekuMetricCategory.BEACON, "execution_payload_source_total")
.getValue(source.toString(), reason.toString());
stubMetricsSystem.getCounterValue(
TekuMetricCategory.BEACON,
"execution_payload_source_total",
source.toString(),
reason.toString());
assertThat(actualCount).isOne();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,11 @@ private void verifyEngineCalled(

private void verifySourceCounter(final Source source, final FallbackReason reason) {
final long actualCount =
stubMetricsSystem
.getCounter(TekuMetricCategory.BEACON, "execution_payload_source_total")
.getValue(source.toString(), reason.toString());
stubMetricsSystem.getCounterValue(
TekuMetricCategory.BEACON,
"execution_payload_source_total",
source.toString(),
reason.toString());
assertThat(actualCount).isOne();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.hyperledger.besu.ethereum.chain.GenesisState;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
Expand All @@ -40,7 +40,7 @@ public static ExecutionPayloadHeader createPayloadForBesuGenesis(
final ProtocolSchedule protocolSchedule =
MainnetProtocolSchedule.fromConfig(
genesisConfigOptions,
MiningParameters.MINING_DISABLED,
MiningConfiguration.MINING_DISABLED,
badBlockManager,
false,
new NoOpMetricsSystem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.LabelledGauge;
import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric;
import tech.pegasys.teku.ethereum.events.SlotEventsChannel;
import tech.pegasys.teku.ethereum.execution.types.Eth1Address;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand Down Expand Up @@ -67,10 +67,10 @@ public ProposersDataManager(
final RecentChainData recentChainData,
final Optional<Eth1Address> proposerDefaultFeeRecipient,
final boolean forkChoiceUpdatedAlwaysSendPayloadAttribute) {
final LabelledGauge labelledGauge =
metricsSystem.createLabelledGauge(
final LabelledSuppliedMetric labelledGauge =
metricsSystem.createLabelledSuppliedGauge(
TekuMetricCategory.BEACON,
"proposers_data_total",
"proposers_data",
"Total number proposers/validators under management",
"type");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.Histogram;
import tech.pegasys.teku.bls.BLS;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.bls.BLSSignature;
Expand All @@ -53,7 +54,7 @@ public class AggregatingSignatureVerificationService extends SignatureVerificati
private final AsyncRunner asyncRunner;
private final Counter batchCounter;
private final Counter taskCounter;
private final MetricsHistogram batchSizeHistogram;
private final Histogram batchSizeHistogram;

@VisibleForTesting
AggregatingSignatureVerificationService(
Expand Down Expand Up @@ -89,13 +90,11 @@ public class AggregatingSignatureVerificationService extends SignatureVerificati
"signature_verifications_task_count_total",
"Reports the number of individual verification tasks processed");
batchSizeHistogram =
MetricsHistogram.create(
metricsSystem.createHistogram(
TekuMetricCategory.EXECUTOR,
metricsSystem,
"signature_verifications_batch_size",
"Histogram of signature verification batch sizes",
3,
List.of());
MetricsHistogram.getDefaultBuckets());
}

public AggregatingSignatureVerificationService(
Expand Down Expand Up @@ -188,7 +187,7 @@ private List<SignatureTask> waitForBatch() {
void batchVerifySignatures(final List<SignatureTask> tasks) {
batchCounter.inc();
taskCounter.inc(tasks.size());
batchSizeHistogram.recordValue(tasks.size());
batchSizeHistogram.observe(tasks.size());
final List<List<BLSPublicKey>> allKeys = new ArrayList<>();
final List<Bytes> allMessages = new ArrayList<>();
final List<BLSSignature> allSignatures = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ private void prepareRegistrations() {
private void assertPreparedProposersCount(final int expectedCount) {
final OptionalDouble optionalValue =
metricsSystem
.getLabelledGauge(TekuMetricCategory.BEACON, "proposers_data_total")
.getLabelledGauge(TekuMetricCategory.BEACON, "proposers_data")
.getValue("prepared_proposers");
assertThat(optionalValue).hasValue(expectedCount);
}

private void assertRegisteredValidatorsCount(final int expectedCount) {
final OptionalDouble optionalValue =
metricsSystem
.getLabelledGauge(TekuMetricCategory.BEACON, "proposers_data_total")
.getLabelledGauge(TekuMetricCategory.BEACON, "proposers_data")
.getValue("registered_validators");
assertThat(optionalValue).hasValue(expectedCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.hyperledger.besu.metrics.ObservableMetricsSystem;
import org.hyperledger.besu.metrics.Observation;
import org.hyperledger.besu.metrics.prometheus.PrometheusMetricsSystem;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.infrastructure.logging.LogCaptor;
Expand Down Expand Up @@ -78,6 +79,7 @@ public class BlockBlobSidecarsTrackersPoolImplTest {
private final StubAsyncRunner asyncRunner = new StubAsyncRunner();
private final RecentChainData recentChainData = mock(RecentChainData.class);
private final ExecutionLayerChannel executionLayer = mock(ExecutionLayerChannel.class);
BlockBlobSidecarsTrackersPoolImpl blockBlobSidecarsTrackersPool;

@SuppressWarnings("unchecked")
private final Function<BlobSidecar, SafeFuture<Void>> blobSidecarPublisher = mock(Function.class);
Expand All @@ -87,21 +89,6 @@ public class BlockBlobSidecarsTrackersPoolImplTest {

private final BlockImportChannel blockImportChannel = mock(BlockImportChannel.class);
private final int maxItems = 15;
private final BlockBlobSidecarsTrackersPoolImpl blockBlobSidecarsTrackersPool =
new PoolFactory(metricsSystem)
.createPoolForBlockBlobSidecarsTrackers(
blockImportChannel,
spec,
timeProvider,
asyncRunner,
recentChainData,
executionLayer,
() -> blobSidecarGossipValidator,
blobSidecarPublisher,
historicalTolerance,
futureTolerance,
maxItems,
this::trackerFactory);

private UInt64 currentSlot = historicalTolerance.times(2);
private final List<Bytes32> requiredBlockRootEvents = new ArrayList<>();
Expand All @@ -115,6 +102,21 @@ public class BlockBlobSidecarsTrackersPoolImplTest {

@BeforeEach
public void setup() {
blockBlobSidecarsTrackersPool =
new PoolFactory(metricsSystem)
.createPoolForBlockBlobSidecarsTrackers(
blockImportChannel,
spec,
timeProvider,
asyncRunner,
recentChainData,
executionLayer,
() -> blobSidecarGossipValidator,
blobSidecarPublisher,
historicalTolerance,
futureTolerance,
maxItems,
this::trackerFactory);
// Set up slot
blockBlobSidecarsTrackersPool.subscribeRequiredBlockRoot(requiredBlockRootEvents::add);
blockBlobSidecarsTrackersPool.subscribeRequiredBlockRootDropped(
Expand All @@ -127,6 +129,11 @@ public void setup() {
setSlot(currentSlot);
}

@AfterEach
public void tearDown() {
metricsSystem.shutdown();
}

private void setSlot(final long slot) {
setSlot(UInt64.valueOf(slot));
}
Expand Down Expand Up @@ -1369,7 +1376,7 @@ private static BlobIdentifier blobIdentifierFromBlobSidecar(final BlobSidecar bl

private void assertStats(final String type, final String subType, final double count) {
assertThat(
getMetricsValues("block_blobs_trackers_pool_stats_total").get(List.of(type, subType)))
getMetricsValues("block_blobs_trackers_pool_stats_total").get(List.of(subType, type)))
.isEqualTo(count);
}

Expand All @@ -1392,8 +1399,8 @@ private void assertBlobSidecarsTrackersCount(final int count) {
private Map<List<String>, Object> getMetricsValues(final String metricName) {
return metricsSystem
.streamObservations(TekuMetricCategory.BEACON)
.filter(ob -> ob.getMetricName().equals(metricName))
.collect(Collectors.toMap(Observation::getLabels, Observation::getValue));
.filter(ob -> ob.metricName().equals(metricName))
.collect(Collectors.toMap(Observation::labels, Observation::value));
}

private BlockBlobSidecarsTracker trackerFactory(final SlotAndBlockRoot slotAndBlockRoot) {
Expand Down
6 changes: 3 additions & 3 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ dependencyManagement {

dependency 'org.xerial.snappy:snappy-java:1.1.10.7'

dependency 'io.prometheus:simpleclient:0.16.0'
dependency 'io.prometheus:prometheus-metrics-bom:1.3.4'

dependencySet(group: 'org.hyperledger.besu.internal', version: '24.10.0') {
dependencySet(group: 'org.hyperledger.besu.internal', version: '24.12.0') {
entry('metrics-core')
entry('core')
entry('config')
}
dependencySet(group: 'org.hyperledger.besu', version: '24.10.0') {
dependencySet(group: 'org.hyperledger.besu', version: '24.12.0') {
entry('besu-datatypes')
entry('evm')
entry('plugin-api')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import java.util.concurrent.TimeUnit;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.LabelledGauge;
import org.hyperledger.besu.plugin.services.metrics.LabelledMetric;
import org.hyperledger.besu.plugin.services.metrics.LabelledSuppliedMetric;
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;

public class MetricTrackingExecutorFactory {

private final MetricsSystem metricsSystem;
private final LabelledGauge labelledGaugeQueueSize;
private final LabelledSuppliedMetric labelledGaugeQueueSize;
private final LabelledMetric<Counter> labelledGaugeRejectedExecutions;

private final OccurrenceCounter rejectedExecutionCounter;
Expand All @@ -41,7 +41,7 @@ public MetricTrackingExecutorFactory(
final MetricsSystem metricsSystem, final OccurrenceCounter rejectedExecutionCounter) {
this.metricsSystem = metricsSystem;
this.labelledGaugeQueueSize =
metricsSystem.createLabelledGauge(
metricsSystem.createLabelledSuppliedGauge(
TekuMetricCategory.EXECUTOR,
"queue_size",
"Current size of the executor task queue",
Expand Down
Loading

0 comments on commit 960092f

Please sign in to comment.