Skip to content

Commit

Permalink
fix: metrics labels after rebasing from unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Jan 4, 2024
1 parent 1ebade9 commit 65bf923
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Metrics} from "../../metrics/index.js";
import {IClock} from "../../util/clock.js";
import {ShufflingCache} from "../shufflingCache.js";
import {MapTracker} from "./mapMetrics.js";
import {CheckpointHex, CheckpointStateCache} from "./types.js";
import {CheckpointHex, CheckpointStateCache, CacheItemType} from "./types.js";
import {CPStateDatastore, DatastoreKey, datastoreKeyToCheckpoint} from "./datastore/index.js";

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

enum CacheItemType {
persisted = "persisted",
inMemory = "in-memory",
}

type InMemoryCacheItem = {
type: CacheItemType.inMemory;
state: CachedBeaconStateAllForks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {MapDef} from "@lodestar/utils";
import {routes} from "@lodestar/api";
import {Metrics} from "../../metrics/index.js";
import {MapTracker} from "./mapMetrics.js";
import {CheckpointStateCache as CheckpointStateCacheInterface} from "./types.js";
import {CheckpointStateCache as CheckpointStateCacheInterface, CacheItemType} from "./types.js";

export type CheckpointHex = {epoch: Epoch; rootHex: RootHex};
const MAX_EPOCHS = 10;
Expand All @@ -29,8 +29,12 @@ export class CheckpointStateCache implements CheckpointStateCacheInterface {
this.cache = new MapTracker(metrics?.cpStateCache);
if (metrics) {
this.metrics = metrics.cpStateCache;
metrics.cpStateCache.size.addCollect(() => metrics.cpStateCache.size.set(this.cache.size));
metrics.cpStateCache.epochSize.addCollect(() => metrics.cpStateCache.epochSize.set(this.epochIndex.size));
metrics.cpStateCache.size.addCollect(() =>
metrics.cpStateCache.size.set({type: CacheItemType.inMemory}, this.cache.size)
);
metrics.cpStateCache.epochSize.addCollect(() =>
metrics.cpStateCache.epochSize.set({type: CacheItemType.inMemory}, this.epochIndex.size)
);
}
}

Expand Down
5 changes: 5 additions & 0 deletions packages/beacon-node/src/chain/stateCache/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ export interface CheckpointStateCache {
clear(): void;
dumpSummary(): routes.lodestar.StateCacheItem[];
}

export enum CacheItemType {
persisted = "persisted",
inMemory = "in-memory",
}
5 changes: 3 additions & 2 deletions packages/beacon-node/src/metrics/metrics/lodestar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {PeerSyncType, RangeSyncType} from "../../sync/utils/remoteSyncType.js";
import {LodestarMetadata} from "../options.js";
import {RegistryMetricCreator} from "../utils/registryMetricCreator.js";
import {OpSource} from "../validatorMonitor.js";
import {CacheItemType} from "../../chain/stateCache/types.js";

export type LodestarMetrics = ReturnType<typeof createLodestarMetrics>;

Expand Down Expand Up @@ -1098,12 +1099,12 @@ export function createLodestarMetrics(
name: "lodestar_cp_state_cache_adds_total",
help: "Total number of items added in checkpoint state cache",
}),
size: register.gauge<"type">({
size: register.gauge<{type: CacheItemType}>({
name: "lodestar_cp_state_cache_size",
help: "Checkpoint state cache size",
labelNames: ["type"],
}),
epochSize: register.gauge<"type">({
epochSize: register.gauge<{type: CacheItemType}>({
name: "lodestar_cp_state_epoch_size",
help: "Checkpoint state cache size",
labelNames: ["type"],
Expand Down

0 comments on commit 65bf923

Please sign in to comment.