fix: improve FileFilter metrics - #700
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This comment has been minimized.
This comment has been minimized.
|
snyk-pr-review-bot and cursor's points were already taken into consideration as tradeoffs for this implementation. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e44fac5. Configure here.
This comment has been minimized.
This comment has been minimized.
e44fac5 to
2a4fe69
Compare
This comment has been minimized.
This comment has been minimized.
2a4fe69 to
490a2a2
Compare
This comment has been minimized.
This comment has been minimized.
490a2a2 to
96815b6
Compare
This comment has been minimized.
This comment has been minimized.
96815b6 to
a8ebf29
Compare
This comment has been minimized.
This comment has been minimized.
danskmt
left a comment
There was a problem hiding this comment.
Approved, left some comments.
Please remove some of the comments as they are not really needed
This comment has been minimized.
This comment has been minimized.
ed7d885 to
ce88e3d
Compare
This comment has been minimized.
This comment has been minimized.
ce88e3d to
a3f69a2
Compare
This comment has been minimized.
This comment has been minimized.
| // accumulated is shared by all Accumulators. | ||
| var ( | ||
| accumulatedMu sync.Mutex | ||
| accumulated = map[string]int{} |
There was a problem hiding this comment.
Suggestion: Ignoring for now that this is called Accumulator, You could actually track all the entries using map[string][]int and calculate different things from it, sum, mean, median ...
There was a problem hiding this comment.
This is more an optional suggestion. or design feedback
| metricFileFilterRulesBuildDurationMs = "rulesBuildDurationMs" // elapsed time for GetRules: directory walk, ignore discovery, and buildGlobs | ||
| metricFileFilterMetacharacterFix = "metacharacterFix" // whether FF_FILE_FILTER_METACHARACTER_FIX was enabled for this run | ||
| metricFileFilterRespectTrackedFiles = "respectTrackedFiles" // whether FF_GITIGNORE_RESPECT_TRACKED_FILES was enabled for this run | ||
| metricFileFilterVariantLegacy = "var0" // neither feature flag enabled |
There was a problem hiding this comment.
Question: what do we do when the feature flags are being removed and the feature will just be enabled?
There was a problem hiding this comment.
Should var0 just be something like default file filter configuration?
There was a problem hiding this comment.
I'm not sure we have the character allowance for a long descriptive name. I went with var0, var1, etc., in the first place because names like "legacy" or "metaFix" were too long.
What if we drop the var3 prefix entirely instead? Then var0, var1, and var2 can act as our temporary ones.
file-filter.filter.inputFileCount instead of file-filter.var3.filter.inputFileCount
file-filter.var0.filter.inputFileCount would remain file-filter.var0.filter.inputFileCount
There was a problem hiding this comment.
sounds good, default is no var
This comment has been minimized.
This comment has been minimized.
| metricFileFilterVariantMetacharFix = "var1" // FF_FILE_FILTER_METACHARACTER_FIX only | ||
| metricFileFilterVariantTrackedFiles = "var2" // FF_GITIGNORE_RESPECT_TRACKED_FILES only | ||
| metricFileFilterVariantBothFixes = "" // both feature flags enabled; the variant segment is omitted | ||
|
|
||
| metricFileFilterInputFileCount = "filter.inputFileCount" // files offered to GetFilteredFiles, before exclusion | ||
| metricFileFilterRuleCount = "filter.ruleCount" // glob patterns GetRules produced | ||
|
|
||
| // Record feature flags alongside the variant so consumers need not decode its name. | ||
| metricFileFilterFeatureMetacharFix = "feature.metaCharFix" // whether FF_FILE_FILTER_METACHARACTER_FIX applied to the run | ||
| metricFileFilterFeatureTrackedFiles = "feature.includeTracked" // whether FF_GITIGNORE_RESPECT_TRACKED_FILES applied to the run |
There was a problem hiding this comment.
they all have same prefix name metricFileFilter, but their values are different. I would suggest improving this naming. Since we are inside file_filter.go, we could use metricVariantXYZ for the var ones, metricFilterXYZ for the 'filter.' ones and metricFeatureXYZ for the 'feature.' ones, WDYT?
| metricFileFilterDurationMs = "filter.durationMs" // elapsed time for GetFilteredFiles, including the caller's drain of the result channel | ||
| metricFileFilterRulesBuildDurationMs = "rules.durationMs" // elapsed time for GetRules: directory walk, ignore discovery, and buildGlobs | ||
| metricFileFilterSurvivingFileCount = "filter.outputFileCount" // number of files that passed exclusion |
There was a problem hiding this comment.
same here, and organize them better so the similar ones stays together
This comment has been minimized.
This comment has been minimized.
danskmt
left a comment
There was a problem hiding this comment.
LGTM - Added some suggestions
e3b7c6a to
89a8bff
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1e2afc0 to
d15ddc6
Compare
PR Reviewer Guide 🔍
|
This comment has been minimized.
This comment has been minimized.
d15ddc6 to
f934962
Compare
This comment has been minimized.
This comment has been minimized.
f934962 to
437ec56
Compare
This comment has been minimized.
This comment has been minimized.
|
Also looks good to me, just wondering if the PR bot feedback was address/dismissed before 😄 |
PR Reviewer Guide 🔍
|

Description
This PR improves FileFilter analytics by replacing per-run metric scopes with stable keys that aggregate repeated runs. Runs are grouped by the feature-flag combination they use, allowing input/output file counts, rule counts, and durations, to be compared across variants. Temporary legacy variants: var0 (no feature flags), var1 (metaCharFix), var2 (gitIgnoreRespectTrackedFiles).
This PR also introduces a concurrency-safe metrics accumulator.
Tests cover every feature-flag variant, repeated and concurrent runs, nil recorders, aggregation behavior, and FileFilter metrics reaching invocation analytics.
Checklist
make test)make generate)make lint)go get github.com/snyk/go-application-framework@YOUR_LATEST_GAF_COMMITin thecliv2directory.go.modto point to your local GAF code.go mod tidyin thecliv2directory.go.modandgo.sumchanges.Note
Medium Risk
Analytics key schema and aggregation semantics change for FileFilter metrics consumed via invocation analytics; filtering behavior is unchanged when metrics are disabled.
Overview
FileFilter analytics no longer use per-run scope IDs (
file-filter.<scopeID>.<metric>). Metrics are written under stable keys grouped by feature-flag combination (var0/var1/var2, orfile-filter.<metric>when both flags are on), and repeated runs aggregate into the same keys instead of overwriting each other.A new
metrics.Accumulatorbacks this: it sums integer metrics (input/output counts, durations), keeps per-key maximums, and records bools without aggregation, with mutex-protected global state shared across accumulators on different recorders.ResetAccumulatedclears that state for tests.FileFilterwiresWithMetricsthrough an accumulator and skips flag reads when nothing is recording.Metric names and semantics shift: e.g.
survivingFileCount→filter.outputFileCount,rulesBuildDurationMs→rules.durationMs, plusfilter.inputFileCount; duration fields are summed across calls for a variant. Feature flags are recorded asfeature.metaCharFixandfeature.includeTracked.RecorderFakegainsNewRecorderFake()so maps are always initialized.Tests cover aggregation, concurrency, variants, and invocation analytics extension keys; workflow tests expect the new
file-filter.var0.*shape.Reviewed by Cursor Bugbot for commit 8b8d122. Bugbot is set up for automated code reviews on this repo. Configure here.