diff --git a/index.d.ts b/index.d.ts index 1fd1eac9..59aae08a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -136,10 +136,12 @@ export class AggregatorRegistry< > extends Registry { /** * Gets aggregated metrics for all workers. + * @param {ClusterMetricsOptions|undefined} options Additional options for cluster metrics aggregation + * @param {number} [options.timeoutMs=5000] Timeout to wait for all workers to respond before error. * @return {Promise} Promise that resolves with the aggregated * metrics. */ - clusterMetrics(): Promise; + clusterMetrics(options?: ClusterMetricsOptions): Promise; /** * Creates a new Registry instance from an array of metrics that were @@ -192,6 +194,11 @@ export enum MetricType { Summary, } +export type ClusterMetricsOptions = { + /** Timeout to wait for all workers to respond before error. */ + timeoutMs?: number; +}; + type CollectFunction = (this: T) => void | Promise; interface MetricObject { diff --git a/lib/cluster.js b/lib/cluster.js index 5cb707ed..119890f9 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -36,10 +36,12 @@ class AggregatorRegistry extends Registry { /** * Gets aggregated metrics for all workers. The optional callback and * returned Promise resolve with the same value; either may be used. + * @param {ClusterMetricsOptions|undefined} options Additional options for cluster metrics aggregation. + * @param {number} [options.timeoutMs=5000] Timeout to wait for all workers to respond before error. * @return {Promise} Promise that resolves with the aggregated * metrics. */ - clusterMetrics() { + clusterMetrics(options = { timeoutMs: 5000 }) { const requestId = requestCtr++; return new Promise((resolve, reject) => { @@ -58,7 +60,7 @@ class AggregatorRegistry extends Registry { errorTimeout: setTimeout(() => { const err = new Error('Operation timed out.'); request.done(err); - }, 5000), + }, options.timeoutMs || 5000), }; requests.set(requestId, request);