Repository navigation
perf(stacks): cache per-component auth within a describe-stacks pass - #2644
Brian Ojeda (sgtoj) wants to merge 2 commits into
Conversation
`processComponentEntry` resolved per-component auth (a full credential write + file lock + keyring rebuild) before applying the stack and component filters. Because describe-stacks walks every stack file, `atmos secret list -s <stack>` authenticated every component in every other stack before discarding it, scaling with the whole repo and appearing to hang on large repos. Move the stack and component filters ahead of resolveComponentAuthManager so per-component auth runs only for in-scope components. Auth still precedes its consumers (BuildTerraformWorkspace, Go-template and YAML-function processing), so nothing downstream loses its AuthContext. This also benefits `describe stacks -s` and the `list` family. Adds a table-driven regression test asserting the resolver is not invoked for out-of-scope stacks or components. Closes cloudposse#2639
Even after scoping per-component auth to the requested stack (cloudposse#2642), every component declaring its own default identity ran a full authentication cycle (a credentials-file rewrite under a file lock plus a keyring rebuild). On a stack whose components import the same default identity from a shared _defaults.yaml, that is N redundant cycles for one identity. Add a pass-scoped cache on the describe-stacks processor, keyed by the parent auth chain plus a deterministic JSON fingerprint of the component auth section. createComponentAuthManager derives its result solely from the auth section, the constant global config, and the parent manager (componentName/stackName affect only logging), so an identical auth section yields an equivalent, identity-scoped manager — safe to reuse. Fingerprinting the auth section rather than a bare identity name keeps reuse provably correct: it never merges components whose sections differ. Measured on a representative multi-stack repo, `atmos secret list -s <stack>` without --component dropped from 68 processor-path authentications to 1 (total auth cycles 110 -> 43, wall time ~34s -> ~21s) with identical output. Errors are never cached; sections that cannot be serialized fall back to no caching. Follows cloudposse#2642.
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
📝 WalkthroughWalkthroughAdds a pass-scoped Changesdescribe-stacks Auth Filter Ordering and Per-Pass Cache
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@internal/exec/describe_stacks_component_processor_auth_test.go`:
- Line 431: Replace the three instances of assert.EqualValues with
require.EqualValues at lines 431, 467, and 477 in the test file. These
assertions validate critical filter behavior and cache correctness—if they fail,
the test should stop immediately rather than continue. Change assert.EqualValues
to require.EqualValues for each of the three occurrences to ensure test failures
are caught immediately and prevent false test passes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4b437e98-e05c-4dc5-8d33-146959a360a0
📒 Files selected for processing (4)
docs/fixes/2026-06-20-describe-stacks-per-identity-auth-cache.mddocs/fixes/2026-06-20-secret-list-stack-scope-per-component-auth.mdinternal/exec/describe_stacks_component_processor.gointernal/exec/describe_stacks_component_processor_auth_test.go
| ) | ||
|
|
||
| require.NoError(t, err, "out-of-scope component must be skipped without resolving auth") | ||
| assert.EqualValues(t, 0, spy.calls.Load(), "per-component auth must not run for an out-of-scope component") |
There was a problem hiding this comment.
Use require for critical test assertions, not assert.
Lines 431, 467, and 477 use assert.EqualValues to verify that the resolver was (or was not) invoked as expected. These are core assertions about filter behavior and cache correctness—if they fail, the test should fail immediately, not silently. Replace assert.EqualValues with require.EqualValues.
- assert.EqualValues(t, 0, spy.calls.Load(), "per-component auth must not run for an out-of-scope component")
+ require.EqualValues(t, 0, spy.calls.Load(), "per-component auth must not run for an out-of-scope component")
- assert.EqualValues(t, 1, spy.calls.Load(), "second component with an identical auth section must reuse the cached manager")
+ require.EqualValues(t, 1, spy.calls.Load(), "second component with an identical auth section must reuse the cached manager")
- assert.EqualValues(t, 2, spy.calls.Load(), "a distinct auth section must miss the cache and resolve anew")
+ require.EqualValues(t, 2, spy.calls.Load(), "a distinct auth section must miss the cache and resolve anew")Also applies to: 467-467, 477-477
🤖 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 `@internal/exec/describe_stacks_component_processor_auth_test.go` at line 431,
Replace the three instances of assert.EqualValues with require.EqualValues at
lines 431, 467, and 477 in the test file. These assertions validate critical
filter behavior and cache correctness—if they fail, the test should stop
immediately rather than continue. Change assert.EqualValues to
require.EqualValues for each of the three occurrences to ensure test failures
are caught immediately and prevent false test passes.
Source: Coding guidelines
|
This extends #2642 . I didn't include the change in the previous PR because I didn't want to do anything to delay that fix being merged. This new PR extend that previous PR and improves performance. It reduced the time it took to complete this |
what
authManagerCache) to the describe-stacks processor so components that share an auth section authenticate once per pass instead of once each.TestResolveComponentAuthManager_CachesByAuthSection) and a fix doc.why
default: trueidentity ran a full authentication cycle — a credentials-file rewrite (under a file lock) plus a keyring rebuild. On a stack whose components import the same default identity from a shared_defaults.yaml, that is N redundant cycles for one identity.createComponentAuthManagerderives its result solely from the component's auth section, the (constant) global config, and the parent manager (componentName/stackNameare used only for logging), so components with an identical auth section produce an equivalent, identity-scoped manager — safe to reuse. Fingerprinting the auth section (rather than a bare identity name) keeps reuse provably correct: it never merges two components whose sections differ.atmos secret list -s <stack>(no--component): processor-path authentications 68 → 1, total auth cycles 110 → 43, wall time ~34s → ~21s, with identical output. Errors are never cached; sections that can't be serialized fall back to no caching.references
fix(stacks): scope per-component auth ...) as well as thisperfcommit. Once fix(stacks): scope per-component auth to requested stack/components #2642 merges, this can be rebased ontomainto leave only theperfcommit.docs/fixes/2026-06-20-describe-stacks-per-identity-auth-cache.md!terraform.output/atmos.Componentresolution path (resolveAuthManagerForNestedComponent), which doesn't share this processor cache — documented as a follow-up.Summary by CodeRabbit
Release Notes
Bug Fixes
atmos secret list -s <stack>command hanging by eliminating unnecessary authentication for out-of-scope components.Performance
Tests