-
Notifications
You must be signed in to change notification settings - Fork 483
fix(opensearch): enforce ES/OS endpoint separation at the OS index-creation chokepoint (#36419) #36421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+204
−10
Open
fix(opensearch): enforce ES/OS endpoint separation at the OS index-creation chokepoint (#36419) #36421
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5b67783
fix(opensearch): enforce ES/OS endpoint separation at the OS index-cr…
swicken 4224e83
fix(opensearch): distinguish OS config-resolution failure from endpoi…
swicken 1779fcd
fix(opensearch): make separation gate phase-aware; restore pass-log s…
swicken c7efcd9
docs(opensearch): remove stale duplicate javadoc on assertEndpointsSe…
swicken 4567994
fix(opensearch): skip endpoint-separation check in Phase 3 (#36419)
swicken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
dotCMS/src/test/java/com/dotcms/content/index/opensearch/IndexStartupValidatorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package com.dotcms.content.index.opensearch; | ||
|
|
||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import com.dotcms.content.index.IndexConfigHelper; | ||
| import com.dotmarketing.exception.DotRuntimeException; | ||
| import com.dotmarketing.util.Config; | ||
| import org.junit.After; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Unit tests for {@link IndexStartupValidator} endpoint-separation logic. | ||
| * | ||
| * <p>Covers the config-only separation gate ({@link IndexStartupValidator#endpointsAreSeparate()}) | ||
|
swicken marked this conversation as resolved.
|
||
| * used at the OS index-creation chokepoint (issue #36419): OS must point to a cluster separate | ||
| * from ES, otherwise the {@code .os} shadow indices must not be created.</p> | ||
| */ | ||
| public class IndexStartupValidatorTest { | ||
|
|
||
| @After | ||
| public void clearEndpoints() { | ||
| Config.setProperty("ES_ENDPOINTS", null); | ||
| Config.setProperty("OS_ENDPOINTS", null); | ||
| Config.setProperty(IndexConfigHelper.MigrationPhase.FLAG_KEY, 0); | ||
| } | ||
|
|
||
| /** | ||
| * Given Scenario: ES and OS are configured with the same address. | ||
| * Expected Result: endpointsAreSeparate() returns false — OS bootstrap must be skipped. | ||
| */ | ||
| @Test | ||
| public void test_endpointsAreSeparate_sameAddress_returnsFalse() { | ||
| Config.setProperty("ES_ENDPOINTS", new String[]{"https://localhost:9201"}); | ||
| Config.setProperty("OS_ENDPOINTS", new String[]{"https://localhost:9201"}); | ||
|
|
||
| assertFalse(IndexStartupValidator.endpointsAreSeparate()); | ||
| } | ||
|
|
||
| /** | ||
| * Given Scenario: ES and OS point at different ports on the same host. | ||
| * Expected Result: endpointsAreSeparate() returns true — safe to create OS indices. | ||
| */ | ||
| @Test | ||
| public void test_endpointsAreSeparate_differentAddress_returnsTrue() { | ||
| Config.setProperty("ES_ENDPOINTS", new String[]{"https://localhost:9200"}); | ||
| Config.setProperty("OS_ENDPOINTS", new String[]{"https://localhost:9201"}); | ||
|
|
||
| assertTrue(IndexStartupValidator.endpointsAreSeparate()); | ||
| } | ||
|
|
||
| /** | ||
| * Given Scenario: same address, but written with different scheme/formatting. | ||
| * Expected Result: overlap is still detected (normalized to host:port) — returns false. | ||
| */ | ||
| @Test | ||
| public void test_endpointsAreSeparate_sameHostPortDifferentScheme_returnsFalse() { | ||
| Config.setProperty("ES_ENDPOINTS", new String[]{"http://localhost:9201"}); | ||
| Config.setProperty("OS_ENDPOINTS", new String[]{"https://localhost:9201"}); | ||
|
|
||
| assertFalse(IndexStartupValidator.endpointsAreSeparate()); | ||
| } | ||
|
|
||
| /** | ||
| * Given Scenario: multi-endpoint ES [a,b] and OS [b,c] share one endpoint. | ||
| * Expected Result: partial overlap is detected — returns false. | ||
| */ | ||
| @Test | ||
| public void test_endpointsAreSeparate_multiEndpointPartialOverlap_returnsFalse() { | ||
| Config.setProperty("ES_ENDPOINTS", | ||
| new String[]{"https://es-a:9200", "https://shared:9200"}); | ||
| Config.setProperty("OS_ENDPOINTS", | ||
| new String[]{"https://shared:9200", "https://os-c:9200"}); | ||
|
|
||
| assertFalse(IndexStartupValidator.endpointsAreSeparate()); | ||
| } | ||
|
|
||
| /** | ||
| * Given Scenario: OS config cannot be resolved (blank endpoint trips OSClientConfig validation). | ||
| * Expected Result: endpointsAreSeparate() fails closed — returns false — rather than throwing | ||
| * out of the OS bootstrap gate. | ||
| */ | ||
| @Test | ||
| public void test_endpointsAreSeparate_unresolvableOsConfig_returnsFalse() { | ||
| Config.setProperty("ES_ENDPOINTS", new String[]{"https://localhost:9200"}); | ||
| Config.setProperty("OS_ENDPOINTS", new String[]{""}); | ||
|
|
||
| assertFalse(IndexStartupValidator.endpointsAreSeparate()); | ||
| } | ||
|
|
||
| /** | ||
| * Given Scenario: Phase 3 (OPENSEARCH_ONLY) with ES and OS resolving to the same address — | ||
| * legitimate, since ES is decommissioned and ES_ENDPOINTS is not required. | ||
| * Expected Result: the separation check is skipped — endpointsAreSeparate() returns true. | ||
| */ | ||
| @Test | ||
| public void test_endpointsAreSeparate_phase3_checkSkipped_returnsTrue() { | ||
| Config.setProperty(IndexConfigHelper.MigrationPhase.FLAG_KEY, 3); | ||
| Config.setProperty("ES_ENDPOINTS", new String[]{"https://localhost:9201"}); | ||
| Config.setProperty("OS_ENDPOINTS", new String[]{"https://localhost:9201"}); | ||
|
|
||
| assertTrue(IndexStartupValidator.endpointsAreSeparate()); | ||
| } | ||
|
|
||
| /** | ||
| * Given Scenario: ES and OS share the same host:port. | ||
| * Expected Result: assertEndpointsSeparate throws DotRuntimeException naming the overlap. | ||
| */ | ||
| @Test | ||
| public void test_assertEndpointsSeparate_overlap_throws() { | ||
| Config.setProperty("ES_ENDPOINTS", new String[]{"https://localhost:9201"}); | ||
| Config.setProperty("OS_ENDPOINTS", new String[]{"https://localhost:9201"}); | ||
|
|
||
| try { | ||
| IndexStartupValidator.assertEndpointsSeparate( | ||
| ConfigurableOpenSearchProvider.configFromProperties()); | ||
| fail("Expected DotRuntimeException for overlapping ES/OS endpoints"); | ||
| } catch (final DotRuntimeException e) { | ||
| assertTrue("message should name the overlap", | ||
| e.getMessage().contains("point to the same endpoint(s)")); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.