Repository navigation
feat: mute known findings via an exclusions config key - #1845
Conversation
|
Heads-up on the failing License Compliance check: this diff is purely additive Go code (no dependency changes — verified |
AlexsJones
left a comment
There was a problem hiding this comment.
Thanks @CJstate, this follows the design note closely and the ApplyExclusions placement (after both analysis passes, before GetAIResults, and in the server handler) is exactly right.
A few things before this can go in:
- Users have no way to get a hash. The design note says
k8sgpt analyzeprints each finding's hash (text suffix plus a JSONhashfield), but nothing in this diff outputs it, so the only way to write an exclusion today is to recompute SHA-256 by hand. Since the CLI subcommand is a follow-up, the hash output needs to land in this PR or the feature isn't usable on its own. expiresrejects the documented format. The PR description and the design note both useexpires: "2026-12-31", butloadExclusionsinpkg/analysis/exclusions.goparses withtime.RFC3339, so that value goes toa.Errorsand the entry is dropped. Accepttime.DateOnlyas well (treating it as end of that day is probably the least surprising), and add the date-only case to the expiry test.- Excluded count only shows in JSON.
Excludedis wired intojsonOutputbut the text output doesn't mention it, while the note promised both. A one-line "N findings excluded" in text output is enough.
The License Compliance failure isn't yours, agreed: it's coming from main's dependency tree, so no need to touch it here.
|
Thanks for the detailed review - all three points are addressed in 1. Users can now get a hash. The hash is printed after each finding in text output and exposed as its own `
It is projected at render time from the same inputs 2. 3. Excluded count now shows in text output. A
One unrelated note while running the suite on Windows: |
0cf69e8 to
92e4406
Compare
|
One more thing worth flagging, because it affects both this PR and #1841. The I also fixed a DCO slip in Still happy to take the |
|
Correction to my previous comment — I need to walk back one claim. I wrote that the What is true:
If the failure came purely from the base dependency tree, #1848 would fail as well. It does not, so my "it's the base tree" explanation cannot be right. Since #1841 adds a single test file and never touches I cannot fix what I cannot see, so I am not going to guess at a dependency change. What I can offer:
Sorry for the noise on the diagnosis. The code review points are unaffected — all three are addressed in |
AlexsJones
left a comment
There was a problem hiding this comment.
Thanks @CJstate, all three points are covered, and keeping the hash as a render-only projection is a nice touch.
Checked at 92e4406:
- Text output prints
hash=<12 hex>after each failure, and JSON gets ahashfield fromresultsWithFindingHashes, which copies the results so the hash stays out of the AI payload. I also checked--anonymize:GetAIResultsmasks a range copy of each failure, soa.Resultskeeps the raw text and the printed hash matches whatApplyExclusionschecks. parseExpiryaccepts2026-12-31and treats it as the end of that day, with tests.- "N findings excluded" now shows in text output, including the no-problems case.
Looks good to me. It's a feat and adds a new config key, so the final call is a manual merge, and the Go build and test workflows haven't run on this head yet (License Compliance is the main issue in #1850).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1845 +/- ##
===========================================
+ Coverage 34.76% 61.91% +27.14%
===========================================
Files 94 131 +37
Lines 6342 8710 +2368
===========================================
+ Hits 2205 5393 +3188
+ Misses 4046 2961 -1085
- Partials 91 356 +265 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The fork workflows ran at The linter only reports changed lines, which is why its neighbours pass. Switching that one call to |
Users have asked since 2023 to silence findings they already know about, so an analysis surfaces only new issues (k8sgpt-ai#372). Add an `exclusions` key to the existing viper config, next to active_filters and custom_analyzers: each entry carries a required reason, a 12-hex-char content hash, and an optional RFC3339 expiry. FindingHash derives that hash from Kind, the result's namespace/name key, and the whitespace-normalized failure text, before any anonymization; normalizing whitespace keeps the hash stable across pod restarts (container-restart counts drift) while still changing when the finding's substance changes. ApplyExclusions runs analyzer-agnostically after RunAnalysis/RunCustomAnalysis and before GetAIResults/PrintOutput, so it covers built-in and custom analyzers, skips the AI call for muted findings, and applies in server mode too. A Result survives unless every failure in it is muted, and the JSON output reports how many failures were dropped as `excluded`, so a mute cannot silently swallow findings. A k8sgpt exclusions add/list/remove command will follow as a second PR so this one stays small, per the design note in k8sgpt-ai#372. Signed-off-by: CJstate <[email protected]>
Addresses the three points from review: 1. Findings now carry their exclusion hash. `analyze` prints `hash=<12>` after each finding in text output and exposes it as a `hash` field in JSON, so the value written into the exclusions config can be read off the output instead of being recomputed by hand. The hash is projected at render time from the same inputs `ApplyExclusions` matches on (Kind, Name and the pre-anonymization failure text), so it is identical to the value the mute path compares and it never enters the AI provider payload. 2. `expires` accepts the documented date-only form. `parseExpiry` keeps RFC 3339 as the precise form and treats `2026-12-31` as the end of that local day, so an exclusion dated today still covers today. Malformed values are still reported and the entry is dropped. 3. Text output reports the mute count. A `N findings excluded` line is printed when anything was muted, both in the no-problems and the problems-present branch, matching what JSON already exposes. Tests cover the text `hash=` suffix, the JSON `hash` field, the excluded count in text, the date-only and RFC 3339 expiry forms, a malformed expiry and the fact that rendering does not mutate `a.Results`. The License Compliance failure is unchanged and, as noted, comes from main's dependency tree rather than this diff. Signed-off-by: CJstate <[email protected]>
staticcheck QF1012 flags the new WriteString(fmt.Sprintf(...)) call; write straight to the builder instead. Signed-off-by: CJstate <[email protected]>
106a5af to
881982b
Compare
AlexsJones
left a comment
There was a problem hiding this comment.
Thanks for the rebase and the lint fix, @CJstate. CI is fully green at 881982b, including License Compliance, and the three earlier review points still hold.
One gap before I can sign this off: the MCP analyze tool doesn't apply exclusions. pkg/server/mcp.go line 480 calls analysis.RunAnalysis() and goes straight to GetAIResults, so a muted finding still shows up for MCP clients and still costs an AI call when Explain is set. The CLI and pkg/server/analyze/analyze.go are both covered, so this is the last entry point. Add analysis.ApplyExclusions() right after line 480, with a small test if you can.
Small one while you're there: the FindingHash comment says collapsing whitespace keeps the hash stable across restart counts, but a changed count changes the text and so the hash. Could you reword it to say only whitespace drift is ignored?
The MCP handleAnalyze ran RunAnalysis and went straight to GetAIResults or PrintOutput, so a finding muted through the exclusions config still reached MCP clients and still cost an AI call when Explain was set. Apply ApplyExclusions right after RunAnalysis, matching the CLI and the server-mode handler, and cover it with a regression test that mutes a CrashLoopBackOff finding and asserts it disappears from the tool output. Also reword the FindingHash comment: collapsing whitespace only ignores whitespace drift; a changed restart count does change the hash. Signed-off-by: CJstate <[email protected]>
|
Both points are addressed in 1. MCP analyze now applies exclusions. The regression test ( 2. Verified locally: |
AlexsJones
left a comment
There was a problem hiding this comment.
Thanks @CJstate, both points are handled cleanly.
Delta checked at f608ad8: handleAnalyze now calls analysis.ApplyExclusions() right after RunAnalysis(), so the MCP path matches the CLI and pkg/server/analyze. TestHandleAnalyzeAppliesExclusions shows the finding before the hash is muted and gone after, which is the right shape. The FindingHash comment now says only whitespace drift is ignored.
One thing before this can merge: GitHub reports the branch as conflicting with main (several pkg/server and pkg/ai PRs landed this week). Could you rebase? Once CI is green on the rebased head I'll sign off.
Approving the change itself.
|
Also covering the lint point from your review: |
|
Thanks @CJstate, confirmed: The only thing left is the conflict with |
Resolve the test-file conflict by keeping both the new MCP exclusions regression test and the filter validation tests added on main.
|
Hi @AlexsJones — thanks again for the approval on this one. The branch had fallen 31 commits behind The conflict was only in the test file: No rush, just flagging that it's mergeable again whenever you get a chance. Thanks! |
AlexsJones
left a comment
There was a problem hiding this comment.
Thanks for sorting the conflict, @CJstate, and for keeping both sets of tests in pkg/server/mcp_handlers_test.go.
Delta checked at f15aa57: I compared the PR diff before and after the merge of main. The production changes are identical, and the only movement is in the test file, where TestHandleAnalyzeAppliesExclusions now sits after main's filter tests. build, golangci-lint and codecov are green on this head.
This is a feat, signed off under the maintainer's 2026-10-24 decision that a fully reviewed feature with green CI can merge. It implements the exclusions design from #372.
Good to merge
Part of #372 — implements the core from the design note posted earlier in the issue.
📑 Description
Users have asked since 2023 to silence findings they already know about so an analysis surfaces only new issues. This adds an
exclusionskey to the existing config file, next toactive_filtersandcustom_analyzers:ApplyExclusions()runs once afterRunAnalysis/RunCustomAnalysisand beforeGetAIResults/PrintOutput— covering built-in and custom analyzers, skipping the AI call for muted findings, and applying in server mode too (the handler runs it the same way).FindingHash): SHA-256 overKind + namespace/name + whitespace-normalized failure text, first 12 hex chars, computed before any anonymization. Whitespace normalization keeps the hash stable across pod restarts (container-restart counts drift between runs) while still changing when the finding's substance changes — the mute lifts on its own, so suppressions cannot go stale.excluded, so a mute cannot silently swallow findings.k8sgpt exclusions add/list/removecommand will follow as a second PR so this one stays small, as discussed in the issue.✅ Checks
ℹ Additional Information
Five new tests cover the mute path, whitespace stability, partial muting, expiry, and the reasonless-entry rejection. The hash recipe intentionally matches the design note in #372; if the proto's
AnalyzeResponseshould also carryexcluded, happy to add that in the follow-up PR.