-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[RAC] Add mapping update logic to RuleDataClient #102586
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
Merged
marshallmain
merged 21 commits into
elastic:master
from
marshallmain:rule-data-client-index-versioning
Jul 8, 2021
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4b78e40
Add component template versioning to RuleDataClient
marshallmain 33461c1
Add versioning for index templates
marshallmain 19b9eaf
Address PR comments, add error handling inside rolloverAliasIfNeeded
marshallmain 3a1fe7c
Merge branch 'master' into rule-data-client-index-versioning
kibanamachine bbd8335
Fix security alerts index name, rollover func param, more robust roll…
marshallmain 4ccf63a
Add empty mapping check to createOrUpdateIndexTemplate
marshallmain c9c7a87
Fix error path in createWriteTargetIfNeeded to suppress resource_alre…
marshallmain cd184c3
Merge branch 'rule-data-client-index-versioning' of github.com:marsha…
marshallmain a45a70a
Add code comments around rollover logic
marshallmain be0f777
Replace numeric versions with semver
marshallmain c8e2642
Use optional chaining operator to fetch current write index mapping
marshallmain 7a4bc11
Fix template version number
marshallmain efcf928
Merge branch 'master' into rule-data-client-index-versioning
kibanamachine 852a8b0
Move mapping updates to plugin startup, remove dependency on componen…
marshallmain bae03df
Undo changes to lifecycle and persistance rule type factories
marshallmain 5e99679
Merge branch 'master' into rule-data-client-index-versioning
marshallmain 0be60e1
Remove test code
marshallmain a87dd50
Simplify race mitigation logic
marshallmain 88a4d9e
Remove outdated comment
marshallmain c1aaa5e
Merge branch 'master' into rule-data-client-index-versioning
kibanamachine d3f099a
Add unit tests, log unexpected errors instead of rethrowing
marshallmain 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
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
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/rule_registry/server/rule_data_plugin_service/utils.test.ts
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,28 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { incrementIndexName } from './utils'; | ||
|
|
||
| describe('incrementIndexName', () => { | ||
| it('should increment 000001 to 000002', () => { | ||
| const oldIndex = '.alerts-mock-000001'; | ||
| const newIndex = incrementIndexName(oldIndex); | ||
| expect(newIndex).toEqual('.alerts-mock-000002'); | ||
| }); | ||
|
|
||
| it('should increment 000010 to 000011', () => { | ||
| const oldIndex = '.alerts-mock-000010'; | ||
| const newIndex = incrementIndexName(oldIndex); | ||
| expect(newIndex).toEqual('.alerts-mock-000011'); | ||
| }); | ||
|
|
||
| it('should return undefined if oldIndex does not end in a number', () => { | ||
| const oldIndex = '.alerts-mock-string'; | ||
| const newIndex = incrementIndexName(oldIndex); | ||
| expect(newIndex).toEqual(undefined); | ||
| }); | ||
| }); |
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/rule_registry/server/rule_data_plugin_service/utils.ts
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,15 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| export function incrementIndexName(oldIndex: string) { | ||
| const baseIndexString = oldIndex.slice(0, -6); | ||
| const newIndexNumber = Number(oldIndex.slice(-6)) + 1; | ||
| if (isNaN(newIndexNumber)) { | ||
| return undefined; | ||
| } | ||
| return baseIndexString + String(newIndexNumber).padStart(6, '0'); | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this should be removed. I don't see the same check in
rolloverAliasIfNeeded, and I think we should be explicit about this, because teams new to RAC will run into it - I did, too, and it is a little annoying to figure out and repair.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sort of check seems like it belongs with the template bootstrapping logic IMO. At this point we've already created the index, so simulating it seems redundant. Can we move this check so it happens sometime before the index is created, maybe at index template creation time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with moving it, but I do would like to keep it, somewhere. But let's figure out first where this all needs to happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be always some common mappings specified (currently they are specified in templates installed in
init()-TECHNICAL_COMPONENT_TEMPLATE_NAMEandECS_COMPONENT_TEMPLATE_NAME). We just have to make sure that final index templates always reference (composed_of) these common component templates.I'd say this is a matter of having an API that doesn't provide 100% flexibility in index bootstrapping and makes sure that index template is always created and it always references the common templates - doesn't matter how the client of the library uses it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this check to index template creation time in 4ccf63a