Skip to content
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

Ensure index templates are not applied to system indices #16418

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

pyek-bot
Copy link

@pyek-bot pyek-bot commented Oct 22, 2024

Description

Prevents index templates from applying to system indices

Related Issues

Resolves #16340

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Pavan Yekbote <mail2pavanyekbote@gmail.com>
@pyek-bot
Copy link
Author

Please advice for backporting

@pyek-bot pyek-bot changed the title [Bug fix] Ensure index templates are not applied to system indices Ensure index templates are not applied to system indices Oct 22, 2024
Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach LGTM.

How can we test this? I've been looking at MetadataCreateIndexTests and don't see that we ever test this method directly.

@dbwiddis dbwiddis added the backport 2.x Backport to 2.x branch label Oct 22, 2024
@dbwiddis
Copy link
Member

Please advice for backporting

We should definitely backport to 2.x. The SystemIndices code is 2.16 though so we can't go further back.

Signed-off-by: Pavan Yekbote <mail2pavanyekbote@gmail.com>
@pyek-bot
Copy link
Author

Approach LGTM.

How can we test this? I've been looking at MetadataCreateIndexTests and don't see that we ever test this method directly.

I will add some test cases

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes LGTM! Waiting for tests to approve.

Copy link
Contributor

❌ Gradle check result for f51c296: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Pavan Yekbote <mail2pavanyekbote@gmail.com>
@pyek-bot
Copy link
Author

Code changes LGTM! Waiting for tests to approve.

Added test cases, please review it. Also, modified one of the methods' access from private to public to enable testing.

Copy link
Contributor

✅ Gradle check result for d838ec2: SUCCESS

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.11%. Comparing base (5941a7e) to head (09a27c9).
Report is 4 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #16418      +/-   ##
============================================
- Coverage     72.16%   72.11%   -0.06%     
+ Complexity    65115    65065      -50     
============================================
  Files          5313     5313              
  Lines        303362   303375      +13     
  Branches      43901    43904       +3     
============================================
- Hits         218917   218765     -152     
- Misses        66489    66653     +164     
- Partials      17956    17957       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dbwiddis
Copy link
Member

@pyek-bot this needs a changelog entry

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending changelog entry. Would appreciate review of @reta or @dblock or @andrross here. I'm confident in the code, but we're fundamentally changing (undocumented and poor) behavior (in what I think is a very good way) so would like more eyes on.

@dbwiddis
Copy link
Member

dbwiddis commented Oct 23, 2024

Also, modified one of the methods' access from private to public to enable testing.

You can make it package private (no modifier) so that a test in the same package can access it.

Signed-off-by: Pavan Yekbote <mail2pavanyekbote@gmail.com>
Signed-off-by: Pavan Yekbote <mail2pavanyekbote@gmail.com>
Copy link
Contributor

✅ Gradle check result for 09a27c9: SUCCESS

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@andrross andrross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes sense to me. Just one comment about the unit test. @dbwiddis is there any way to create an integration test of the scenario you observed that would validate this fix?

Comment on lines +2603 to +2617
metadataCreateIndexService.applyCreateIndexRequest(clusterState, request, false, mockMetadataTransformer);
verify(metadataCreateIndexService).applyCreateIndexRequestWithNoTemplates(
eq(clusterState),
eq(request),
eq(false),
eq(mockMetadataTransformer)
);

verify(metadataCreateIndexService).applyCreateIndexRequestWithV1Templates(
eq(clusterState),
eq(request),
eq(false),
eq(Collections.emptyList()),
eq(mockMetadataTransformer)
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't think tests like these add a lot of value. You're really just testing that you're calling an internal method that you think you're calling. This isn't verifying that the code is actually doing the thing you expect it to be doing (i.e. that index templates are not actually applied to a system index). Furthermore, this becomes brittle to internal refactorings of the class under test even if the refactoring does not change the behavior of the class at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any way to create an integration test of the scenario you observed that would validate this fix?

Good call-out. This seems the better approach here. The repro in the original issue should be easy to set up in an integ test, the only hitch here is making sure systemIndices is populated with whatever test index we're choosing, unless the test is isolated enough that we can use one of the actual indices specified.

Copy link
Collaborator

@reta reta Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having an YAML spec or IT test case would definitely be helpful

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, IT test will actually validate this behavior rather than simply check for a method call. Is there a guide to how such a test can be added? I could take a look.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pyek-bot Here is an example test that asserts that deprecation warnings are emitted when a user writes to a system index:

public void testSystemIndexAccessBlockedByDefault() throws Exception {

@reta reta added v3.0.0 Issues and PRs related to version 3.0.0 v2.19.0 Issues and PRs related to version 2.19.0 labels Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch bug Something isn't working Indexing Indexing, Bulk Indexing and anything related to indexing v2.19.0 Issues and PRs related to version 2.19.0 v3.0.0 Issues and PRs related to version 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Composable index template mapping can prevent creating an index if mappings conflict
5 participants