Skip to content

Commit 3bfcd86

Browse files
committed
[Metrics UI] Fix Metrics Explorer TSVB link to use workaround pattern (#73986)
* [Metrics UI] Fix Metrics Explorer TSVB link to use workaround pattern * Adding link to TSVB bug to comment
1 parent 8f6e055 commit 3bfcd86

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,25 @@ describe('createTSVBLink()', () => {
157157
});
158158
});
159159

160+
it('should use the workaround index pattern when there are multiple listed in the source', () => {
161+
const customSource = {
162+
...source,
163+
metricAlias: 'my-beats-*,metrics-*',
164+
fields: { ...source.fields, timestamp: 'time' },
165+
};
166+
const link = createTSVBLink(customSource, options, series, timeRange, chartOptions);
167+
expect(link).toStrictEqual({
168+
app: 'visualize',
169+
hash: '/create',
170+
search: {
171+
_a:
172+
"(filters:!(),linked:!f,query:(language:kuery,query:''),uiState:(),vis:(aggs:!(),params:(axis_formatter:number,axis_min:0,axis_position:left,axis_scale:normal,default_index_pattern:'metric*',filter:(language:kuery,query:'host.name : \"example-01\"'),id:test-id,index_pattern:'metric*',interval:auto,series:!((axis_position:right,chart_type:line,color:#6092C0,fill:0,formatter:percent,id:test-id,label:'avg(system.cpu.user.pct)',line_width:2,metrics:!((field:system.cpu.user.pct,id:test-id,type:avg)),point_size:0,separate_axis:0,split_mode:everything,stacked:none,value_template:{{value}})),show_grid:1,show_legend:1,time_field:time,type:timeseries),title:example-01,type:metrics))",
173+
_g: '(refreshInterval:(pause:!t,value:0),time:(from:now-1h,to:now))',
174+
type: 'metrics',
175+
},
176+
});
177+
});
178+
160179
test('createFilterFromOptions()', () => {
161180
const customOptions = { ...options, groupBy: 'host.name' };
162181
const customSeries = { ...series, id: 'test"foo' };

x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/helpers/create_tsvb_link.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ import { SourceQuery } from '../../../../../graphql/types';
2323
import { createMetricLabel } from './create_metric_label';
2424
import { LinkDescriptor } from '../../../../../hooks/use_link_props';
2525

26+
/*
27+
We've recently changed the default index pattern in Metrics UI from `metricbeat-*` to
28+
`metrics-*,metricbeat-*`. There is a bug in TSVB when there is an empty index in the pattern
29+
the field dropdowns are not populated correctly. This index pattern is a temporary fix.
30+
See: https://github.com/elastic/kibana/issues/73987
31+
*/
32+
const TSVB_WORKAROUND_INDEX_PATTERN = 'metric*';
33+
2634
export const metricsExplorerMetricToTSVBMetric = (metric: MetricsExplorerOptionsMetric) => {
2735
if (metric.aggregation === 'rate') {
2836
const metricId = uuid.v1();
@@ -128,13 +136,23 @@ export const createFilterFromOptions = (
128136
return { language: 'kuery', query: filters.join(' and ') };
129137
};
130138

139+
const createTSVBIndexPattern = (alias: string) => {
140+
if (alias.split(',').length > 1) {
141+
return TSVB_WORKAROUND_INDEX_PATTERN;
142+
}
143+
return alias;
144+
};
145+
131146
export const createTSVBLink = (
132147
source: SourceQuery.Query['source']['configuration'] | undefined,
133148
options: MetricsExplorerOptions,
134149
series: MetricsExplorerSeries,
135150
timeRange: MetricsExplorerTimeOptions,
136151
chartOptions: MetricsExplorerChartOptions
137152
): LinkDescriptor => {
153+
const tsvbIndexPattern = createTSVBIndexPattern(
154+
(source && source.metricAlias) || TSVB_WORKAROUND_INDEX_PATTERN
155+
);
138156
const appState = {
139157
filters: [],
140158
linked: false,
@@ -147,8 +165,8 @@ export const createTSVBLink = (
147165
axis_position: 'left',
148166
axis_scale: 'normal',
149167
id: uuid.v1(),
150-
default_index_pattern: (source && source.metricAlias) || 'metricbeat-*',
151-
index_pattern: (source && source.metricAlias) || 'metricbeat-*',
168+
default_index_pattern: tsvbIndexPattern,
169+
index_pattern: tsvbIndexPattern,
152170
interval: 'auto',
153171
series: options.metrics.map(mapMetricToSeries(chartOptions)),
154172
show_grid: 1,

0 commit comments

Comments
 (0)