Skip to content

Commit

Permalink
feat: Remove executor metrics on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Feb 13, 2024
1 parent 439d760 commit e3c69f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions runner/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ export const METRICS = {
};

const aggregatorRegistry = new AggregatorRegistry();
const workerMetrics: Record<number, string> = {};
const workerMetrics: Map<number, string> = {};

export const registerWorkerMetrics = (workerId: number, metrics: string): void => {
workerMetrics[workerId] = metrics;
workerMetrics.set(workerId, metrics);
};

export const deregisterWorkerMetrics = (workerId: number): void => {
workerMetrics.delete(workerId);
};

export const startServer = async (): Promise<void> => {
Expand All @@ -81,7 +85,7 @@ export const startServer = async (): Promise<void> => {
app.get('/metrics', async (_req, res) => {
res.set('Content-Type', aggregatorRegistry.contentType);

const metrics = await AggregatorRegistry.aggregate(Object.values(workerMetrics)).metrics();
const metrics = await AggregatorRegistry.aggregate(Array.from(workerMetrics.values())).metrics();
res.send(metrics);
});

Expand Down
2 changes: 2 additions & 0 deletions runner/src/stream-handler/stream-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export default class StreamHandler {
}

async stop (): Promise<void> {
deregisterWorkerMetrics(this.worker.threadId);

await this.worker.terminate();
}

Expand Down

0 comments on commit e3c69f6

Please sign in to comment.