Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ export class AggregatorRegistry<
> extends Registry<T> {
/**
* Gets aggregated metrics for all workers.
* @param {ClusterMetricsOptions|undefined} options Additional options for cluster metrics aggregation
Comment thread
vitush93 marked this conversation as resolved.
* @param {number} [options.timeoutMs=5000] Timeout to wait for all workers to respond before error.
* @return {Promise<string>} Promise that resolves with the aggregated
* metrics.
*/
clusterMetrics(): Promise<string>;
clusterMetrics(options?: ClusterMetricsOptions): Promise<string>;

/**
* Creates a new Registry instance from an array of metrics that were
Expand Down Expand Up @@ -192,6 +194,11 @@ export enum MetricType {
Summary,
}

export type ClusterMetricsOptions = {
/** Timeout to wait for all workers to respond before error. */
timeoutMs?: number;
Comment thread
vitush93 marked this conversation as resolved.
};

type CollectFunction<T> = (this: T) => void | Promise<void>;

interface MetricObject {
Expand Down
6 changes: 4 additions & 2 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment thread
vitush93 marked this conversation as resolved.
* @param {number} [options.timeoutMs=5000] Timeout to wait for all workers to respond before error.
* @return {Promise<string>} Promise that resolves with the aggregated
* metrics.
*/
clusterMetrics() {
clusterMetrics(options = { timeoutMs: 5000 }) {
const requestId = requestCtr++;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the value passed into the constructor?


return new Promise((resolve, reject) => {
Expand All @@ -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);

Expand Down