Skip to content

Commit

Permalink
Migrate to Prometheus lib 1.x (hyperledger#7880)
Browse files Browse the repository at this point in the history
* Upgrade to Promethus java client 1.x and adapt the code to the new version

Signed-off-by: Fabio Di Fabio <[email protected]>

* Update CHANGELOG.md

Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: Fabio Di Fabio <[email protected]>

---------

Signed-off-by: Fabio Di Fabio <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
  • Loading branch information
fab-10 and macfarla authored Nov 27, 2024
1 parent e8a282f commit 5b2da5a
Show file tree
Hide file tree
Showing 36 changed files with 1,504 additions and 1,280 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@

### Breaking Changes
- Removed Retesteth rpc service and commands [#7833](https://github.com/hyperledger/besu/pull/7783)
- With the upgrade of the Prometheus Java Metrics library, there are the following changes:
- Gauge names are not allowed to end with `total`, therefore the metric `besu_blockchain_difficulty_total` is losing the `_total` suffix
- The `_created` timestamps are not returned by default, you can set the env var `BESU_OPTS="-Dio.prometheus.exporter.includeCreatedTimestamps=true"` to enable them
- Some JVM metrics have changed name to adhere to the OTEL standard (see the table below), [Besu Full Grafana dashboard](https://grafana.com/grafana/dashboards/16455-besu-full/) is updated to support both names

| Old Name | New Name |
|---------------------------------|---------------------------------|
| jvm_memory_bytes_committed | jvm_memory_committed_bytes |
| jvm_memory_bytes_init | jvm_memory_init_bytes |
| jvm_memory_bytes_max | jvm_memory_max_bytes |
| jvm_memory_bytes_used | jvm_memory_used_bytes |
| jvm_memory_pool_bytes_committed | jvm_memory_pool_committed_bytes |
| jvm_memory_pool_bytes_init | jvm_memory_pool_init_bytes |
| jvm_memory_pool_bytes_max | jvm_memory_pool_max_bytes |
| jvm_memory_pool_bytes_used | jvm_memory_pool_used_bytes |

### Upcoming Breaking Changes
- Plugin API will be deprecating the BesuContext interface to be replaced with the ServiceManager interface.
Expand All @@ -26,6 +41,7 @@
- Add a method to check if a metric category is enabled to the plugin API [#7832](https://github.com/hyperledger/besu/pull/7832)
- Add a new metric collector for counters which get their value from suppliers [#7894](https://github.com/hyperledger/besu/pull/7894)
- Add account and state overrides to `eth_call` [#7801](https://github.com/hyperledger/besu/pull/7801) and `eth_estimateGas` [#7890](https://github.com/hyperledger/besu/pull/7890)
- Prometheus Java Metrics library upgraded to version 1.3.3 [#7880](https://github.com/hyperledger/besu/pull/7880)

### Bug fixes
- Fix registering new metric categories from plugins [#7825](https://github.com/hyperledger/besu/pull/7825)
Expand Down
8 changes: 3 additions & 5 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1034,8 +1034,7 @@ public Runner build() {
subscriptionManager, privacyParameters, context.getBlockchain().getGenesisBlockHeader());
}

final Optional<MetricsService> metricsService =
createMetricsService(vertx, metricsConfiguration);
final Optional<MetricsService> metricsService = createMetricsService(metricsConfiguration);

final Optional<EthStatsService> ethStatsService;
if (isEthStatsEnabled()) {
Expand Down Expand Up @@ -1469,9 +1468,8 @@ private WebSocketService createWebsocketService(
vertx, configuration, websocketMessageHandler, authenticationService, metricsSystem);
}

private Optional<MetricsService> createMetricsService(
final Vertx vertx, final MetricsConfiguration configuration) {
return MetricsService.create(vertx, configuration, metricsSystem);
private Optional<MetricsService> createMetricsService(final MetricsConfiguration configuration) {
return MetricsService.create(configuration, metricsSystem);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import java.util.function.Function;
import java.util.function.Supplier;

import io.vertx.core.Vertx;
import jakarta.validation.constraints.NotBlank;
import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
Expand Down Expand Up @@ -458,8 +457,7 @@ private static Optional<MetricsService> initMetrics(final BlocksSubCommand paren
parentCommand.parentCommand.metricsConfiguration();

Optional<MetricsService> metricsService =
MetricsService.create(
Vertx.vertx(), metricsConfiguration, parentCommand.parentCommand.getMetricsSystem());
MetricsService.create(metricsConfiguration, parentCommand.parentCommand.getMetricsSystem());
metricsService.ifPresent(MetricsService::start);
return metricsService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
private void addObservation(
final Map<String, Object> observations, final Observation observation) {
final Map<String, Object> categoryObservations =
getNextMapLevel(observations, observation.getCategory().getName());
if (observation.getLabels().isEmpty()) {
categoryObservations.put(observation.getMetricName(), observation.getValue());
getNextMapLevel(observations, observation.category().getName());
if (observation.labels().isEmpty()) {
categoryObservations.put(observation.metricName(), observation.value());
} else {
addLabelledObservation(categoryObservations, observation);
}
}

private void addLabelledObservation(
final Map<String, Object> categoryObservations, final Observation observation) {
final List<String> labels = observation.getLabels();
Map<String, Object> values = getNextMapLevel(categoryObservations, observation.getMetricName());
final List<String> labels = observation.labels();
Map<String, Object> values = getNextMapLevel(categoryObservations, observation.metricName());
for (int i = 0; i < labels.size() - 1; i++) {
values = getNextMapLevel(values, labels.get(i));
}
values.put(labels.get(labels.size() - 1), observation.getValue());
values.put(labels.get(labels.size() - 1), observation.value());
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void createGauges(final MetricsSystem metricsSystem) {

metricsSystem.createGauge(
BLOCKCHAIN,
"difficulty_total",
"difficulty",
"Total difficulty of the chainhead",
() -> this.getChainHead().getTotalDifficulty().toBigInteger().doubleValue());

Expand Down
Loading

0 comments on commit 5b2da5a

Please sign in to comment.