Buckets:
| // Copyright (c) 2026 the Zuke contributors | |
| // SPDX-License-Identifier: MIT | |
| /** | |
| * The bounds check of the `cloudMonitoring(...)` canary analysis. Internal to | |
| * the package. | |
| * | |
| * `@zuke/canary` has the same check for its `prometheus(...)` and | |
| * `metricThreshold(...)` analyses, and this one reports in the same words so | |
| * a rollout reads alike whichever analysis failed it. It is not imported | |
| * from there because a wrapper package depends on `@zuke/core` alone. | |
| * | |
| * @module | |
| */ | |
| /** Inclusive bounds a metric must stay within; either side may be open. */ | |
| interface Bounds { | |
| /** The lowest acceptable value, if any. */ | |
| min?: number; | |
| /** The highest acceptable value, if any. */ | |
| max?: number; | |
| } | |
| /** | |
| * The bounds `min` and `max` describe, refusing a set that cannot work. Each | |
| * is finite already: the analysis's setters refuse anything else. | |
| */ | |
| export function boundsOf( | |
| label: string, | |
| min: number | undefined, | |
| max: number | undefined, | |
| ): Bounds { | |
| if (min === undefined && max === undefined) { | |
| throw new Error(`"${label}" sets no bound — call .min(...) or .max(...).`); | |
| } | |
| if (min !== undefined && max !== undefined && min > max) { | |
| throw new Error( | |
| `"${label}" can never pass: its minimum ${min} is above its maximum ` + | |
| `${max}.`, | |
| ); | |
| } | |
| return { | |
| ...(min === undefined ? {} : { min }), | |
| ...(max === undefined ? {} : { max }), | |
| }; | |
| } | |
| /** | |
| * Throw when `value` is not a number within `bounds`, naming the metric. | |
| * Cloud Monitoring can send a double as `"NaN"`, which compares false both | |
| * ways and would pass every bound, so it fails here as canary's check fails | |
| * it. | |
| */ | |
| export function checkThreshold( | |
| label: string, | |
| value: number, | |
| bounds: Bounds, | |
| ): void { | |
| if (Number.isNaN(value)) throw new Error(`${label} is not a number (NaN).`); | |
| if (bounds.max !== undefined && value > bounds.max) { | |
| throw new Error(`${label} is ${value}, above the maximum ${bounds.max}.`); | |
| } | |
| if (bounds.min !== undefined && value < bounds.min) { | |
| throw new Error(`${label} is ${value}, below the minimum ${bounds.min}.`); | |
| } | |
| } | |
Xet Storage Details
- Size:
- 2.1 kB
- Xet hash:
- 93e6c983178697d4dd34273fc5f8eb768fc21943f9da4240d528a6acfdf4834b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.