fix: ConfigService.getConfig(appId, namespace) returns wrong app's config#140
fix: ConfigService.getConfig(appId, namespace) returns wrong app's config#140Shawyeok wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughAdds a public ConfigService.getConfigFile(appId, namespace, configFileFormat) overload, updates DefaultConfigFactory to pass appId when resolving config files, adds tests validating custom appId for Config and ConfigFile lookups, and adds a probe helper to wait for namespaces. ChangesAppId-aware ConfigFile retrieval
Sequence DiagramsequenceDiagram
participant DefaultConfigFactory
participant ConfigService
participant ConfigManager
DefaultConfigFactory->>ConfigService: getConfigFile(appId, namespace, format)
ConfigService->>ConfigManager: getConfigFile(appId, namespace, format)
ConfigManager-->>ConfigService: ConfigFile
ConfigService-->>DefaultConfigFactory: ConfigFile
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #140 +/- ##
============================================
+ Coverage 68.68% 71.17% +2.48%
- Complexity 1503 1640 +137
============================================
Files 212 224 +12
Lines 6396 6733 +337
Branches 647 680 +33
============================================
+ Hits 4393 4792 +399
+ Misses 1673 1592 -81
- Partials 330 349 +19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 `@apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigService.java`:
- Around line 104-115: Update the Javadoc for ConfigService.getConfigFile:
clarify that the namespace parameter should NOT include a file extension (e.g.,
use "application" not "application.yml") because the extension is derived from
the configFileFormat and appended internally by DefaultConfigManager; reference
ConfigService.getConfigFile, the namespace parameter, and ConfigFileFormat (and
DefaultConfigManager behavior) in the comment so callers know to pass just the
base namespace name.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: af07b96b-693d-4836-af0e-931a7384e731
📒 Files selected for processing (3)
apollo-client/src/main/java/com/ctrip/framework/apollo/ConfigService.javaapollo-client/src/main/java/com/ctrip/framework/apollo/spi/DefaultConfigFactory.javaapollo-client/src/test/java/com/ctrip/framework/apollo/ConfigServiceTest.java
…tory for non-default appId DefaultConfigFactory.createPropertiesCompatibleFileConfigRepository() received an appId parameter but called ConfigService.getConfigFile(namespace, format) — the two-arg overload that ignores appId and resolves against the default app.id from app.properties. Fixes the bug by: 1. Adding ConfigService.getConfigFile(appId, namespace, format) that delegates to the already-correct ConfigManager.getConfigFile(appId, namespace, format). 2. Updating DefaultConfigFactory to call the new three-arg overload so the caller-specified appId is preserved. Adds tests: - DefaultConfigFactoryTest.testCreatePropertiesCompatibleFileConfigRepositoryForwardsCustomAppId: verifies ConfigManager is invoked with the supplied appId, never the default. - ConfigServiceTest.testGetConfigFileWithCustomAppId: verifies the new ConfigService.getConfigFile(appId, ns, format) overload returns a ConfigFile whose getAppId() equals the requested appId. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2a1096e to
c7d2dac
Compare
The test was asserting that the first ApolloConfigChangeEvent is for 'application', but async notification dispatch does not guarantee ordering. Replace the strict first-event check with a helper that drains events until the expected namespace is found within the timeout window. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apollo-compat-tests/apollo-spring-compat-it/src/test/java/com/ctrip/framework/apollo/compat/spring/SpringApolloEventListenerProbe.java (1)
41-55: Discarded namespaces aren’t a reliability problem in the current test
waitForNamespace(...)consumes thenamespacesqueue viapoll(...)and discards non-matching values, but in this module theSpringApolloEventListenerProbeis only consumed once (waitForNamespace("application", ...)inSpringAnnotationCompatibilityTest), and there are no other usages of the probe (no otherwaitForNamespace/pollNamespacecalls). Discarding won’t affect later assertions here.
If you later reuse the same probe instance to wait for multiple different namespaces, consider a non-destructive approach (e.g., retain unmatched values).🤖 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 `@apollo-compat-tests/apollo-spring-compat-it/src/test/java/com/ctrip/framework/apollo/compat/spring/SpringApolloEventListenerProbe.java` around lines 41 - 55, waitForNamespace in SpringApolloEventListenerProbe currently polls and discards non-matching entries from the namespaces queue, which may lose events if the probe is reused; change the logic in waitForNamespace (and any helper like namespaces queue handling) to be non-destructive: peek the head and only poll when it matches expectedNamespace (or temporarily buffer unmatched values and requeue them if needed) so unmatched namespace values are retained for subsequent waits (reference waitForNamespace, namespaces, and SpringApolloEventListenerProbe to locate the code; consider SpringAnnotationCompatibilityTest which calls waitForNamespace("application", ...)).
🤖 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
`@apollo-compat-tests/apollo-spring-compat-it/src/test/java/com/ctrip/framework/apollo/compat/spring/SpringApolloEventListenerProbe.java`:
- Around line 41-55: waitForNamespace in SpringApolloEventListenerProbe
currently polls and discards non-matching entries from the namespaces queue,
which may lose events if the probe is reused; change the logic in
waitForNamespace (and any helper like namespaces queue handling) to be
non-destructive: peek the head and only poll when it matches expectedNamespace
(or temporarily buffer unmatched values and requeue them if needed) so unmatched
namespace values are retained for subsequent waits (reference waitForNamespace,
namespaces, and SpringApolloEventListenerProbe to locate the code; consider
SpringAnnotationCompatibilityTest which calls waitForNamespace("application",
...)).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 85763920-8d5b-434f-9070-533887030288
📒 Files selected for processing (2)
apollo-compat-tests/apollo-spring-compat-it/src/test/java/com/ctrip/framework/apollo/compat/spring/SpringAnnotationCompatibilityTest.javaapollo-compat-tests/apollo-spring-compat-it/src/test/java/com/ctrip/framework/apollo/compat/spring/SpringApolloEventListenerProbe.java
This reverts commit 6261c1e.
|
Thanks for the fix. I checked the latest head ( I do not see a blocking issue from this pass. A maintainer can do the final approval/merge decision. Note: this reply was generated and posted automatically by AI for initial triage; a maintainer will follow up if needed. |
Problem
ConfigService.getConfig(appId, "some-namespace.yml")silently returns config belonging to the default application (app.idinapp.properties) instead of the requestedappId, with no error or warning.The same bug affects any non-properties namespace format (YAML, YML, JSON, XML, TXT).
Root cause
DefaultConfigFactory.create(appId, namespace)correctly dispatches tocreatePropertiesCompatibleFileConfigRepository(appId, namespace, format)for non-properties namespaces, but that method then calls the two-argConfigService.getConfigFile(namespace, format)— silently droppingappId:ConfigManageralready had a correct three-arggetConfigFile(appId, namespace, format)overload, but it was not exposed onConfigService.Fix
ConfigService.java— add the missing overload that mirrors the existinggetConfig(appId, namespace)pattern:DefaultConfigFactory.java— use the new overload soappIdis preserved:Tests
| Test | What it verifies |
|------|-----------------||
ConfigServiceTest.testGetConfigWithCustomAppId|ConfigService.getConfig(appId, namespace)returns aConfigwhose property values reflect the requested appId, not the default ||
ConfigServiceTest.testGetConfigFileWithCustomAppId|ConfigService.getConfigFile(appId, ns, format)returns aConfigFilewhosegetAppId()matches the requested appId |Affected versions
Reproducible on
apollo-client 2.4.0and2.5.0.ConfigFileFormat.Propertiesnamespaces are unaffected (they go throughcreateConfigRepository, notcreatePropertiesCompatibleFileConfigRepository).Summary by CodeRabbit
New Features
Tests