-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[streams][lifecycle] ilm for classic streams #221364
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
Changes from all commits
391b869
532759b
8619062
2ba14aa
8566f7f
0e2169e
e8f352b
84f38cc
21dcf0f
2b26c88
7b62adb
addc150
221fb2f
0c5ebb5
996da44
1d1ddc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,10 +39,6 @@ describe('generateLayer', () => { | |
| }, | ||
| "name": "[email protected]", | ||
| "template": Object { | ||
| "lifecycle": Object { | ||
| "data_retention": "30d", | ||
| "enabled": true, | ||
| }, | ||
| "mappings": Object { | ||
| "dynamic": false, | ||
| "properties": Object { | ||
|
|
@@ -63,10 +59,7 @@ describe('generateLayer', () => { | |
| }, | ||
| }, | ||
| }, | ||
| "settings": Object { | ||
| "index.lifecycle.name": undefined, | ||
| "index.lifecycle.prefer_ilm": false, | ||
| }, | ||
| "settings": Object {}, | ||
| }, | ||
| "version": 1, | ||
| } | ||
|
|
@@ -83,9 +76,6 @@ describe('generateLayer', () => { | |
| }, | ||
| "name": "[email protected]", | ||
| "template": Object { | ||
| "lifecycle": Object { | ||
| "data_retention": "30d", | ||
| }, | ||
| "mappings": Object { | ||
| "dynamic": false, | ||
| "properties": Object { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import type { | |
| IngestProcessorContainer, | ||
| } from '@elastic/elasticsearch/lib/api/types'; | ||
| import type { IngestStreamLifecycle } from '@kbn/streams-schema'; | ||
| import { isDslLifecycle, isInheritLifecycle, Streams } from '@kbn/streams-schema'; | ||
| import { isIlmLifecycle, isInheritLifecycle, Streams } from '@kbn/streams-schema'; | ||
| import _, { cloneDeep } from 'lodash'; | ||
| import { isNotFoundError } from '@kbn/es-errors'; | ||
| import { StatusError } from '../../errors/status_error'; | ||
|
|
@@ -28,7 +28,7 @@ import { StreamActiveRecord, PrintableStream } from '../stream_active_record/str | |
|
|
||
| export class UnwiredStream extends StreamActiveRecord<Streams.UnwiredStream.Definition> { | ||
| private _processingChanged: boolean = false; | ||
| private _lifeCycleChanged: boolean = false; | ||
| private _lifecycleChanged: boolean = false; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to align naming |
||
|
|
||
| constructor(definition: Streams.UnwiredStream.Definition, dependencies: StateDependencies) { | ||
| super(definition, dependencies); | ||
|
|
@@ -42,7 +42,7 @@ export class UnwiredStream extends StreamActiveRecord<Streams.UnwiredStream.Defi | |
| return { | ||
| ...super.toPrintable(), | ||
| processingChanged: this._processingChanged, | ||
| lifeCycleChanged: this._lifeCycleChanged, | ||
| lifecycleChanged: this._lifecycleChanged, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -77,7 +77,7 @@ export class UnwiredStream extends StreamActiveRecord<Streams.UnwiredStream.Defi | |
| startingStateStreamDefinition.ingest.processing | ||
| ); | ||
|
|
||
| this._lifeCycleChanged = | ||
| this._lifecycleChanged = | ||
| !startingStateStreamDefinition || | ||
| !_.isEqual(this._definition.ingest.lifecycle, startingStateStreamDefinition.ingest.lifecycle); | ||
|
|
||
|
|
@@ -100,8 +100,24 @@ export class UnwiredStream extends StreamActiveRecord<Streams.UnwiredStream.Defi | |
| desiredState: State, | ||
| startingState: State | ||
| ): Promise<ValidationResult> { | ||
| if (this.dependencies.isServerless && isIlmLifecycle(this.getLifecycle())) { | ||
| return { isValid: false, errors: [new Error('Using ILM is not supported in Serverless')] }; | ||
| } | ||
|
|
||
| if ( | ||
| startingState.get(this._definition.name)?.definition && | ||
| this._lifecycleChanged && | ||
| isInheritLifecycle(this.getLifecycle()) | ||
| ) { | ||
| // temporary until https://github.com/elastic/kibana/issues/222440 is resolved | ||
| return { | ||
| isValid: false, | ||
| errors: [new Error('Cannot revert to default lifecycle once updated')], | ||
| }; | ||
| } | ||
|
|
||
| // Check for conflicts | ||
| if (this._lifeCycleChanged || this._processingChanged) { | ||
| if (this._lifecycleChanged || this._processingChanged) { | ||
| try { | ||
| const dataStreamResult = | ||
| await this.dependencies.scopedClusterClient.asCurrentUser.indices.getDataStream({ | ||
|
|
@@ -134,19 +150,6 @@ export class UnwiredStream extends StreamActiveRecord<Streams.UnwiredStream.Defi | |
| } | ||
| } | ||
|
|
||
| if (this._lifeCycleChanged && isDslLifecycle(this.getLifeCycle())) { | ||
| const dataStream = await this.dependencies.streamsClient.getDataStream(this._definition.name); | ||
| if (dataStream.ilm_policy !== undefined) { | ||
| return { | ||
| isValid: false, | ||
| errors: [ | ||
| new Error( | ||
| 'Cannot apply DSL lifecycle to a data stream that is already managed by an ILM policy' | ||
| ), | ||
| ], | ||
| }; | ||
| } | ||
| } | ||
| return { isValid: true, errors: [] }; | ||
| } | ||
|
|
||
|
|
@@ -166,12 +169,12 @@ export class UnwiredStream extends StreamActiveRecord<Streams.UnwiredStream.Defi | |
| if (this._definition.ingest.processing.length > 0) { | ||
| actions.push(...(await this.createUpsertPipelineActions())); | ||
| } | ||
| if (!isInheritLifecycle(this.getLifeCycle())) { | ||
| if (!isInheritLifecycle(this.getLifecycle())) { | ||
| actions.push({ | ||
| type: 'update_lifecycle', | ||
| request: { | ||
| name: this._definition.name, | ||
| lifecycle: this.getLifeCycle(), | ||
| lifecycle: this.getLifecycle(), | ||
| }, | ||
| }); | ||
| } | ||
|
|
@@ -182,11 +185,11 @@ export class UnwiredStream extends StreamActiveRecord<Streams.UnwiredStream.Defi | |
| return actions; | ||
| } | ||
|
|
||
| public hasChangedLifeCycle(): boolean { | ||
| return this._lifeCycleChanged; | ||
| public hasChangedLifecycle(): boolean { | ||
| return this._lifecycleChanged; | ||
| } | ||
|
|
||
| public getLifeCycle(): IngestStreamLifecycle { | ||
| public getLifecycle(): IngestStreamLifecycle { | ||
| return this._definition.ingest.lifecycle; | ||
| } | ||
|
|
||
|
|
@@ -223,12 +226,12 @@ export class UnwiredStream extends StreamActiveRecord<Streams.UnwiredStream.Defi | |
| }); | ||
| } | ||
|
|
||
| if (this._lifeCycleChanged) { | ||
| if (this._lifecycleChanged && !isInheritLifecycle(this.getLifecycle())) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there was a bug here where applying inherit after a dsl/ilm was first applied would force an infinite retention instead of being a noop |
||
| actions.push({ | ||
| type: 'update_lifecycle', | ||
| request: { | ||
| name: this._definition.name, | ||
| lifecycle: this.getLifeCycle(), | ||
| lifecycle: this.getLifecycle(), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
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 updates backing indices settings as well