feat: Add PZ metrics for tag count BED-7841#2792
Conversation
📝 WalkthroughWalkthroughAdds Prometheus instrumentation for privilege-zone tag changes: defines a counter vector with ChangesAnalysis subsystem Prometheus metrics
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
fc96ab2 to
9332765
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/go/analysis/agt_test.go (1)
434-514: 💤 Low valueTier tag test looks good; consider adding owned tag coverage.
The new tier tag subtest comprehensively validates the position label calculation for tier tags. Test coverage now includes label tags (2 subtests) and tier tags (1 subtest). For completeness, consider adding a similar test for
AssetGroupTagTypeOwnedto verify the "owned" position label, though it would exercise the same code path as label tags.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/go/analysis/agt_test.go` around lines 434 - 514, Add a parallel subtest that covers AssetGroupTagTypeOwned like the existing tier subtest: create an owned tag via bhDB.CreateAssetGroupTag with model.AssetGroupTagTypeOwned, create a selector via bhDB.CreateAssetGroupTagSelector, create nodes that should be added and nodes that already carry the tag to be removed (using graph.Transaction CreateNode and attaching tagKind where needed), call tagAssetGroupNodesForTag(testCtx, bhDB, graphDB, tag, exclusionSet, nodesToUpdate), and assert nodesToUpdate length and pzNodeTagCounterVec counts with prometheus.Labels{"action":"tag_added","position":"owned"} and {"action":"tag_removed","position":"owned"} to verify the "owned" position label; mirror the setup steps from the tier subtest and reuse symbols tagAssetGroupNodesForTag, pzNodeTagCounterVec, CreateAssetGroupTag, CreateAssetGroupTagSelector, and tag.ToKind() for locating the code to copy.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/go/analysis/agt_test.go`:
- Around line 434-514: Add a parallel subtest that covers AssetGroupTagTypeOwned
like the existing tier subtest: create an owned tag via bhDB.CreateAssetGroupTag
with model.AssetGroupTagTypeOwned, create a selector via
bhDB.CreateAssetGroupTagSelector, create nodes that should be added and nodes
that already carry the tag to be removed (using graph.Transaction CreateNode and
attaching tagKind where needed), call tagAssetGroupNodesForTag(testCtx, bhDB,
graphDB, tag, exclusionSet, nodesToUpdate), and assert nodesToUpdate length and
pzNodeTagCounterVec counts with
prometheus.Labels{"action":"tag_added","position":"owned"} and
{"action":"tag_removed","position":"owned"} to verify the "owned" position
label; mirror the setup steps from the tier subtest and reuse symbols
tagAssetGroupNodesForTag, pzNodeTagCounterVec, CreateAssetGroupTag,
CreateAssetGroupTagSelector, and tag.ToKind() for locating the code to copy.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 26d5a81e-3e40-400d-aa9b-fb0bff78e6d0
📒 Files selected for processing (3)
packages/go/analysis/agt.gopackages/go/analysis/agt_test.gopackages/go/analysis/metrics.go
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/go/analysis/agt.go
Description
Instrument the number of nodes tagged by privilege zones or user tags.
Motivation and Context
Resolves https://specterops.atlassian.net/browse/BED-7841
How Has This Been Tested?
This new metric is verified in an existing integration test. Also tested locally to produce the following output on /metrics:
Screenshots (optional):
Types of changes
Checklist:
Summary by CodeRabbit