- 
                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
          
     Merged
      
      
    
  
     Merged
                    Changes from 10 commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      391b869
              
                ilm for classic streams
              
              
                klacabane 532759b
              
                reset to default for unwired streams
              
              
                klacabane 8619062
              
                api test
              
              
                klacabane 2ba14aa
              
                Merge branch 'main' into 218-ilm-classic-stream
              
              
                klacabane 8566f7f
              
                [CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
              
              
                kibanamachine 0e2169e
              
                pass prefer_ilm to _settings
              
              
                klacabane e8f352b
              
                important lowercasing
              
              
                klacabane 84f38cc
              
                Merge branch 'main' into 218-ilm-classic-stream
              
              
                klacabane 21dcf0f
              
                Merge branch 'main' into 218-ilm-classic-stream
              
              
                klacabane 2b26c88
              
                remove redundant template settings
              
              
                klacabane 7b62adb
              
                fix tests
              
              
                klacabane addc150
              
                rename dlm
              
              
                klacabane 221fb2f
              
                Merge branch 'main' into 218-ilm-classic-stream
              
              
                klacabane 0c5ebb5
              
                fix unwired inherit
              
              
                klacabane 996da44
              
                only use dsl for serverless tests
              
              
                klacabane 1d1ddc3
              
                dont allow inherit after update
              
              
                klacabane 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -138,32 +138,28 @@ export async function updateDataStreamsLifecycle({ | |
| { logger } | ||
| ); | ||
| 
     | 
||
| // if we transition from ilm to dlm or vice versa, the rolled over backing | ||
| // if we transition from ilm to dsl or vice versa, the rolled over backing | ||
| // indices need to be updated or they'll retain the lifecycle configuration | ||
| // set at the time of creation. | ||
| // this is not needed for serverless since only dlm is allowed but in stateful | ||
| // we update every indices while not always necessary. this should be optimized | ||
| // this is not needed for serverless since only dsl is allowed. | ||
| if (isServerless) { | ||
| return; | ||
| } | ||
| 
     | 
||
| const dataStreams = await esClient.indices.getDataStream({ name: names }); | ||
| const isIlm = isIlmLifecycle(lifecycle); | ||
| 
     | 
||
| for (const dataStream of dataStreams.data_streams) { | ||
| logger.debug(`updating settings for data stream ${dataStream.name} backing indices`); | ||
| await retryTransientEsErrors( | ||
| () => | ||
| esClient.indices.putSettings({ | ||
| index: dataStream.indices.map((index) => index.index_name), | ||
| settings: { | ||
| 'lifecycle.prefer_ilm': isIlm, | ||
| 'lifecycle.name': isIlm ? lifecycle.ilm.policy : null, | ||
| }, | ||
| }), | ||
| { logger } | ||
| ); | ||
| } | ||
| await retryTransientEsErrors( | ||
| () => | ||
| // TODO: use client method once available | ||
| esClient.transport.request({ | ||
| method: 'PUT', | ||
| path: `/_data_stream/${names.join(',')}/_settings`, | ||
| 
         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. this updates backing indices settings as well  | 
||
| body: { | ||
| 'index.lifecycle.name': isIlm ? lifecycle.ilm.policy : null, | ||
| 'index.lifecycle.prefer_ilm': isIlm, | ||
| }, | ||
| }), | ||
| { logger } | ||
| ); | ||
| } catch (err: any) { | ||
| logger.error(`Error updating data stream lifecycle: ${err.message}`); | ||
| throw err; | ||
| 
          
            
          
           | 
    ||
  
    
      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 | 
|---|---|---|
| 
          
            
          
           | 
    @@ -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 { 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); | ||
| 
     | 
||
| 
        
          
        
         | 
    @@ -101,7 +101,7 @@ export class UnwiredStream extends StreamActiveRecord<Streams.UnwiredStream.Defi | |
| startingState: State | ||
| ): Promise<ValidationResult> { | ||
| // 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 +134,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 +153,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 +169,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 +210,12 @@ export class UnwiredStream extends StreamActiveRecord<Streams.UnwiredStream.Defi | |
| }); | ||
| } | ||
| 
     | 
||
| if (this._lifeCycleChanged) { | ||
| if (this._lifecycleChanged) { | ||
| actions.push({ | ||
| type: 'update_lifecycle', | ||
| request: { | ||
| name: this._definition.name, | ||
| lifecycle: this.getLifeCycle(), | ||
| lifecycle: this.getLifecycle(), | ||
| }, | ||
| }); | ||
| } | ||
| 
          
            
          
           | 
    ||
  
    
      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
    
  
  
    
              
      
      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.
  
    
  
    
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.
Adding lifecycle configuration to the template is now redundant since we update the data stream directly in both ilm and dsl cases