diff --git a/README.md b/README.md index 362f9a7..5e1fc38 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ Configure options for the new instance of MetricsHistory. ##### options.limit? Type: `integer` -Default: `10` +Default: `60` FIFO size of array for calculating percentile. diff --git a/src/MetricsHistory.mjs b/src/MetricsHistory.mjs index c2fbc0b..7fba72f 100644 --- a/src/MetricsHistory.mjs +++ b/src/MetricsHistory.mjs @@ -1,7 +1,7 @@ import { Observer } from '@esmj/observable'; export class MetricsHistory extends Observer { - #options = { limit: 10 }; + #options = { limit: 60 }; #history = []; constructor(options) { @@ -9,6 +9,10 @@ export class MetricsHistory extends Observer { this.#options = { ...this.#options, ...options }; } + get size() { + return this.#history.length; + } + complete() { this.#history = []; } diff --git a/src/__tests__/MetricsHistorySpec.mjs b/src/__tests__/MetricsHistorySpec.mjs index 9099e4c..4bb7d8e 100644 --- a/src/__tests__/MetricsHistorySpec.mjs +++ b/src/__tests__/MetricsHistorySpec.mjs @@ -70,5 +70,6 @@ describe('MetricsHistory', () => { expect(percentile25).toMatchInlineSnapshot(`4`); expect(percentile20).toMatchInlineSnapshot(`2.6000000000000005`); expect(percentile0).toMatchInlineSnapshot(`1`); + expect(metricsHistory.size).toEqual(6); }); });