diff options
-rw-r--r-- | lib/compilation-queue.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/compilation-queue.js b/lib/compilation-queue.js index 394d89748..f8e017632 100644 --- a/lib/compilation-queue.js +++ b/lib/compilation-queue.js @@ -25,6 +25,22 @@ import {executionAsyncId} from 'async_hooks'; import {default as Queue} from 'p-queue'; +import PromClient from 'prom-client'; + +// globals as essentially the compilation queue is a singleton, and if we make them members of the queue, tests fail as +// when we create a second queue, the previous counters are still registered. +const queueEnqueued = new PromClient.Counter({ + name: 'ce_compilation_queue_enqueued_total', + help: 'Total number of jobs enqueued', +}); +const queueDequeued = new PromClient.Counter({ + name: 'ce_compilation_queue_dequeued_total', + help: 'Total number of jobs dequeued', +}); +const queueCompleted = new PromClient.Counter({ + name: 'ce_compilation_queue_completed_total', + help: 'Total number of jobs completed', +}); export class CompilationQueue { constructor(concurrency, timeout) { @@ -45,7 +61,9 @@ export class CompilationQueue { // If we're asked to enqueue a job when we're already in a async queued job context, just run it. // This prevents a deadlock. if (this._running.has(enqueueAsyncId)) return job(); + queueEnqueued.inc(); return this._queue.add(() => { + queueDequeued.inc(); const jobAsyncId = executionAsyncId(); if (this._running.has(jobAsyncId)) throw new Error('somehow we entered the context twice'); try { @@ -53,6 +71,7 @@ export class CompilationQueue { return job(); } finally { this._running.delete(jobAsyncId); + queueCompleted.inc(); } }); } |