Skip to content

Commit

Permalink
Ensure that loaded keys metric is accurate (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
jframe authored Jun 22, 2022
1 parent f6defef commit 1e4c5fb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- Added new metric `eth2_slashingprotection_database_duration` to track time spent performing database queries during either block or attestation signing operations
- Private keys bulk loading from AWS Secrets Manager via cli options in eth2 mode [#499](https://github.com/ConsenSys/web3signer/issues/499)

### Bugs Fixed
- Fix issue where signing_signers_loaded_count metric didn't update after refresh endpoint was used to update loaded keys
---

## 22.5.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ protected Router populateRouter(final Context context) {
.handler(
new BlockingHandlerDecorator(
new Eth1SignForIdentifierHandler(
secpSigner, new HttpApiMetrics(context.getMetricsSystem(), SECP256K1)),
secpSigner,
new HttpApiMetrics(context.getMetricsSystem(), SECP256K1, signerProvider)),
false))
.failureHandler(errorHandler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void registerEth2Routes(
new BlockingHandlerDecorator(
new Eth2SignForIdentifierHandler(
blsSigner,
new HttpApiMetrics(metricsSystem, BLS),
new HttpApiMetrics(metricsSystem, BLS, blsSignerProvider),
new SlashingProtectionMetrics(metricsSystem),
slashingProtectionContext.map(SlashingProtectionContext::getSlashingProtection),
objectMapper,
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/tech/pegasys/web3signer/core/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package tech.pegasys.web3signer.core;

import static tech.pegasys.web3signer.core.service.http.OpenApiOperationsId.UPCHECK;
import static tech.pegasys.web3signer.core.service.http.metrics.HttpApiMetrics.incSignerLoadCount;

import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.web3signer.core.config.ClientAuthConstraints;
Expand Down Expand Up @@ -107,7 +106,6 @@ public void run() {
} catch (final InterruptedException | ExecutionException e) {
LOG.error("Error loading signers", e);
}
incSignerLoadCount(metricsSystem, artifactSignerProvider.availableIdentifiers().size());

final OpenApiSpecsExtractor openApiSpecsExtractor =
new OpenApiSpecsExtractor.OpenApiSpecsExtractorBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@
package tech.pegasys.web3signer.core.service.http.metrics;

import tech.pegasys.web3signer.common.Web3SignerMetricCategory;
import tech.pegasys.web3signer.signing.ArtifactSignerProvider;
import tech.pegasys.web3signer.signing.KeyType;

import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import org.hyperledger.besu.plugin.services.metrics.OperationTimer;

public class HttpApiMetrics {
private static Counter signersLoadedCounter;

private final Counter malformedRequestCounter;
private final OperationTimer signingTimer;
private final Counter missingSignerCounter;

public HttpApiMetrics(final MetricsSystem metricsSystem, final KeyType keyType) {

public HttpApiMetrics(
final MetricsSystem metricsSystem,
final KeyType keyType,
final ArtifactSignerProvider artifactSignerProvider) {
malformedRequestCounter =
metricsSystem.createCounter(
Web3SignerMetricCategory.HTTP,
Expand All @@ -43,6 +44,11 @@ public HttpApiMetrics(final MetricsSystem metricsSystem, final KeyType keyType)
Web3SignerMetricCategory.SIGNING,
keyType.name().toLowerCase() + "_missing_identifier_count",
"Number of signing operations requested, for keys which are not available");
metricsSystem.createIntegerGauge(
Web3SignerMetricCategory.SIGNING,
"signers_loaded_count",
"Number of keys loaded (combining SECP256k1 and BLS12-381",
() -> artifactSignerProvider.availableIdentifiers().size());
}

public Counter getMalformedRequestCounter() {
Expand All @@ -56,15 +62,4 @@ public OperationTimer getSigningTimer() {
public Counter getMissingSignerCounter() {
return missingSignerCounter;
}

public static void incSignerLoadCount(final MetricsSystem metricsSystem, final long count) {
if (signersLoadedCounter == null) {
signersLoadedCounter =
metricsSystem.createCounter(
Web3SignerMetricCategory.SIGNING,
"signers_loaded_count",
"Number of keys loaded (combining SECP256k1 and BLS12-381");
}
signersLoadedCounter.inc(count);
}
}

0 comments on commit 1e4c5fb

Please sign in to comment.