diff --git a/packages/beacon-node/src/metrics/server/http.ts b/packages/beacon-node/src/metrics/server/http.ts index b699471e07d5..e3f6e8440e82 100644 --- a/packages/beacon-node/src/metrics/server/http.ts +++ b/packages/beacon-node/src/metrics/server/http.ts @@ -19,9 +19,9 @@ export async function getHttpMetricsServer( opts: HttpMetricsServerOpts, { register, - getOtherMetrics = async () => "", + getOtherMetrics = async () => [], logger, - }: {register: Registry; getOtherMetrics?: () => Promise; logger: Logger} + }: {register: Registry; getOtherMetrics?: () => Promise; logger: Logger} ): Promise { // New registry to metric the metrics. Using the same registry would deadlock the .metrics promise const httpServerRegister = new RegistryMetricCreator(); @@ -48,7 +48,8 @@ export async function getHttpMetricsServer( } else { // Get scrape time metrics const httpServerMetrics = await httpServerRegister.metrics(); - const metricsStr = `${metricsRes[0].result}\n\n${metricsRes[1]}\n\n${httpServerMetrics}`; + const metrics = [metricsRes[0].result, httpServerMetrics, ...metricsRes[1]]; + const metricsStr = metrics.join("\n\n"); res.writeHead(200, {"content-type": register.contentType}).end(metricsStr); } } else { diff --git a/packages/beacon-node/src/node/nodejs.ts b/packages/beacon-node/src/node/nodejs.ts index 8f73632d0a96..62b380c64493 100644 --- a/packages/beacon-node/src/node/nodejs.ts +++ b/packages/beacon-node/src/node/nodejs.ts @@ -197,6 +197,16 @@ export class BeaconNode { ) : null; + const historicalStateRegen = await HistoricalStateRegen.init({ + opts: { + genesisTime: anchorState.genesisTime, + dbLocation: opts.db.name, + }, + config, + metrics, + logger: logger.child({module: LoggerModule.chain}), + }); + const chain = new BeaconChain(opts.chain, { config, db, @@ -219,15 +229,7 @@ export class BeaconNode { executionBuilder: opts.executionBuilder.enabled ? initializeExecutionBuilder(opts.executionBuilder, config, metrics) : undefined, - historicalStateRegen: await HistoricalStateRegen.init({ - opts: { - genesisTime: anchorState.genesisTime, - dbLocation: opts.db.name, - }, - config, - metrics, - logger: logger.child({module: LoggerModule.chain}), - }), + historicalStateRegen, }); // Load persisted data from disk to in-memory caches @@ -286,7 +288,7 @@ export class BeaconNode { const metricsServer = opts.metrics.enabled ? await getHttpMetricsServer(opts.metrics, { register: (metrics as Metrics).register, - getOtherMetrics: () => network.scrapeMetrics(), + getOtherMetrics: async () => Promise.all([network.scrapeMetrics(), historicalStateRegen.scrapeMetrics()]), logger: logger.child({module: LoggerModule.metrics}), }) : null;