Skip to content

Commit

Permalink
chore: wire up metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain committed Oct 11, 2023
1 parent 583bc18 commit 8c1790b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
7 changes: 4 additions & 3 deletions packages/beacon-node/src/metrics/server/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export async function getHttpMetricsServer(
opts: HttpMetricsServerOpts,
{
register,
getOtherMetrics = async () => "",
getOtherMetrics = async () => [],
logger,
}: {register: Registry; getOtherMetrics?: () => Promise<string>; logger: Logger}
}: {register: Registry; getOtherMetrics?: () => Promise<string[]>; logger: Logger}
): Promise<HttpMetricsServer> {
// New registry to metric the metrics. Using the same registry would deadlock the .metrics promise
const httpServerRegister = new RegistryMetricCreator();
Expand All @@ -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 {
Expand Down
22 changes: 12 additions & 10 deletions packages/beacon-node/src/node/nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8c1790b

Please sign in to comment.