Skip to content

Commit

Permalink
Merge branch 'main' into feature/140204-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 authored Sep 28, 2022
2 parents 9e3997f + 6ae4764 commit 5030879
Show file tree
Hide file tree
Showing 227 changed files with 6,187 additions and 680 deletions.
7 changes: 7 additions & 0 deletions docs/user/alerting/alerting-setup.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ user without those privileges updates the rule, the rule will no longer
function. Conversely, if a user with greater or administrator privileges
modifies the rule, it will begin running with increased privileges.
==============================================

[float]
[[alerting-ccs-setup]]
=== {ccs-cap}

If you want to use alerting rules with {ccs}, you must configure
{ref}/remote-clusters-privileges.html#clusters-privileges-ccs-kibana[privileges for {ccs-init} and {kib}].
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('convertTSVBtoLensConfiguration', () => {
test('should return null for a not supported chart', async () => {
const metricModel = {
...model,
type: 'metric',
type: 'markdown',
} as Panel;
const triggerOptions = await convertTSVBtoLensConfiguration(metricModel);
expect(triggerOptions).toBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const getConvertFnByType = (type: PANEL_TYPES) => {
const { convertToLens } = await import('./top_n');
return convertToLens;
},
[PANEL_TYPES.METRIC]: async () => {
const { convertToLens } = await import('./metric');
return convertToLens;
},
};

return convertionFns[type]?.();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { MetricVisConfiguration } from '@kbn/visualizations-plugin/common';
import { Metric, Panel, Series } from '../../../../../common/types';
import { Column, Layer } from '../../convert';
import { getSeriesAgg } from '../../series';
import { getPalette } from './palette';

const getMetricWithCollapseFn = (series: Series | undefined) => {
if (!series) {
return;
}
const { metrics, seriesAgg } = getSeriesAgg(series.metrics);
const visibleMetric = metrics[metrics.length - 1];
return { metric: visibleMetric, collapseFn: seriesAgg };
};

const findMetricColumn = (metric: Metric | undefined, columns: Column[]) => {
if (!metric) {
return;
}

return columns.find((column) => 'meta' in column && column.meta.metricId === metric.id);
};

export const getConfigurationForMetric = (
model: Panel,
layer: Layer,
bucket?: Column
): MetricVisConfiguration | null => {
const [primarySeries, secondarySeries] = model.series.filter(({ hidden }) => !hidden);

const primaryMetricWithCollapseFn = getMetricWithCollapseFn(primarySeries);

if (!primaryMetricWithCollapseFn || !primaryMetricWithCollapseFn.metric) {
return null;
}

const secondaryMetricWithCollapseFn = getMetricWithCollapseFn(secondarySeries);
const primaryColumn = findMetricColumn(primaryMetricWithCollapseFn.metric, layer.columns);
const secondaryColumn = findMetricColumn(secondaryMetricWithCollapseFn?.metric, layer.columns);

if (primaryMetricWithCollapseFn.collapseFn && secondaryMetricWithCollapseFn?.collapseFn) {
return null;
}

const palette = getPalette(model.background_color_rules ?? []);
if (palette === null) {
return null;
}

return {
layerId: layer.layerId,
layerType: 'data',
metricAccessor: primaryColumn?.columnId,
secondaryMetricAccessor: secondaryColumn?.columnId,
breakdownByAccessor: bucket?.columnId,
palette,
collapseFn: primaryMetricWithCollapseFn.collapseFn ?? secondaryMetricWithCollapseFn?.collapseFn,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { getPalette } from './palette';

describe('getPalette', () => {
const invalidRules = [
{ id: 'some-id-0' },
{ id: 'some-id-1', value: 10 },
{ id: 'some-id-2', operator: 'gte' },
{ id: 'some-id-3', color: '#000' },
{ id: 'some-id-4', background_color: '#000' },
];
test('should return undefined if no filled rules was provided', () => {
expect(getPalette([])).toBeUndefined();
expect(getPalette(invalidRules)).toBeUndefined();
});

test('should return undefined if only one valid rule is provided and it is not lte', () => {
expect(getPalette([])).toBeUndefined();
expect(
getPalette([
...invalidRules,
{ id: 'some-id-5', operator: 'gt', value: 100, background_color: '#000' },
])
).toBeUndefined();
});

test('should return custom palette if only one valid rule is provided and it is lte', () => {
expect(getPalette([])).toBeUndefined();
expect(
getPalette([
...invalidRules,
{ id: 'some-id-5', operator: 'lte', value: 100, background_color: '#000' },
])
).toEqual({
name: 'custom',
params: {
colorStops: [{ color: '#000000', stop: 100 }],
continuity: 'below',
maxSteps: 5,
name: 'custom',
progression: 'fixed',
rangeMax: 100,
rangeMin: -Infinity,
rangeType: 'number',
reverse: false,
steps: 1,
stops: [{ color: '#000000', stop: 100 }],
},
type: 'palette',
});
});

test('should return undefined if more than two types of rules', () => {
expect(getPalette([])).toBeUndefined();
expect(
getPalette([
...invalidRules,
{ id: 'some-id-5', operator: 'lte', value: 100, background_color: '#000' },
{ id: 'some-id-6', operator: 'gte', value: 150, background_color: '#000' },
{ id: 'some-id-7', operator: 'lt', value: 200, background_color: '#000' },
])
).toBeUndefined();
});

test('should return undefined if two types of rules and last rule is not lte', () => {
expect(getPalette([])).toBeUndefined();
expect(
getPalette([
...invalidRules,
{ id: 'some-id-5', operator: 'gte', value: 100, background_color: '#000' },
{ id: 'some-id-7', operator: 'lt', value: 200, background_color: '#000' },
{ id: 'some-id-6', operator: 'gte', value: 150, background_color: '#000' },
])
).toBeUndefined();
});

test('should return undefined if all rules are lte', () => {
expect(getPalette([])).toBeUndefined();
expect(
getPalette([
...invalidRules,
{ id: 'some-id-5', operator: 'lte', value: 100, background_color: '#000' },
{ id: 'some-id-7', operator: 'lte', value: 200, background_color: '#000' },
{ id: 'some-id-6', operator: 'lte', value: 150, background_color: '#000' },
])
).toBeUndefined();
});

test('should return undefined if two types of rules and all except last one are lt and last one is not lte', () => {
expect(getPalette([])).toBeUndefined();
expect(
getPalette([
...invalidRules,
{ id: 'some-id-5', operator: 'lt', value: 100, background_color: '#000' },
{ id: 'some-id-7', operator: 'gte', value: 200, background_color: '#000' },
{ id: 'some-id-6', operator: 'lt', value: 150, background_color: '#000' },
])
).toBeUndefined();
});

test('should return custom palette if two types of rules and all except last one is lt and last one is lte', () => {
expect(getPalette([])).toBeUndefined();
expect(
getPalette([
...invalidRules,
{ id: 'some-id-5', operator: 'lt', value: 100, background_color: '#000' },
{ id: 'some-id-7', operator: 'lte', value: 200, background_color: '#000' },
{ id: 'some-id-6', operator: 'lt', value: 150, background_color: '#000' },
])
).toEqual({
name: 'custom',
params: {
colorStops: [
{ color: '#000000', stop: -Infinity },
{ color: '#000000', stop: 100 },
{ color: '#000000', stop: 150 },
],
continuity: 'below',
maxSteps: 5,
name: 'custom',
progression: 'fixed',
rangeMax: 200,
rangeMin: -Infinity,
rangeType: 'number',
reverse: false,
steps: 4,
stops: [
{ color: '#000000', stop: 100 },
{ color: '#000000', stop: 150 },
{ color: '#000000', stop: 200 },
],
},
type: 'palette',
});
});

test('should return custom palette if last one is lte and all previous are gte', () => {
expect(getPalette([])).toBeUndefined();
expect(
getPalette([
...invalidRules,
{ id: 'some-id-5', operator: 'gte', value: 100, background_color: '#000' },
{ id: 'some-id-7', operator: 'lte', value: 200, background_color: '#000' },
{ id: 'some-id-6', operator: 'gte', value: 150, background_color: '#000' },
])
).toEqual({
name: 'custom',
params: {
colorStops: [
{ color: '#000000', stop: 100 },
{ color: '#000000', stop: 150 },
],
continuity: 'none',
maxSteps: 5,
name: 'custom',
progression: 'fixed',
rangeMax: 200,
rangeMin: 100,
rangeType: 'number',
reverse: false,
steps: 2,
stops: [
{ color: '#000000', stop: 150 },
{ color: '#000000', stop: 200 },
],
},
type: 'palette',
});
});
});
Loading

0 comments on commit 5030879

Please sign in to comment.