Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/fix-summary-nan-quantiles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Fix `Metric.summary` and `Metric.summaryWithTimestamp` accepting NaN quantiles.
2 changes: 1 addition & 1 deletion packages/effect/src/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,7 @@ class SummaryMetric extends Metric$<readonly [value: number, timestamp: number],
const observations = Arr.allocate<[number, number]>(this.#maxSize)

for (const quantile of this.#quantiles) {
if (quantile < 0 || quantile > 1) {
if (!(quantile >= 0 && quantile <= 1)) {
throw new Error(`Quantile must be between 0 and 1, found: ${quantile}`)
}
}
Expand Down
11 changes: 11 additions & 0 deletions packages/effect/test/Metric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,17 @@ describe("Metric", () => {
})

describe("Summary", () => {
it.effect("rejects NaN quantiles on first use", () =>
Effect.gen(function*() {
const summary = Metric.summary(nextId(), {
maxAge: "1 minute",
maxSize: 10,
quantiles: [Number.NaN]
})
const result = yield* Effect.exit(Metric.update(summary, 1))
assert.deepStrictEqual(result, Exit.die(new Error("Quantile must be between 0 and 1, found: NaN")))
}))

it.effect("reports the maximum for negative-only observations", () =>
Effect.gen(function*() {
const summary = Metric.summary(nextId(), {
Expand Down
Loading