Skip to content

Stabilize the pod-count test (#94)#105

Open
e-300 wants to merge 2 commits into
opencost:mainfrom
e-300:add-pod-count-test
Open

Stabilize the pod-count test (#94)#105
e-300 wants to merge 2 commits into
opencost:mainfrom
e-300:add-pod-count-test

Conversation

@e-300

@e-300 e-300 commented Jun 16, 2026

Copy link
Copy Markdown
Member

Description

The pod-count test (test/integration/query/count/allocation_running_pods_test.go) compares running pods per namespace from two independent sources (allocation API and Prometheus).
The issue in the previous code was that both sources sampled the cluster at two different time windows.

Changes

  • Shared timestamp. One endTime is computed per attempt at a completed hour boundary; the API now uses an absolute window=start,end (verified to resolve to the exact requested interval) instead of the relative 24h form that drifted to the request-processing instant. Prometheus continues to query at the same endTime.
  • Set-overlap tolerance. Per-namespace comparison now uses overlap (intersection/union) against a documented threshold (overlapThreshold = 0.80) instead of exact counts. Namespaces below a size floor (minNamespacePods = 3) require sets to be equal. A namespace present in only one namespace would cause the test to fail.
  • Retries. Up to 3 attempts with backoff; each attempt re-samples a complete fresh timestamp pair
  • Diagnostic output. Failures print the sampled window (unix + UTC), per-namespace pod sets, and the symmetric difference (api-only vs prom-only)

Related issues

Testing

Passed against the demo cluster, all namespaces with both sources sharing one window (e.g. kube-system 149/149).
Local k3d run is blocked (404 on /allocation, no workloads).

Signed-off-by: Ebad Shahid <ebad@ebad.dev>
@e-300
e-300 requested a review from a team as a code owner June 16, 2026 18:07
Copilot AI review requested due to automatic review settings June 16, 2026 18:07

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 rewrites the integration test for comparing pod counts between the Allocation API and Prometheus. It replaces a simple count comparison with a Jaccard overlap-based approach that includes retry logic, absolute time windows, and improved filtering.

Changes:

  • Replaced strict pod-count equality checks with Jaccard overlap comparison (exact-match for small namespaces, ratio threshold for larger ones)
  • Added retry logic (maxResampleAttempts) with re-anchored absolute time windows to handle transient churn
  • Improved synthetic pod filtering from a hardcoded allowlist to suffix-based matching (-unmounted-pvcs)

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

Comment on lines 19 to +20
)
const (
Comment on lines +75 to +76
endTime = time.Now().UTC().Truncate(time.Hour).Unix()
startTime = endTime - 86400

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented single duration time window from tc.window

Comment on lines +182 to +187
intersection := 0
for _, p := range apiAgg.Pods {
if slices.Contains(promAgg.Pods, p) {
intersection++
}
}
Signed-off-by: Ebad Shahid <ebad@ebad.dev>
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.

Stabilize pod-count test: shared timestamp, churn tolerance, retries

2 participants