-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Lens] Migration from 7.7 #62879
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
[Lens] Migration from 7.7 #62879
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
54e087d
[Lens] Migration from 7.7
wylieconlon ca51136
Fix types
wylieconlon ccdf919
Merge remote-tracking branch 'origin/master' into lens/7.7-migration-2
wylieconlon e789020
Fix types in test
wylieconlon f900183
Add docs
wylieconlon 9b93e03
Commit forgotten file
wylieconlon ca9043e
Merge remote-tracking branch 'origin/master' into lens/7.7-migration-2
wylieconlon afc2a6d
Remove extra types
wylieconlon 3452d07
Merge branch 'master' into lens/7.7-migration-2
elasticmachine 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { migrations } from './migrations'; | ||
| import { SavedObjectMigrationContext } from 'src/core/server'; | ||
|
|
||
| describe('Lens migrations', () => { | ||
| describe('7.7.0 missing dimensions in XY', () => { | ||
| const context = {} as SavedObjectMigrationContext; | ||
|
|
||
| const example = { | ||
| type: 'lens', | ||
| attributes: { | ||
| expression: | ||
| 'kibana\n| kibana_context query="{\\"language\\":\\"kuery\\",\\"query\\":\\"\\"}" \n| lens_merge_tables layerIds="c61a8afb-a185-4fae-a064-fb3846f6c451" \n tables={esaggs index="logstash-*" metricsAtAllLevels=false partialRows=false includeFormatHints=true aggConfigs="[{\\"id\\":\\"2cd09808-3915-49f4-b3b0-82767eba23f7\\",\\"enabled\\":true,\\"type\\":\\"max\\",\\"schema\\":\\"metric\\",\\"params\\":{\\"field\\":\\"bytes\\"}}]" | lens_rename_columns idMap="{\\"col-0-2cd09808-3915-49f4-b3b0-82767eba23f7\\":\\"2cd09808-3915-49f4-b3b0-82767eba23f7\\"}"}\n| lens_metric_chart title="Maximum of bytes" accessor="2cd09808-3915-49f4-b3b0-82767eba23f7"', | ||
| state: { | ||
| datasourceMetaData: { | ||
| filterableIndexPatterns: [ | ||
| { | ||
| id: 'logstash-*', | ||
| title: 'logstash-*', | ||
| }, | ||
| ], | ||
| }, | ||
| datasourceStates: { | ||
| indexpattern: { | ||
| currentIndexPatternId: 'logstash-*', | ||
| layers: { | ||
| 'c61a8afb-a185-4fae-a064-fb3846f6c451': { | ||
| columnOrder: ['2cd09808-3915-49f4-b3b0-82767eba23f7'], | ||
| columns: { | ||
| '2cd09808-3915-49f4-b3b0-82767eba23f7': { | ||
| dataType: 'number', | ||
| isBucketed: false, | ||
| label: 'Maximum of bytes', | ||
| operationType: 'max', | ||
| scale: 'ratio', | ||
| sourceField: 'bytes', | ||
| }, | ||
| 'd3e62a7a-c259-4fff-a2fc-eebf20b7008a': { | ||
| dataType: 'number', | ||
| isBucketed: false, | ||
| label: 'Minimum of bytes', | ||
| operationType: 'min', | ||
| scale: 'ratio', | ||
| sourceField: 'bytes', | ||
| }, | ||
| 'd6e40cea-6299-43b4-9c9d-b4ee305a2ce8': { | ||
| dataType: 'date', | ||
| isBucketed: true, | ||
| label: 'Date Histogram of @timestamp', | ||
| operationType: 'date_histogram', | ||
| params: { | ||
| interval: 'auto', | ||
| }, | ||
| scale: 'interval', | ||
| sourceField: '@timestamp', | ||
| }, | ||
| }, | ||
| indexPatternId: 'logstash-*', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| filters: [], | ||
| query: { | ||
| language: 'kuery', | ||
| query: '', | ||
| }, | ||
| visualization: { | ||
| accessor: '2cd09808-3915-49f4-b3b0-82767eba23f7', | ||
| isHorizontal: false, | ||
| layerId: 'c61a8afb-a185-4fae-a064-fb3846f6c451', | ||
| layers: [ | ||
| { | ||
| accessors: [ | ||
| 'd3e62a7a-c259-4fff-a2fc-eebf20b7008a', | ||
| '26ef70a9-c837-444c-886e-6bd905ee7335', | ||
| ], | ||
| layerId: 'c61a8afb-a185-4fae-a064-fb3846f6c451', | ||
| seriesType: 'area', | ||
| splitAccessor: '54cd64ed-2a44-4591-af84-b2624504569a', | ||
| xAccessor: 'd6e40cea-6299-43b4-9c9d-b4ee305a2ce8', | ||
| }, | ||
| ], | ||
| legend: { | ||
| isVisible: true, | ||
| position: 'right', | ||
| }, | ||
| preferredSeriesType: 'area', | ||
| }, | ||
| }, | ||
| title: 'Artistpreviouslyknownaslens', | ||
| visualizationType: 'lnsXY', | ||
| }, | ||
| }; | ||
|
|
||
| it('should not change anything by XY visualizations', () => { | ||
| const target = { | ||
| ...example, | ||
| attributes: { | ||
| ...example.attributes, | ||
| visualizationType: 'lnsMetric', | ||
| }, | ||
| }; | ||
| const result = migrations['7.7.0'](target, context); | ||
| expect(result).toEqual(target); | ||
| }); | ||
|
|
||
| it('should handle missing layers', () => { | ||
| const result = migrations['7.7.0']( | ||
| { | ||
| ...example, | ||
| attributes: { | ||
| ...example.attributes, | ||
| state: { | ||
| ...example.attributes.state, | ||
| datasourceStates: { | ||
| indexpattern: { | ||
| layers: [], | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| context | ||
| ); | ||
|
|
||
| expect(result.attributes.state.visualization.layers).toEqual([ | ||
| { | ||
| layerId: 'c61a8afb-a185-4fae-a064-fb3846f6c451', | ||
| seriesType: 'area', | ||
| // Removed split accessor | ||
| splitAccessor: undefined, | ||
| xAccessor: undefined, | ||
| // Removed a yAcccessor | ||
| accessors: [], | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should remove only missing accessors', () => { | ||
| const result = migrations['7.7.0'](example, context); | ||
|
|
||
| expect(result.attributes.state.visualization.layers).toEqual([ | ||
| { | ||
| layerId: 'c61a8afb-a185-4fae-a064-fb3846f6c451', | ||
| seriesType: 'area', | ||
| xAccessor: 'd6e40cea-6299-43b4-9c9d-b4ee305a2ce8', | ||
| // Removed split accessor | ||
| splitAccessor: undefined, | ||
| // Removed a yAcccessor | ||
| accessors: ['d3e62a7a-c259-4fff-a2fc-eebf20b7008a'], | ||
| }, | ||
| ]); | ||
| }); | ||
| }); | ||
| }); |
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,37 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { cloneDeep } from 'lodash'; | ||
| import { SavedObjectMigrationFn } from 'src/core/server'; | ||
|
|
||
| interface XYLayerPre77 { | ||
| layerId: string; | ||
| xAccessor: string; | ||
| splitAccessor: string; | ||
| accessors: string[]; | ||
| } | ||
|
|
||
| export const migrations: Record<string, SavedObjectMigrationFn> = { | ||
| '7.7.0': doc => { | ||
| const newDoc = cloneDeep(doc); | ||
| if (newDoc.attributes?.visualizationType === 'lnsXY') { | ||
| const datasourceState = newDoc.attributes.state?.datasourceStates?.indexpattern; | ||
| const datasourceLayers = datasourceState?.layers ?? {}; | ||
| const xyState = newDoc.attributes.state?.visualization; | ||
| newDoc.attributes.state.visualization.layers = xyState.layers.map((layer: XYLayerPre77) => { | ||
| const layerId = layer.layerId; | ||
| const datasource = datasourceLayers[layerId]; | ||
| return { | ||
| ...layer, | ||
| xAccessor: datasource?.columns[layer.xAccessor] ? layer.xAccessor : undefined, | ||
| splitAccessor: datasource?.columns[layer.splitAccessor] ? layer.splitAccessor : undefined, | ||
| accessors: layer.accessors.filter(accessor => !!datasource?.columns[accessor]), | ||
| }; | ||
| }) as typeof xyState.layers; | ||
| } | ||
| return newDoc; | ||
| }, | ||
| }; |
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.
This line is slightly different from 7.7 because migrations are now registered to specific types