Skip to content

Commit

Permalink
[Metrics UI] Fix Metrics Explorer TSVB link to use workaround pattern (
Browse files Browse the repository at this point in the history
…elastic#73986)

* [Metrics UI] Fix Metrics Explorer TSVB link to use workaround pattern

* Adding link to TSVB bug to comment
  • Loading branch information
simianhacker committed Jul 31, 2020
1 parent 7b90b31 commit 6fa39eb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ describe('createTSVBLink()', () => {
});
});

it('should use the workaround index pattern when there are multiple listed in the source', () => {
const customSource = {
...source,
metricAlias: 'my-beats-*,metrics-*',
fields: { ...source.fields, timestamp: 'time' },
};
const link = createTSVBLink(customSource, options, series, timeRange, chartOptions);
expect(link).toStrictEqual({
app: 'visualize',
hash: '/create',
search: {
_a:
"(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))",
_g: '(refreshInterval:(pause:!t,value:0),time:(from:now-1h,to:now))',
type: 'metrics',
},
});
});

test('createFilterFromOptions()', () => {
const customOptions = { ...options, groupBy: 'host.name' };
const customSeries = { ...series, id: 'test"foo' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ import { SourceQuery } from '../../../../../graphql/types';
import { createMetricLabel } from './create_metric_label';
import { LinkDescriptor } from '../../../../../hooks/use_link_props';

/*
We've recently changed the default index pattern in Metrics UI from `metricbeat-*` to
`metrics-*,metricbeat-*`. There is a bug in TSVB when there is an empty index in the pattern
the field dropdowns are not populated correctly. This index pattern is a temporary fix.
See: https://github.com/elastic/kibana/issues/73987
*/
const TSVB_WORKAROUND_INDEX_PATTERN = 'metric*';

export const metricsExplorerMetricToTSVBMetric = (metric: MetricsExplorerOptionsMetric) => {
if (metric.aggregation === 'rate') {
const metricId = uuid.v1();
Expand Down Expand Up @@ -128,13 +136,23 @@ export const createFilterFromOptions = (
return { language: 'kuery', query: filters.join(' and ') };
};

const createTSVBIndexPattern = (alias: string) => {
if (alias.split(',').length > 1) {
return TSVB_WORKAROUND_INDEX_PATTERN;
}
return alias;
};

export const createTSVBLink = (
source: SourceQuery.Query['source']['configuration'] | undefined,
options: MetricsExplorerOptions,
series: MetricsExplorerSeries,
timeRange: MetricsExplorerTimeOptions,
chartOptions: MetricsExplorerChartOptions
): LinkDescriptor => {
const tsvbIndexPattern = createTSVBIndexPattern(
(source && source.metricAlias) || TSVB_WORKAROUND_INDEX_PATTERN
);
const appState = {
filters: [],
linked: false,
Expand All @@ -147,8 +165,8 @@ export const createTSVBLink = (
axis_position: 'left',
axis_scale: 'normal',
id: uuid.v1(),
default_index_pattern: (source && source.metricAlias) || 'metricbeat-*',
index_pattern: (source && source.metricAlias) || 'metricbeat-*',
default_index_pattern: tsvbIndexPattern,
index_pattern: tsvbIndexPattern,
interval: 'auto',
series: options.metrics.map(mapMetricToSeries(chartOptions)),
show_grid: 1,
Expand Down

0 comments on commit 6fa39eb

Please sign in to comment.