Add non-negativity sanity integration test - #112
Conversation
Signed-off-by: Luis Valdez <[email protected]>
Signed-off-by: Luis Valdez <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds a new integration “sanity” suite to validate broad numeric invariants in /allocation query responses (finite numeric fields, non-negative costs/usage metrics, runtime minutes within window, and computed CPU/RAM/GPU efficiency bounds).
Changes:
- Introduces a new Go integration test that iterates across multiple allocation query windows/aggregations and validates non-negativity + finiteness constraints.
- Adds computed efficiency sanity checks derived from request-average and usage metrics.
- Adds a new Bats entry to run the sanity test package.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| test/integration/query/sanity/test.bats | Adds a Bats entry to execute the new allocation sanity Go test. |
| test/integration/query/sanity/non_negativity_sanity_test.go | Implements allocation response sanity validations (non-negative/finite fields, minutes-within-window, computed efficiency bounds). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // checkComputedCPUEfficiency computes CPU efficiency from request-average and usage data | ||
| // and validates it is within [0, 1 + tolerance]. | ||
| // cpuEfficiency = cpuCoreHours / (cpuCoreRequestAverage * minutes / 60) | ||
| // Skips check if CPU request is negligible (< 1e-6). |
| // checkComputedRAMEfficiency computes RAM efficiency from request-average and usage data | ||
| // and validates it is within [0, 1 + tolerance]. | ||
| // ramEfficiency = ramByteHours / (ramByteRequestAverage * minutes / 60) | ||
| // Skips check if RAM request is negligible (< 1e-6). |
| // checkComputedGPUEfficiency computes GPU efficiency from request-average and usage data | ||
| // and validates it is within [0, 1 + tolerance]. | ||
| // gpuEfficiency = gpuHours / (gpuRequestAverage * minutes / 60) | ||
| // Skips check if GPU request is negligible (< 1e-6). |
| // Efficiency tolerance allows for differences in time units and averaging methods. | ||
| // Request-average fields may use different bases (per-minute, per-second, etc.), | ||
| // so we allow efficiencies up to 5x to catch real issues while avoiding false | ||
| // positives from unit/reporting differences. | ||
| efficiencyTolerance = 5.0 |
…[email protected]> Co-authored-by: Copilot Autofix powered by AI <[email protected]> Signed-off-by: luisvlz0 <[email protected]>
| // Efficiency tolerance allows for differences in time units and averaging methods. | ||
| // Request-average fields may use different bases (per-minute, per-second, etc.), | ||
| // so we allow efficiencies up to 5x to catch real issues while avoiding false | ||
| // positives from unit/reporting differences. | ||
| efficiencyTolerance = 5.0 |
| } | ||
|
|
||
| @test "query allocation non-negativity sanity checks" { | ||
| go test ./test/integration/query/sanity -run TestAllocationNonNegativitySanity -count=1 -v |
| return | ||
| } | ||
|
|
||
| cpuRequestedHours := item.CPUCoreRequestAverage * windowMinutes / 60.0 |
|
We actually had an option to test for negative costs on all fields but chose to do it only for idle costs. I feel the spirit of an integration test should be to test different parts of the system in conjuction, like prometheus providing inputs to opencost and the test comparing the /allocation values. There is a test for "negative idle costs" which does something similar, but checking for idle_costs is relevant because it is a computed by subtracting I feel this test is better suited to be a unit test rather than an integration test. @ameijer , what do you think? |
Adds allocation non-negativity sanity coverage for query responses.
This checks broad numeric invariants for allocation output, including finite numeric values, non-negative costs and usage metrics, runtime minutes within the returned window, and computed CPU/RAM efficiency sanity bounds.
The follow-up adjustment relaxes totalEfficiency validation so the test only requires it to be finite and non-negative, since observed demo values can exceed 1.0.