Skip to content

Commit 20d8385

Browse files
authored
feat: default counter value (#19954)
Ref: A-414
2 parents 3212811 + 065ad88 commit 20d8385

File tree

25 files changed

+419
-96
lines changed

25 files changed

+419
-96
lines changed

yarn-project/archiver/src/modules/instrumentation.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type TelemetryClient,
1111
type Tracer,
1212
type UpDownCounter,
13+
createUpDownCounterWithDefault,
1314
} from '@aztec/telemetry-client';
1415

1516
export class ArchiverInstrumentation {
@@ -48,29 +49,37 @@ export class ArchiverInstrumentation {
4849

4950
this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
5051

51-
this.txCount = meter.createUpDownCounter(Metrics.ARCHIVER_TOTAL_TXS);
52+
this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
5253

53-
this.proofsSubmittedCount = meter.createUpDownCounter(Metrics.ARCHIVER_ROLLUP_PROOF_COUNT);
54+
this.proofsSubmittedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
55+
[Attributes.PROOF_TIMED_OUT]: [true, false],
56+
});
5457

5558
this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
5659

5760
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
5861

59-
this.syncBlockCount = meter.createUpDownCounter(Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
62+
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
6063

6164
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
6265

6366
this.txsPerBlock = meter.createHistogram(Metrics.ARCHIVER_TXS_PER_BLOCK);
6467

6568
this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE);
6669

67-
this.syncMessageCount = meter.createUpDownCounter(Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
70+
this.syncMessageCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
6871

6972
this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION);
7073

71-
this.pruneCount = meter.createUpDownCounter(Metrics.ARCHIVER_PRUNE_COUNT);
74+
this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT);
7275

73-
this.blockProposalTxTargetCount = meter.createUpDownCounter(Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT);
76+
this.blockProposalTxTargetCount = createUpDownCounterWithDefault(
77+
meter,
78+
Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT,
79+
{
80+
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: [true, false],
81+
},
82+
);
7483

7584
this.dbMetrics = new LmdbMetrics(
7685
meter,
@@ -84,10 +93,6 @@ export class ArchiverInstrumentation {
8493
public static async new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback) {
8594
const instance = new ArchiverInstrumentation(telemetry, lmdbStats);
8695

87-
instance.syncBlockCount.add(0);
88-
instance.syncMessageCount.add(0);
89-
instance.pruneCount.add(0);
90-
9196
await instance.telemetry.flush();
9297

9398
return instance;

yarn-project/aztec-node/src/aztec-node/node_metrics.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Attributes, type Histogram, Metrics, type TelemetryClient, type UpDownCounter } from '@aztec/telemetry-client';
1+
import {
2+
Attributes,
3+
type Histogram,
4+
Metrics,
5+
type TelemetryClient,
6+
type UpDownCounter,
7+
createUpDownCounterWithDefault,
8+
} from '@aztec/telemetry-client';
29

310
export class NodeMetrics {
411
private receiveTxCount: UpDownCounter;
@@ -9,14 +16,14 @@ export class NodeMetrics {
916

1017
constructor(client: TelemetryClient, name = 'AztecNode') {
1118
const meter = client.getMeter(name);
12-
this.receiveTxCount = meter.createUpDownCounter(Metrics.NODE_RECEIVE_TX_COUNT);
19+
this.receiveTxCount = createUpDownCounterWithDefault(meter, Metrics.NODE_RECEIVE_TX_COUNT, {
20+
[Attributes.OK]: [true, false],
21+
});
1322
this.receiveTxDuration = meter.createHistogram(Metrics.NODE_RECEIVE_TX_DURATION);
1423

1524
this.snapshotDuration = meter.createHistogram(Metrics.NODE_SNAPSHOT_DURATION);
1625

17-
this.snapshotErrorCount = meter.createUpDownCounter(Metrics.NODE_SNAPSHOT_ERROR_COUNT);
18-
19-
this.snapshotErrorCount.add(0);
26+
this.snapshotErrorCount = createUpDownCounterWithDefault(meter, Metrics.NODE_SNAPSHOT_ERROR_COUNT);
2027
}
2128

2229
receivedTx(durationMs: number, isAccepted: boolean) {

yarn-project/bb-prover/src/verifier/queued_chonk_verifier.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type ObservableGauge,
1111
type TelemetryClient,
1212
type UpDownCounter,
13+
createUpDownCounterWithDefault,
1314
getTelemetryClient,
1415
} from '@aztec/telemetry-client';
1516

@@ -39,7 +40,7 @@ class IVCVerifierMetrics {
3940

4041
this.ivcTotalVerificationHistogram = meter.createHistogram(Metrics.IVC_VERIFIER_TOTAL_TIME);
4142

42-
this.ivcFailureCount = meter.createUpDownCounter(Metrics.IVC_VERIFIER_FAILURE_COUNT);
43+
this.ivcFailureCount = createUpDownCounterWithDefault(meter, Metrics.IVC_VERIFIER_FAILURE_COUNT);
4344

4445
this.aggDurationMetrics = {
4546
avg: meter.createObservableGauge(Metrics.IVC_VERIFIER_AGG_DURATION_AVG),

yarn-project/blob-client/src/archive/instrumentation.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Attributes, Metrics, type TelemetryClient, type UpDownCounter } from '@aztec/telemetry-client';
1+
import {
2+
Attributes,
3+
Metrics,
4+
type TelemetryClient,
5+
type UpDownCounter,
6+
createUpDownCounterWithDefault,
7+
} from '@aztec/telemetry-client';
28

39
export class BlobArchiveClientInstrumentation {
410
private blockRequestCounter: UpDownCounter;
@@ -11,11 +17,23 @@ export class BlobArchiveClientInstrumentation {
1117
name: string,
1218
) {
1319
const meter = client.getMeter(name);
14-
this.blockRequestCounter = meter.createUpDownCounter(Metrics.BLOB_SINK_ARCHIVE_BLOCK_REQUEST_COUNT);
20+
const requestAttrs = {
21+
[Attributes.HTTP_RESPONSE_STATUS_CODE]: [200, 404],
22+
[Attributes.HTTP_REQUEST_HOST]: [httpHost],
23+
};
24+
this.blockRequestCounter = createUpDownCounterWithDefault(
25+
meter,
26+
Metrics.BLOB_SINK_ARCHIVE_BLOCK_REQUEST_COUNT,
27+
requestAttrs,
28+
);
1529

16-
this.blobRequestCounter = meter.createUpDownCounter(Metrics.BLOB_SINK_ARCHIVE_BLOB_REQUEST_COUNT);
30+
this.blobRequestCounter = createUpDownCounterWithDefault(
31+
meter,
32+
Metrics.BLOB_SINK_ARCHIVE_BLOB_REQUEST_COUNT,
33+
requestAttrs,
34+
);
1735

18-
this.retrievedBlobs = meter.createUpDownCounter(Metrics.BLOB_SINK_ARCHIVE_BLOB_COUNT);
36+
this.retrievedBlobs = createUpDownCounterWithDefault(meter, Metrics.BLOB_SINK_ARCHIVE_BLOB_COUNT);
1937
}
2038

2139
incRequest(type: 'blocks' | 'blobs', status: number) {

yarn-project/node-lib/src/metrics/l1_tx_metrics.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import type { IL1TxMetrics, L1TxState } from '@aztec/ethereum/l1-tx-utils';
22
import { TxUtilsState } from '@aztec/ethereum/l1-tx-utils';
33
import { createLogger } from '@aztec/foundation/log';
4-
import { Attributes, type Histogram, type Meter, Metrics, type UpDownCounter } from '@aztec/telemetry-client';
4+
import {
5+
Attributes,
6+
type Histogram,
7+
type Meter,
8+
Metrics,
9+
type UpDownCounter,
10+
createUpDownCounterWithDefault,
11+
} from '@aztec/telemetry-client';
512

613
export type L1TxScope = 'sequencer' | 'prover' | 'other';
714

@@ -35,13 +42,14 @@ export class L1TxMetrics implements IL1TxMetrics {
3542

3643
this.txAttemptsUntilMined = this.meter.createHistogram(Metrics.L1_TX_ATTEMPTS_UNTIL_MINED);
3744

38-
this.txMinedCount = this.meter.createUpDownCounter(Metrics.L1_TX_MINED_COUNT);
45+
const scopeAttributes = [{ [Attributes.L1_TX_SCOPE]: this.scope }];
46+
this.txMinedCount = createUpDownCounterWithDefault(this.meter, Metrics.L1_TX_MINED_COUNT, scopeAttributes);
3947

40-
this.txRevertedCount = this.meter.createUpDownCounter(Metrics.L1_TX_REVERTED_COUNT);
48+
this.txRevertedCount = createUpDownCounterWithDefault(this.meter, Metrics.L1_TX_REVERTED_COUNT, scopeAttributes);
4149

42-
this.txCancelledCount = this.meter.createUpDownCounter(Metrics.L1_TX_CANCELLED_COUNT);
50+
this.txCancelledCount = createUpDownCounterWithDefault(this.meter, Metrics.L1_TX_CANCELLED_COUNT, scopeAttributes);
4351

44-
this.txNotMinedCount = this.meter.createUpDownCounter(Metrics.L1_TX_NOT_MINED_COUNT);
52+
this.txNotMinedCount = createUpDownCounterWithDefault(this.meter, Metrics.L1_TX_NOT_MINED_COUNT, scopeAttributes);
4553

4654
this.maxPriorityFeeHistogram = this.meter.createHistogram(Metrics.L1_TX_MAX_PRIORITY_FEE);
4755

yarn-project/p2p/src/mem_pools/instrumentation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type ObservableGauge,
1313
type TelemetryClient,
1414
type UpDownCounter,
15+
createUpDownCounterWithDefault,
1516
} from '@aztec/telemetry-client';
1617

1718
export enum PoolName {
@@ -97,7 +98,7 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
9798
dbStats,
9899
);
99100

100-
this.addObjectCounter = this.meter.createUpDownCounter(metricsLabels.itemsAdded);
101+
this.addObjectCounter = createUpDownCounterWithDefault(this.meter, metricsLabels.itemsAdded);
101102

102103
this.minedDelay = this.meter.createHistogram(metricsLabels.itemMinedDelay);
103104

yarn-project/p2p/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { EpochCacheInterface } from '@aztec/epoch-cache';
22
import { type CheckpointAttestation, PeerErrorSeverity, type ValidationResult } from '@aztec/stdlib/p2p';
3-
import { Attributes, Metrics, type TelemetryClient } from '@aztec/telemetry-client';
3+
import { Attributes, Metrics, type TelemetryClient, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
44

55
import type { AttestationPool } from '../../mem_pools/attestation_pool/attestation_pool.js';
66
import { CheckpointAttestationValidator } from './attestation_validator.js';
@@ -25,7 +25,13 @@ export class FishermanAttestationValidator extends CheckpointAttestationValidato
2525
this.logger = this.logger.createChild('[FISHERMAN]');
2626

2727
const meter = telemetryClient.getMeter('FishermanAttestationValidator');
28-
this.invalidAttestationCounter = meter.createUpDownCounter(Metrics.VALIDATOR_INVALID_ATTESTATION_RECEIVED_COUNT);
28+
this.invalidAttestationCounter = createUpDownCounterWithDefault(
29+
meter,
30+
Metrics.VALIDATOR_INVALID_ATTESTATION_RECEIVED_COUNT,
31+
{
32+
[Attributes.ERROR_TYPE]: ['base_validation_failed', 'payload_mismatch'],
33+
},
34+
);
2935
}
3036

3137
override async validate(message: CheckpointAttestation): Promise<ValidationResult> {

yarn-project/p2p/src/services/libp2p/instrumentation.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type ObservableGauge,
99
type TelemetryClient,
1010
type UpDownCounter,
11+
createUpDownCounterWithDefault,
1112
} from '@aztec/telemetry-client';
1213

1314
import { type RecordableHistogram, createHistogram } from 'node:perf_hooks';
@@ -29,11 +30,23 @@ export class P2PInstrumentation {
2930

3031
this.messageValidationDuration = meter.createHistogram(Metrics.P2P_GOSSIP_MESSAGE_VALIDATION_DURATION);
3132

32-
this.messagePrevalidationCount = meter.createUpDownCounter(Metrics.P2P_GOSSIP_MESSAGE_PREVALIDATION_COUNT);
33+
this.messagePrevalidationCount = createUpDownCounterWithDefault(
34+
meter,
35+
Metrics.P2P_GOSSIP_MESSAGE_PREVALIDATION_COUNT,
36+
{
37+
[Attributes.TOPIC_NAME]: [
38+
TopicType.tx,
39+
TopicType.block_proposal,
40+
TopicType.checkpoint_proposal,
41+
TopicType.checkpoint_attestation,
42+
],
43+
[Attributes.OK]: [true, false],
44+
},
45+
);
3346

3447
this.messageLatency = meter.createHistogram(Metrics.P2P_GOSSIP_MESSAGE_LATENCY);
3548

36-
this.txReceivedCount = meter.createUpDownCounter(Metrics.P2P_GOSSIP_TX_RECEIVED_COUNT);
49+
this.txReceivedCount = createUpDownCounterWithDefault(meter, Metrics.P2P_GOSSIP_TX_RECEIVED_COUNT);
3750

3851
this.aggLatencyMetrics = {
3952
avg: meter.createObservableGauge(Metrics.P2P_GOSSIP_AGG_MESSAGE_LATENCY_AVG),

yarn-project/p2p/src/services/peer-manager/metrics.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import {
66
type TelemetryClient,
77
type Tracer,
88
type UpDownCounter,
9+
createUpDownCounterWithDefault,
910
getTelemetryClient,
1011
} from '@aztec/telemetry-client';
1112

1213
import type { PeerId } from '@libp2p/interface';
1314

14-
import { type GoodByeReason, prettyGoodbyeReason } from '../reqresp/protocols/index.js';
15+
import { GoodByeReason, prettyGoodbyeReason } from '../reqresp/protocols/index.js';
1516

1617
export class PeerManagerMetrics {
1718
private sentGoodbyes: UpDownCounter;
@@ -31,10 +32,26 @@ export class PeerManagerMetrics {
3132
this.tracer = telemetryClient.getTracer(name);
3233

3334
const meter = telemetryClient.getMeter(name);
34-
this.sentGoodbyes = meter.createUpDownCounter(Metrics.PEER_MANAGER_GOODBYES_SENT);
35-
this.receivedGoodbyes = meter.createUpDownCounter(Metrics.PEER_MANAGER_GOODBYES_RECEIVED);
35+
const goodbyeReasonAttrs = {
36+
[Attributes.P2P_GOODBYE_REASON]: [
37+
prettyGoodbyeReason(GoodByeReason.SHUTDOWN),
38+
prettyGoodbyeReason(GoodByeReason.MAX_PEERS),
39+
prettyGoodbyeReason(GoodByeReason.LOW_SCORE),
40+
prettyGoodbyeReason(GoodByeReason.BANNED),
41+
prettyGoodbyeReason(GoodByeReason.WRONG_NETWORK),
42+
prettyGoodbyeReason(GoodByeReason.UNKNOWN),
43+
],
44+
};
45+
this.sentGoodbyes = createUpDownCounterWithDefault(meter, Metrics.PEER_MANAGER_GOODBYES_SENT, goodbyeReasonAttrs);
46+
this.receivedGoodbyes = createUpDownCounterWithDefault(
47+
meter,
48+
Metrics.PEER_MANAGER_GOODBYES_RECEIVED,
49+
goodbyeReasonAttrs,
50+
);
3651
this.peerCount = meter.createGauge(Metrics.PEER_MANAGER_PEER_COUNT);
37-
this.lowScoreDisconnects = meter.createUpDownCounter(Metrics.PEER_MANAGER_LOW_SCORE_DISCONNECTS);
52+
this.lowScoreDisconnects = createUpDownCounterWithDefault(meter, Metrics.PEER_MANAGER_LOW_SCORE_DISCONNECTS, {
53+
[Attributes.P2P_PEER_SCORE_STATE]: ['Banned', 'Disconnect'],
54+
});
3855
this.peerConnectionDuration = meter.createHistogram(Metrics.PEER_MANAGER_PEER_CONNECTION_DURATION);
3956
}
4057

yarn-project/p2p/src/services/peer-manager/peer_scoring.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Metrics,
77
type TelemetryClient,
88
type UpDownCounter,
9+
createUpDownCounterWithDefault,
910
getTelemetryClient,
1011
} from '@aztec/telemetry-client';
1112

@@ -52,7 +53,9 @@ export class PeerScoring {
5253

5354
const meter = telemetry.getMeter('PeerScoring');
5455

55-
this.peerStateCounter = meter.createUpDownCounter(Metrics.P2P_PEER_STATE_COUNT);
56+
this.peerStateCounter = createUpDownCounterWithDefault(meter, Metrics.P2P_PEER_STATE_COUNT, {
57+
[Attributes.P2P_PEER_SCORE_STATE]: ['Healthy', 'Disconnect', 'Banned'],
58+
});
5659
}
5760

5861
public penalizePeer(peerId: PeerId, penalty: PeerErrorSeverity) {

0 commit comments

Comments
 (0)