Skip to content

fix(external-cost): align cost re-attribution with ingest resolution - #2384

Merged
yashmehrotra merged 1 commit into
mainfrom
fix-cost-attr
Sep 8, 2026
Merged

fix(external-cost): align cost re-attribution with ingest resolution#2384
yashmehrotra merged 1 commit into
mainfrom
fix-cost-attr

Conversation

@yashmehrotra

@yashmehrotra yashmehrotra commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved cost attribution by restricting matches to the appropriate scraper scope.
    • Added support for matching GCP resources by basename when needed.
    • Prioritized full resource names over conflicting basename matches.
    • Improved selection between live and soft-deleted resources during attribution.
    • Ensured charges without an explicit scraper are attributed using the emitting scraper when applicable.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Benchstat

Base: f35f83028c3611603c1ed576d7c5d4b698b7eb5e
Head: 4c30ba25bbc5cae4528fea6f3f52528950edb984

✅ 2 improvement(s)
Benchmark Base Head Change p-value
LocationFilter/largeEnv-4 49.77µ 45.40µ -8.77% 0.004
BenchSaveResultsUpdateChanged/N=1000-4 7.058 6.944 -1.61% 0.041
Full benchstat output
goos: linux
goarch: amd64
pkg: github.com/flanksource/config-db/bench
cpu: AMD EPYC 9V74 80-Core Processor                
                                         │ bench-base.txt │           bench-head.txt           │
                                         │     sec/op     │    sec/op     vs base              │
LocationFilter/smallEnv-4                     19.29µ ± 1%   21.80µ ± 16%       ~ (p=0.240 n=6)
LocationFilter/largeEnv-4                     49.77µ ± 7%   45.40µ ±  4%  -8.77% (p=0.004 n=6)
RunTemplateBool/smallEnv-4                    11.40µ ± 1%   11.34µ ±  1%       ~ (p=0.132 n=6)
RunTemplateBool/largeEnv-4                    20.53µ ± 1%   20.71µ ±  1%       ~ (p=0.093 n=6)
BenchSaveResultsSeed/N=1000-4                  3.397 ± 4%    3.408 ±  3%       ~ (p=0.394 n=6)
BenchSaveResultsUpdateUnchanged/N=1000-4       2.918 ± 1%    2.919 ±  2%       ~ (p=0.818 n=6)
BenchSaveResultsUpdateChanged/N=1000-4         7.058 ± 4%    6.944 ±  2%  -1.61% (p=0.041 n=6)
geomean                                       3.976m        3.988m        +0.30%

                                         │ bench-base.txt │            bench-head.txt            │
                                         │      B/op      │     B/op      vs base                │
LocationFilter/smallEnv-4                    15.76Ki ± 0%   15.76Ki ± 0%       ~ (p=1.000 n=6) ¹
LocationFilter/largeEnv-4                    21.17Ki ± 0%   21.17Ki ± 0%  +0.00% (p=0.002 n=6)
RunTemplateBool/smallEnv-4                   9.149Ki ± 0%   9.149Ki ± 0%       ~ (p=1.000 n=6) ¹
RunTemplateBool/largeEnv-4                   10.95Ki ± 0%   10.95Ki ± 0%       ~ (p=1.000 n=6) ¹
BenchSaveResultsSeed/N=1000-4                1.295Gi ± 0%   1.295Gi ± 0%       ~ (p=1.000 n=6)
BenchSaveResultsUpdateUnchanged/N=1000-4     32.02Mi ± 0%   32.03Mi ± 0%       ~ (p=0.485 n=6)
BenchSaveResultsUpdateChanged/N=1000-4       796.4Mi ± 1%   796.3Mi ± 1%       ~ (p=0.818 n=6)
geomean                                      1.004Mi        1.004Mi       +0.00%
¹ all samples are equal

                                         │ bench-base.txt │            bench-head.txt            │
                                         │   allocs/op    │  allocs/op    vs base                │
LocationFilter/smallEnv-4                     300.0 ±  0%    300.0 ±  0%       ~ (p=1.000 n=6) ¹
LocationFilter/largeEnv-4                     544.0 ±  0%    544.0 ±  0%       ~ (p=1.000 n=6) ¹
RunTemplateBool/smallEnv-4                    238.0 ±  0%    238.0 ±  0%       ~ (p=1.000 n=6) ¹
RunTemplateBool/largeEnv-4                    319.0 ±  0%    319.0 ±  0%       ~ (p=1.000 n=6) ¹
BenchSaveResultsSeed/N=1000-4                741.7k ±  0%   741.7k ±  0%       ~ (p=0.818 n=6)
BenchSaveResultsUpdateUnchanged/N=1000-4     405.9k ±  0%   405.9k ±  0%       ~ (p=0.665 n=6)
BenchSaveResultsUpdateChanged/N=1000-4       992.1k ± 12%   992.1k ± 12%       ~ (p=0.623 n=6)
geomean                                      8.676k         8.676k        +0.00%
¹ all samples are equal

                                         │ bench-base.txt │           bench-head.txt           │
                                         │      MB/s      │    MB/s     vs base                │
BenchSaveResultsSeed/N=1000-4                0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
BenchSaveResultsUpdateUnchanged/N=1000-4     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
BenchSaveResultsUpdateChanged/N=1000-4       0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                                 ²               +0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 61691a29-30ba-431e-8e75-fa17b5c91a22

📥 Commits

Reviewing files that changed from the base of the PR and between f35f830 and 4c30ba2.

📒 Files selected for processing (2)
  • jobs/config_cost_attribution.go
  • jobs/config_cost_attribution_test.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The cost attribution query now scopes matches by scraper, supports GCP basename fallback, ranks live items ahead of soft-deleted items, and preserves scraper identity during updates. New tests validate these matching and ranking rules.

Changes

Cost attribution

Layer / File(s) Summary
Attribution query and scoping
jobs/config_cost_attribution.go
The SQL carries scraper_id, derives scraper scope and GCP basenames, matches full or basename identifiers, ranks live candidates ahead of deleted candidates, and adds scraper identity to the update join.
Attribution behavior tests
jobs/config_cost_attribution_test.go
Tests cover scraper-owned resources, missing scraper scopes, GCP basename fallback, full-name precedence, and soft-deleted resource ranking.

Merge Risk: ⚪ Minimal · up to 4c30b

Cost re-attribution now selects configuration items using scraper-aware matching, GCP basename fallback, and predictable candidate ranking. The covered behavior introduces no identified merge-blocking risk.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: fixing external-cost re-attribution so it aligns with ingest resolution. It is concise and specific.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-cost-attr
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix-cost-attr

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Gavel results

Gavel exited with code 1.

View full results

@yashmehrotra
yashmehrotra merged commit 917781f into main Sep 8, 2026
17 of 18 checks passed
@yashmehrotra
yashmehrotra deleted the fix-cost-attr branch September 8, 2026 10:29
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.

1 participant