Skip to content

Add aggregation cost conservation test#103

Open
Noah-Philip wants to merge 2 commits into
opencost:mainfrom
Noah-Philip:add-aggregation-cost-conservation-test
Open

Add aggregation cost conservation test#103
Noah-Philip wants to merge 2 commits into
opencost:mainfrom
Noah-Philip:add-aggregation-cost-conservation-test

Conversation

@Noah-Philip

Copy link
Copy Markdown

Description

Adds an allocation aggregation cost conservation test.

The test queries the same completed historical window across multiple aggregation levels:

  • cluster
  • node
  • namespace
  • pod
  • container

It sums totalCost for each aggregation and verifies that each total matches the cluster total within a documented absolute-or-relative tolerance.

Implementation

  • Uses the same query parameters for every aggregation
  • Uses yesterday to avoid live-window drift between sequential requests
  • Includes idle cost separately with includeIdle=true
  • Avoids redistributing idle with shareIdle=false
  • Uses cluster aggregation as the comparison baseline
  • Allows small differences from rounding and floating-point accumulation
  • Failure output reports the divergent aggregation, cluster total, aggregation total, absolute difference, and relative difference

Testing

Using demo cluster:

  • go test -count=1 ./test/integration/api/allocation -run TestAllocationCostConservedAcrossAggregations -v
  • bats test/integration/api/allocation/test.bats

Signed-off-by: noah-philip <noahphilip06@outlook.com>
Copilot AI review requested due to automatic review settings June 16, 2026 16:19
@Noah-Philip Noah-Philip requested a review from a team as a code owner June 16, 2026 16:19

Copilot AI left a comment

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds a new integration test that validates cost conservation across different aggregation levels in the allocation API. It ensures that querying the same historical window with different aggregations (cluster, node, namespace, pod, container) yields consistent total costs within a defined tolerance.

Changes:

  • Added a new Go test file that queries the allocation API at multiple aggregation levels and compares their total costs against the cluster-level baseline.
  • Registered the new test in the bats test runner.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/integration/api/allocation/test.bats Adds a new bats entry to run the aggregation cost conservation test.
test/integration/api/allocation/aggregation_cost_conservation_test.go New test that fetches allocation totals for multiple aggregation levels and asserts they match the cluster total within tolerance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/integration/api/allocation/aggregation_cost_conservation_test.go Outdated
Signed-off-by: noah-philip <noahphilip06@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants