Repository navigation
Add cost anomaly detection (day-over-day spend spike) — resolves #17 - #29
Merged
Merged
Conversation
Add a day-over-day spend-spike policy that flags a resource whose daily cost jumps to >=3x its own trailing 7-day average, reading from fact_cost (the normalized azure.cost_export billing export) rather than live inventory/metrics like the existing checks. - policies/cost_anomaly.sql: window-function policy with a full 7-day baseline guard so short histories don't false-positive - cloudcost.cost-anomaly-real.yml: live pipeline reusing azure.cost_export + focus.normalize (no new source plugin needed) - tests/policies/test_cost_anomaly.py: 6 unit tests for the SQL logic Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
raphgm
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #17 — add cost anomaly detection (day-over-day spend spike alerting).
Every existing check finds persistent waste. This adds the complementary "something changed suddenly" signal: a service/resource whose daily spend jumps to 3x or more of its own trailing 7-day average, reading from the normalized billing export (
fact_cost) rather than live inventory/metrics.What's included
policies/cost_anomaly.sqlcloudcost.cost-anomaly-real.ymltests/policies/test_cost_anomaly.pyNo new source plugin is needed: the check reads from
azure.cost_export+focus.normalize, both of which already exist — that's the documented reason the source file is absent from the four-file pattern inCONTRIBUTING.md.Policy logic
fact_costinto per-resource/per-service daily totals.ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING).COUNT(...) >= 7) so short histories can't false-positive on a single-day "average".daily_cost > 3.0 * trailing_avg_7d.Testing
The 6 new tests cover: spike above 3x, spike below 3x, steady spend, full-baseline requirement, per-resource isolation, and empty input.
Verification note
I don't have access to the test Azure account, so I could not run the live
azure.cost_exportpipeline end-to-end; the SQL was verified against in-memoryfact_costtables via the tests above. The finding amount is the spike day's daily spend (billed_cost), withtrailing_avg_7dandspike_multiplierincluded in the evidence for review.