Skip to content

Commit 65bf923

Browse files
committed
fix: metrics labels after rebasing from unstable
1 parent 1ebade9 commit 65bf923

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {Metrics} from "../../metrics/index.js";
88
import {IClock} from "../../util/clock.js";
99
import {ShufflingCache} from "../shufflingCache.js";
1010
import {MapTracker} from "./mapMetrics.js";
11-
import {CheckpointHex, CheckpointStateCache} from "./types.js";
11+
import {CheckpointHex, CheckpointStateCache, CacheItemType} from "./types.js";
1212
import {CPStateDatastore, DatastoreKey, datastoreKeyToCheckpoint} from "./datastore/index.js";
1313

1414
type GetHeadStateFn = () => CachedBeaconStateAllForks;
@@ -30,11 +30,6 @@ type PersistentCheckpointStateCacheOpts = {
3030
/** checkpoint serialized as a string */
3131
type CacheKey = string;
3232

33-
enum CacheItemType {
34-
persisted = "persisted",
35-
inMemory = "in-memory",
36-
}
37-
3833
type InMemoryCacheItem = {
3934
type: CacheItemType.inMemory;
4035
state: CachedBeaconStateAllForks;

packages/beacon-node/src/chain/stateCache/stateContextCheckpointsCache.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {MapDef} from "@lodestar/utils";
55
import {routes} from "@lodestar/api";
66
import {Metrics} from "../../metrics/index.js";
77
import {MapTracker} from "./mapMetrics.js";
8-
import {CheckpointStateCache as CheckpointStateCacheInterface} from "./types.js";
8+
import {CheckpointStateCache as CheckpointStateCacheInterface, CacheItemType} from "./types.js";
99

1010
export type CheckpointHex = {epoch: Epoch; rootHex: RootHex};
1111
const MAX_EPOCHS = 10;
@@ -29,8 +29,12 @@ export class CheckpointStateCache implements CheckpointStateCacheInterface {
2929
this.cache = new MapTracker(metrics?.cpStateCache);
3030
if (metrics) {
3131
this.metrics = metrics.cpStateCache;
32-
metrics.cpStateCache.size.addCollect(() => metrics.cpStateCache.size.set(this.cache.size));
33-
metrics.cpStateCache.epochSize.addCollect(() => metrics.cpStateCache.epochSize.set(this.epochIndex.size));
32+
metrics.cpStateCache.size.addCollect(() =>
33+
metrics.cpStateCache.size.set({type: CacheItemType.inMemory}, this.cache.size)
34+
);
35+
metrics.cpStateCache.epochSize.addCollect(() =>
36+
metrics.cpStateCache.epochSize.set({type: CacheItemType.inMemory}, this.epochIndex.size)
37+
);
3438
}
3539
}
3640

packages/beacon-node/src/chain/stateCache/types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ export interface CheckpointStateCache {
6666
clear(): void;
6767
dumpSummary(): routes.lodestar.StateCacheItem[];
6868
}
69+
70+
export enum CacheItemType {
71+
persisted = "persisted",
72+
inMemory = "in-memory",
73+
}

packages/beacon-node/src/metrics/metrics/lodestar.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {PeerSyncType, RangeSyncType} from "../../sync/utils/remoteSyncType.js";
1616
import {LodestarMetadata} from "../options.js";
1717
import {RegistryMetricCreator} from "../utils/registryMetricCreator.js";
1818
import {OpSource} from "../validatorMonitor.js";
19+
import {CacheItemType} from "../../chain/stateCache/types.js";
1920

2021
export type LodestarMetrics = ReturnType<typeof createLodestarMetrics>;
2122

@@ -1098,12 +1099,12 @@ export function createLodestarMetrics(
10981099
name: "lodestar_cp_state_cache_adds_total",
10991100
help: "Total number of items added in checkpoint state cache",
11001101
}),
1101-
size: register.gauge<"type">({
1102+
size: register.gauge<{type: CacheItemType}>({
11021103
name: "lodestar_cp_state_cache_size",
11031104
help: "Checkpoint state cache size",
11041105
labelNames: ["type"],
11051106
}),
1106-
epochSize: register.gauge<"type">({
1107+
epochSize: register.gauge<{type: CacheItemType}>({
11071108
name: "lodestar_cp_state_epoch_size",
11081109
help: "Checkpoint state cache size",
11091110
labelNames: ["type"],

0 commit comments

Comments
 (0)