Skip to content

Commit

Permalink
[8.x] [Lens] dont use legacy metric in the suggestions (#197101) (#19…
Browse files Browse the repository at this point in the history
…7337)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Lens] dont use legacy metric in the suggestions
(#197101)](#197101)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marta
Bondyra","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-22T20:04:07Z","message":"[Lens]
dont use legacy metric in the suggestions (#197101)\n\n##
Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/197078","sha":"6f44bf5b65843ce656c6b66e37403be91e19b96b","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Visualizations","release_note:skip","Feature:Lens","v9.0.0","backport:prev-minor"],"title":"[Lens]
dont use legacy metric in the
suggestions","number":197101,"url":"https://github.com/elastic/kibana/pull/197101","mergeCommit":{"message":"[Lens]
dont use legacy metric in the suggestions (#197101)\n\n##
Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/197078","sha":"6f44bf5b65843ce656c6b66e37403be91e19b96b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197101","number":197101,"mergeCommit":{"message":"[Lens]
dont use legacy metric in the suggestions (#197101)\n\n##
Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/197078","sha":"6f44bf5b65843ce656c6b66e37403be91e19b96b"}}]}]
BACKPORT-->

Co-authored-by: Marta Bondyra <[email protected]>
  • Loading branch information
kibanamachine and mbondyra authored Oct 25, 2024
1 parent 273b32c commit cd01cb5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
3 changes: 2 additions & 1 deletion test/functional/apps/discover/group3/_lens_vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
return seriesType;
}

describe('discover lens vis', function () {
// Failing: See https://github.com/elastic/kibana/issues/197342
describe.skip('discover lens vis', function () {
before(async () => {
await security.testUser.setRoles(['kibana_admin', 'test_logstash_reader']);
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('metric_suggestions', () => {
expect(rest).toHaveLength(0);
expect(suggestion).toMatchInlineSnapshot(`
Object {
"hide": false,
"hide": true,
"previewIcon": [Function],
"score": 0.1,
"state": Object {
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('metric_suggestions', () => {
expect(rest).toHaveLength(0);
expect(suggestion).toMatchInlineSnapshot(`
Object {
"hide": false,
"hide": true,
"previewIcon": [Function],
"score": 0.1,
"state": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function getSuggestion(

return {
title,
hide: datasourceId === 'textBased',
hide: true,
score: 0.1,
previewIcon: IconChartMetric,
state: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('metric suggestions', () => {
// should ignore bucketed column for initial drag
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.51,
},
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('metric suggestions', () => {
breakdownByAccessor: bucketColumn.columnId,
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.51,
},
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('metric suggestions', () => {
breakdownByAccessor: bucketColumn.columnId,
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.51,
},
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('metric suggestions', () => {
breakdownByAccessor: bucketColumn.columnId,
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.52,
},
Expand Down Expand Up @@ -326,7 +326,7 @@ describe('metric suggestions', () => {
breakdownByAccessor: bucketColumn.columnId,
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.52,
},
Expand Down Expand Up @@ -357,7 +357,7 @@ describe('metric suggestions', () => {
breakdownByAccessor: bucketColumn.columnId,
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.52,
},
Expand Down
13 changes: 9 additions & 4 deletions x-pack/plugins/lens/public/visualizations/metric/suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const getSuggestions: Visualization<MetricVisualizationState>['getSuggest

const bucketedColumns = table.columns.filter(({ operation }) => operation.isBucketed);

const hasInterval = bucketedColumns.some(({ operation }) => operation.scale === 'interval');

const unsupportedColumns = table.columns.filter(
({ operation }) => !supportedDataTypes.has(operation.dataType) && !operation.isBucketed
);
Expand Down Expand Up @@ -59,11 +61,10 @@ export const getSuggestions: Visualization<MetricVisualizationState>['getSuggest
layerId: table.layerId,
layerType: LayerTypes.DATA,
},
title: metricLabel,
title: metricColumns[0]?.operation.label || metricLabel,
previewIcon: IconChartMetric,
score: 0.5,
// don't show suggestions since we're in tech preview
hide: true,
hide: hasInterval,
};

const accessorMappings: Pick<MetricVisualizationState, 'metricAccessor' | 'breakdownByAccessor'> =
Expand All @@ -72,7 +73,11 @@ export const getSuggestions: Visualization<MetricVisualizationState>['getSuggest
breakdownByAccessor: bucketedColumns[0]?.columnId,
};

baseSuggestion.score += 0.01 * Object.values(accessorMappings).filter(Boolean).length;
baseSuggestion.score = Number(
(baseSuggestion.score + 0.01 * Object.values(accessorMappings).filter(Boolean).length).toFixed(
2
)
);

const suggestion = {
...baseSuggestion,
Expand Down

0 comments on commit cd01cb5

Please sign in to comment.