-
Notifications
You must be signed in to change notification settings - Fork 891
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade to Promethus java client 1.x and adapt the code to the new ve…
…rsion Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
- Loading branch information
Showing
23 changed files
with
1,096 additions
and
639 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
metrics/core/src/main/java/org/hyperledger/besu/metrics/opentelemetry/DebugMetricReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...core/src/main/java/org/hyperledger/besu/metrics/prometheus/AbstractPrometheusSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright contributors to Besu. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.metrics.prometheus; | ||
|
||
import org.hyperledger.besu.metrics.Observation; | ||
import org.hyperledger.besu.plugin.services.metrics.MetricCategory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.stream.Stream; | ||
|
||
import io.prometheus.metrics.model.snapshots.SummarySnapshot; | ||
|
||
abstract class AbstractPrometheusSummary extends CategorizedPrometheusCollector { | ||
|
||
/** | ||
* Create a new collector assigned to the given category and with the given name, and computed the | ||
* prefixed name. | ||
* | ||
* @param category The {@link MetricCategory} this collector is assigned to | ||
* @param name The name of this collector | ||
*/ | ||
protected AbstractPrometheusSummary(final MetricCategory category, final String name) { | ||
super(category, name); | ||
} | ||
|
||
protected abstract SummarySnapshot collect(); | ||
|
||
@Override | ||
public Stream<Observation> streamObservations() { | ||
return collect().getDataPoints().stream() | ||
.flatMap( | ||
dataPoint -> { | ||
final var labelValues = PrometheusCollector.getLabelValues(dataPoint.getLabels()); | ||
final var quantiles = dataPoint.getQuantiles(); | ||
final var observations = new ArrayList<Observation>(quantiles.size() + 2); | ||
|
||
if (dataPoint.hasSum()) { | ||
observations.add( | ||
new Observation( | ||
category, | ||
name, | ||
dataPoint.getSum(), | ||
PrometheusCollector.addLabelValues(labelValues, "sum"))); | ||
} | ||
|
||
if (dataPoint.hasCount()) { | ||
observations.add( | ||
new Observation( | ||
category, | ||
name, | ||
dataPoint.getCount(), | ||
PrometheusCollector.addLabelValues(labelValues, "count"))); | ||
} | ||
|
||
quantiles.forEach( | ||
quantile -> | ||
observations.add( | ||
new Observation( | ||
category, | ||
name, | ||
quantile.getValue(), | ||
PrometheusCollector.addLabelValues( | ||
labelValues, | ||
"quantile", | ||
Double.toString(quantile.getQuantile()))))); | ||
|
||
return observations.stream(); | ||
}); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...src/main/java/org/hyperledger/besu/metrics/prometheus/CategorizedPrometheusCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright contributors to Besu. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.metrics.prometheus; | ||
|
||
import org.hyperledger.besu.plugin.services.metrics.MetricCategory; | ||
|
||
/** A Prometheus collector that is assigned to a category */ | ||
public abstract class CategorizedPrometheusCollector implements PrometheusCollector { | ||
/** The {@link MetricCategory} this collector is assigned to */ | ||
protected final MetricCategory category; | ||
|
||
/** The name of this collector */ | ||
protected final String name; | ||
|
||
/** The prefixed name of this collector */ | ||
protected final String prefixedName; | ||
|
||
/** | ||
* Create a new collector assigned to the given category and with the given name, and computed the | ||
* prefixed name. | ||
* | ||
* @param category The {@link MetricCategory} this collector is assigned to | ||
* @param name The name of this collector | ||
*/ | ||
protected CategorizedPrometheusCollector(final MetricCategory category, final String name) { | ||
this.category = category; | ||
this.name = name; | ||
this.prefixedName = prefixedName(category, name); | ||
} | ||
|
||
private static String categoryPrefix(final MetricCategory category) { | ||
return category.getApplicationPrefix().orElse("") + category.getName() + "_"; | ||
} | ||
|
||
private static String prefixedName(final MetricCategory category, final String name) { | ||
return categoryPrefix(category) + name; | ||
} | ||
} |
59 changes: 0 additions & 59 deletions
59
...ics/core/src/main/java/org/hyperledger/besu/metrics/prometheus/CurrentValueCollector.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.