Skip to content

Commit

Permalink
Merge branch 'main' into fix/120387
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jan 4, 2022
2 parents c4c4fdb + 348bfb8 commit 5a081c0
Show file tree
Hide file tree
Showing 39 changed files with 214 additions and 23,709 deletions.
2 changes: 1 addition & 1 deletion src/dev/storybook/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const storybookAliases = {
expression_shape: 'src/plugins/expression_shape/.storybook',
expression_tagcloud: 'src/plugins/chart_expressions/expression_tagcloud/.storybook',
expression_metric_vis: 'src/plugins/chart_expressions/expression_metric/.storybook',
fleet: 'x-pack/plugins/fleet/storybook',
fleet: 'x-pack/plugins/fleet/.storybook',
infra: 'x-pack/plugins/infra/.storybook',
security_solution: 'x-pack/plugins/security_solution/.storybook',
ui_actions_enhanced: 'x-pack/plugins/ui_actions_enhanced/.storybook',
Expand Down
41 changes: 40 additions & 1 deletion src/plugins/vis_types/xy/public/config/get_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

import { getConfig } from './get_config';
import { visData, visParamsWithTwoYAxes } from '../mocks';
import { visData, visDataPercentile, visParamsWithTwoYAxes } from '../mocks';
import { VisParams } from '../types';

// ToDo: add more tests for all the config properties
describe('getConfig', () => {
Expand Down Expand Up @@ -65,4 +66,42 @@ describe('getConfig', () => {
const config = getConfig(visData, newVisParams);
expect(config.yAxes.length).toBe(1);
});

it('assigns the correct number of yAxes if the agg is Percentile', () => {
const newVisParams = {
...visParamsWithTwoYAxes,
seriesParams: [
{
type: 'line',
data: {
label: 'Percentiles of bytes',
id: '1',
},
drawLinesBetweenPoints: true,
interpolate: 'linear',
lineWidth: 2,
mode: 'normal',
show: true,
showCircles: true,
circlesRadius: 3,
valueAxis: 'ValueAxis-1',
},
],
dimensions: {
...visParamsWithTwoYAxes.dimensions,
y: ['1st', '5th', '25th', '50th', '75th', '95th', '99th'].map((prefix, accessor) => ({
label: `${prefix} percentile of bytes`,
aggType: 'percentiles',
params: {},
accessor,
format: {
id: 'number',
params: {},
},
})),
},
} as VisParams;
const config = getConfig(visDataPercentile, newVisParams);
expect(config.yAxes.length).toBe(1);
});
});
9 changes: 7 additions & 2 deletions src/plugins/vis_types/xy/public/config/get_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { getLegend } from './get_legend';
import { getAxis } from './get_axis';
import { getAspects } from './get_aspects';
import { ChartType } from '../index';
import { getSafeId } from '../utils/accessors';

export function getConfig(
table: Datatable,
Expand All @@ -51,13 +52,17 @@ export function getConfig(

const yAxes: Array<AxisConfig<ScaleContinuousType>> = [];

// avoid duplicates based on aggId
const aspectVisited = new Set();
params.dimensions.y.forEach((y) => {
const accessor = y.accessor;
const aspect = aspects.y.find(({ column }) => column === accessor);
const serie = params.seriesParams.find(({ data: { id } }) => id === aspect?.aggId);
const aggId = getSafeId(aspect?.aggId);
const serie = params.seriesParams.find(({ data: { id } }) => id === aggId);
const valueAxis = params.valueAxes.find(({ id }) => id === serie?.valueAxis);
if (aspect && valueAxis) {
if (aspect && valueAxis && !aspectVisited.has(aggId)) {
yAxes.push(getAxis<YScaleType>(valueAxis, params.grid, aspect, params.seriesParams));
aspectVisited.add(aggId);
}
});

Expand Down
80 changes: 80 additions & 0 deletions src/plugins/vis_types/xy/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,86 @@ export const visData = {
],
} as Datatable;

export const visDataPercentile = {
type: 'datatable',
columns: [
{
id: 'col-0-1.1',
name: '1st percentile of bytes',
meta: {
type: 'number',
field: 'bytes',
index: 'kibana_sample_data_logs',
},
},
{
id: 'col-1-1.5',
name: '5th percentile of bytes',
meta: {
type: 'number',
field: 'bytes',
index: 'kibana_sample_data_logs',
},
},
{
id: 'col-2-1.25',
name: '25th percentile of bytes',
meta: {
type: 'number',
field: 'bytes',
index: 'kibana_sample_data_logs',
},
},
{
id: 'col-3-1.50',
name: '50th percentile of bytes',
meta: {
type: 'number',
field: 'bytes',
index: 'kibana_sample_data_logs',
},
},
{
id: 'col-4-1.75',
name: '75th percentile of bytes',
meta: {
type: 'number',
field: 'bytes',
index: 'kibana_sample_data_logs',
},
},
{
id: 'col-5-1.95',
name: '95th percentile of bytes',
meta: {
type: 'number',
field: 'bytes',
index: 'kibana_sample_data_logs',
},
},
{
id: 'col-6-1.99',
name: '99th percentile of bytes',
meta: {
type: 'number',
field: 'bytes',
index: 'kibana_sample_data_logs',
},
},
],
rows: [
{
'col-0-1.1': 0,
'col-1-1.5': 0,
'col-2-1.25': 1741.5,
'col-3-1.50': 4677,
'col-4-1.75': 5681.5,
'col-5-1.95': 6816,
'col-6-1.99': 6816,
},
],
} as Datatable;

export const visParamsWithTwoYAxes = {
type: 'histogram',
addLegend: true,
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/vis_types/xy/public/utils/accessors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ export const getSplitSeriesAccessorFnMap = (
};

// For percentile, the aggregation id is coming in the form %s.%d, where %s is agg_id and %d - percents
export const isPercentileIdEqualToSeriesId = (columnId: number | string, seriesColumnId: string) =>
columnId.toString().split('.')[0] === seriesColumnId;
export const getSafeId = (columnId?: number | string | null) =>
(columnId || '').toString().split('.')[0];

export const isPercentileIdEqualToSeriesId = (
columnId: number | string | null | undefined,
seriesColumnId: string
) => getSafeId(columnId) === seriesColumnId;

export const isValidSeriesForDimension = (seriesColumnId: string, { aggId, accessor }: Aspect) =>
(aggId === seriesColumnId || isPercentileIdEqualToSeriesId(aggId ?? '', seriesColumnId)) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
* 2.0.
*/

import { defaultConfigWebFinal } from '@kbn/storybook';
import { defaultConfig } from '@kbn/storybook';

module.exports = {
...defaultConfigWebFinal,
addons: ['@storybook/addon-essentials'],
babel: () => ({
presets: [require.resolve('@kbn/babel-preset/webpack_preset')],
}),
};
module.exports = defaultConfig;
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
},
"include": [
// add all the folders containg files to be compiled
".storybook/**/*",
"common/**/*",
"public/**/*",
"server/**/*",
"server/**/*.json",
"scripts/**/*",
"package.json",
"storybook/**/*",
"../../../typings/**/*"
],
"references": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function hasStandaloneClusters(req: LegacyRequest, indexPatterns: s
},
{
terms: {
'metricset.name': ['logstash_stats', 'logstash_state', 'beats_stats', 'beats_state'],
'event.dataset': ['logstash.node.stats', 'logstash.node', 'beat.stats', 'beat.state'],
},
},
],
Expand Down
23 changes: 23 additions & 0 deletions x-pack/test/functional/apps/monitoring/cluster/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ export default function ({ getService, getPageObjects }) {
});
});

describe('with standalone cluster', () => {
const { setup, tearDown } = getLifecycleMethods(getService, getPageObjects);

before(async () => {
await setup('x-pack/test/functional/es_archives/monitoring/standalone_cluster', {
from: 'Feb 4, 2019 @ 17:50:00.000',
to: 'Feb 4, 2019 @ 17:52:00.000',
});

await clusterList.closeAlertsModal();
await clusterList.assertDefaults();
});

after(async () => {
await tearDown();
});

it('displays a standalone cluster', async () => {
expect(await clusterList.hasCluster('__standalone_cluster__')).to.be(true);
expect(await clusterList.hasCluster('lfhHkgqfTy2Vy3SvlPSvXg')).to.be(true);
});
});

describe('with all basic license clusters', () => {
const { setup, tearDown } = getLifecycleMethods(getService, getPageObjects);

Expand Down
39 changes: 39 additions & 0 deletions x-pack/test/functional/apps/monitoring/cluster/list_mb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { getLifecycleMethods } from '../_get_lifecycle_methods';

export default function ({ getService, getPageObjects }) {
const clusterList = getService('monitoringClusterList');

describe('Cluster listing mb', () => {
describe('with standalone cluster', () => {
const { setup, tearDown } = getLifecycleMethods(getService, getPageObjects);

before(async () => {
await setup('x-pack/test/functional/es_archives/monitoring/standalone_cluster_mb', {
from: 'Feb 4, 2019 @ 17:50:00.000',
to: 'Feb 4, 2019 @ 17:52:00.000',
useCreate: true,
});

await clusterList.closeAlertsModal();
await clusterList.assertDefaults();
});

after(async () => {
await tearDown();
});

it('displays a standalone cluster', async () => {
expect(await clusterList.hasCluster('__standalone_cluster__')).to.be(true);
expect(await clusterList.hasCluster('lfhHkgqfTy2Vy3SvlPSvXg')).to.be(true);
});
});
});
}
1 change: 1 addition & 0 deletions x-pack/test/functional/apps/monitoring/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function ({ loadTestFile }) {
loadTestFile(require.resolve('./feature_controls'));

loadTestFile(require.resolve('./cluster/list'));
loadTestFile(require.resolve('./cluster/list_mb'));
loadTestFile(require.resolve('./cluster/overview'));
// loadTestFile(require.resolve('./cluster/license'));

Expand Down
Binary file not shown.
Loading

0 comments on commit 5a081c0

Please sign in to comment.