Skip to content

Commit

Permalink
[ML] Add option to show overlay chart to Data drift expanded row (#17…
Browse files Browse the repository at this point in the history
…2239)

## Summary

This PR adds overlay chart as an option to data drift table's expanded
row


https://github.com/elastic/kibana/assets/43350163/c632a913-b998-46fa-b2d4-5f513b1b4da2

This setting is saved in the browser and remain same until changed.
Changing option for one will also change for all other rows.


### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
qn895 and kibanamachine authored Dec 4, 2023
1 parent f044bcc commit 7d3cbd2
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,65 @@
* 2.0.
*/

import { Axis, BarSeries, Chart, Tooltip, Position, ScaleType, Settings } from '@elastic/charts';
import {
Axis,
BarSeries,
Chart,
Tooltip,
Position,
ScaleType,
Settings,
AreaSeries,
CurveType,
} from '@elastic/charts';
import React from 'react';
import { FIELD_FORMAT_IDS } from '@kbn/field-formats-plugin/common';
import { i18n } from '@kbn/i18n';
import { useStorage } from '@kbn/ml-local-storage';
import { EuiButtonGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui';
import { NoChartsData } from './no_charts_data';
import type { Feature } from '../types';
import { COMPARISON_LABEL, DATA_COMPARISON_TYPE } from '../constants';
import { COMPARISON_LABEL, DATA_COMPARISON_TYPE, REFERENCE_LABEL } from '../constants';
import { DataComparisonChartTooltipBody } from '../data_drift_chart_tooltip_body';
import { getFieldFormatType, useFieldFormatter } from './default_value_formatter';
import {
DVKey,
DVStorageMapped,
DV_DATA_DRIFT_DISTRIBUTION_CHART_TYPE,
} from '../../index_data_visualizer/types/storage';
import { DATA_DRIFT_COMPARISON_CHART_TYPE } from '../../index_data_visualizer/types/data_drift';
import { useCurrentEuiTheme } from '../../common/hooks/use_current_eui_theme';

const CHART_HEIGHT = 200;

const showAsAreaChartOption = i18n.translate(
'xpack.dataVisualizer.dataDrift.showAsAreaChartOptionLabel',
{ defaultMessage: 'Show as area chart' }
);

const showAsBarChartOption = i18n.translate(
'xpack.dataVisualizer.dataDrift.showAsBarChartOptionLabel',
{ defaultMessage: 'Show as bar chart' }
);

const visualizeComparisonChartType = i18n.translate(
'xpack.dataVisualizer.dataDrift.visualizeComparisonTypeLabel',
{ defaultMessage: 'Visualize comparison type' }
);

const visualizeComparisonChartIcons = [
{
id: DATA_DRIFT_COMPARISON_CHART_TYPE.AREA,
label: showAsAreaChartOption,
iconType: 'visArea',
},
{
id: DATA_DRIFT_COMPARISON_CHART_TYPE.BAR,
label: showAsBarChartOption,
iconType: 'visBarVertical',
},
];

export const DataDriftDistributionChart = ({
item,
colors,
Expand All @@ -27,14 +74,38 @@ export const DataDriftDistributionChart = ({
secondaryType: string;
domain?: Feature['domain'];
}) => {
const euiTheme = useCurrentEuiTheme();

const xAxisFormatter = useFieldFormatter(getFieldFormatType(secondaryType));
const yAxisFormatter = useFieldFormatter(FIELD_FORMAT_IDS.NUMBER);
const [comparisonChartType, setComparisonChartType] = useStorage<
DVKey,
DVStorageMapped<typeof DV_DATA_DRIFT_DISTRIBUTION_CHART_TYPE>
>(
DV_DATA_DRIFT_DISTRIBUTION_CHART_TYPE,
// By default we will set default comparison chart in expanded row as area chart
DATA_DRIFT_COMPARISON_CHART_TYPE.AREA
);

if (!item || item.comparisonDistribution.length === 0) return <NoChartsData />;
const { featureName, fieldType, comparisonDistribution: data } = item;

return (
<div css={{ width: '100%', height: CHART_HEIGHT }}>
<div css={{ width: '100%', height: `calc(${CHART_HEIGHT}px + ${euiTheme.euiSize});` }}>
<EuiFlexItem grow={false}>
<EuiButtonGroup
legend={visualizeComparisonChartType}
options={visualizeComparisonChartIcons}
idSelected={comparisonChartType}
onChange={(id: string) =>
setComparisonChartType(
id as typeof DATA_DRIFT_COMPARISON_CHART_TYPE[keyof typeof DATA_DRIFT_COMPARISON_CHART_TYPE]
)
}
isIconOnly
/>
</EuiFlexItem>
<EuiSpacer size="s" />
<Chart>
<Tooltip body={DataComparisonChartTooltipBody} />
<Settings locale={i18n.getLocale()} />
Expand All @@ -50,22 +121,50 @@ export const DataDriftDistributionChart = ({
tickFormat={yAxisFormatter}
domain={{ min: 0, max: 1 }}
/>
<BarSeries
id="data-drift-viz"
name={featureName}
xScaleType={
fieldType === DATA_COMPARISON_TYPE.NUMERIC ? ScaleType.Linear : ScaleType.Ordinal
}
yScaleType={ScaleType.Linear}
xAccessor="key"
yAccessors={['percentage']}
splitSeriesAccessors={['g']}
data={data}
color={(identifier) => {
const key = identifier.seriesKeys[0];
return key === COMPARISON_LABEL ? colors.comparisonColor : colors.referenceColor;
}}
/>
{comparisonChartType === DATA_DRIFT_COMPARISON_CHART_TYPE.BAR ? (
<BarSeries
id="dataVisualizer.barDistributionComparisonChart"
name={featureName}
xScaleType={
fieldType === DATA_COMPARISON_TYPE.NUMERIC ? ScaleType.Linear : ScaleType.Ordinal
}
yScaleType={ScaleType.Linear}
xAccessor="key"
yAccessors={['percentage']}
splitSeriesAccessors={['g']}
data={data}
color={(identifier) => {
const key = identifier.seriesKeys[0];
return key === COMPARISON_LABEL ? colors.comparisonColor : colors.referenceColor;
}}
/>
) : (
<AreaSeries
id="dataVisualizer.overlapDistributionComparisonChart"
name={i18n.translate('xpack.dataVisualizer.dataDrift.distributionComparisonChartName', {
defaultMessage:
'Distribution comparison of {referenceLabel} and {comparisonLabel} data for {fieldName}',
values: {
referenceLabel: REFERENCE_LABEL.toLowerCase(),
comparisonLabel: COMPARISON_LABEL.toLowerCase(),
fieldName: featureName,
},
})}
xScaleType={
fieldType === DATA_COMPARISON_TYPE.NUMERIC ? ScaleType.Linear : ScaleType.Ordinal
}
yScaleType={ScaleType.Linear}
xAccessor="key"
yAccessors={['percentage']}
splitSeriesAccessors={['g']}
data={data}
curve={CurveType.CURVE_STEP}
color={(identifier) => {
const key = identifier.seriesKeys[0];
return key === COMPARISON_LABEL ? colors.comparisonColor : colors.referenceColor;
}}
/>
)}
</Chart>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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.
*/

export enum DATA_DRIFT_COMPARISON_CHART_TYPE {
BAR = 'bar',
AREA = 'area',
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
import { type FrozenTierPreference } from '@kbn/ml-date-picker';

import { type RandomSamplerOption } from '../constants/random_sampler';
import { DATA_DRIFT_COMPARISON_CHART_TYPE } from './data_drift';

export const DV_FROZEN_TIER_PREFERENCE = 'dataVisualizer.frozenDataTierPreference';
export const DV_RANDOM_SAMPLER_PREFERENCE = 'dataVisualizer.randomSamplerPreference';
export const DV_RANDOM_SAMPLER_P_VALUE = 'dataVisualizer.randomSamplerPValue';
export const DV_DATA_DRIFT_DISTRIBUTION_CHART_TYPE = 'dataVisualizer.dataDriftChartType';

export type DV = Partial<{
[DV_FROZEN_TIER_PREFERENCE]: FrozenTierPreference;
[DV_RANDOM_SAMPLER_PREFERENCE]: RandomSamplerOption;
[DV_RANDOM_SAMPLER_P_VALUE]: null | number;
[DV_DATA_DRIFT_DISTRIBUTION_CHART_TYPE]: DATA_DRIFT_COMPARISON_CHART_TYPE;
}> | null;

export type DVKey = keyof Exclude<DV, null>;
Expand All @@ -27,10 +30,13 @@ export type DVStorageMapped<T extends DVKey> = T extends typeof DV_FROZEN_TIER_P
? RandomSamplerOption | undefined
: T extends typeof DV_RANDOM_SAMPLER_P_VALUE
? number | null
: T extends typeof DV_DATA_DRIFT_DISTRIBUTION_CHART_TYPE
? DATA_DRIFT_COMPARISON_CHART_TYPE
: null;

export const DV_STORAGE_KEYS = [
DV_FROZEN_TIER_PREFERENCE,
DV_RANDOM_SAMPLER_PREFERENCE,
DV_RANDOM_SAMPLER_P_VALUE,
DV_DATA_DRIFT_DISTRIBUTION_CHART_TYPE,
] as const;
100 changes: 50 additions & 50 deletions x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -20272,55 +20272,6 @@
"xpack.infra.appName": "Logs Infra",
"xpack.infra.assetDetails.alerts.tooltip.documentationLink": "documentation",
"xpack.infra.assetDetails.flyout.AlertsPageLinkLabel": "Afficher tout",
"xpack.metricsData.assetDetails.formulas.cpuUsage": "Utilisation CPU",
"xpack.metricsData.assetDetails.formulas.cpuUsage.iowaitLabel": "iowait",
"xpack.metricsData.assetDetails.formulas.cpuUsage.irqLabel": "irq",
"xpack.metricsData.assetDetails.formulas.cpuUsage.niceLabel": "nice",
"xpack.metricsData.assetDetails.formulas.cpuUsage.softirqLabel": "softirq",
"xpack.metricsData.assetDetails.formulas.cpuUsage.stealLabel": "steal",
"xpack.metricsData.assetDetails.formulas.cpuUsage.systemLabel": "system",
"xpack.metricsData.assetDetails.formulas.cpuUsage.userLabel": "utilisateur",
"xpack.metricsData.assetDetails.formulas.diskIORead": "Entrées et sorties par seconde en lecture sur le disque",
"xpack.metricsData.assetDetails.formulas.diskIOWrite": "Entrées et sorties par seconde en écriture sur le disque",
"xpack.metricsData.assetDetails.formulas.diskReadThroughput": "Rendement de lecture du disque",
"xpack.metricsData.assetDetails.formulas.diskSpaceAvailability": "Disponibilité de l'espace disque",
"xpack.metricsData.assetDetails.formulas.diskSpaceAvailable": "Espace disque disponible",
"xpack.metricsData.assetDetails.formulas.diskUsage": "Utilisation du disque",
"xpack.metricsData.assetDetails.formulas.diskWriteThroughput": "Rendement d’écriture du disque",
"xpack.metricsData.assetDetails.formulas.hostCount.hostsLabel": "Hôtes",
"xpack.metricsData.assetDetails.formulas.kubernetes.capacity": "Capacité",
"xpack.metricsData.assetDetails.formulas.kubernetes.used": "Utilisé",
"xpack.metricsData.assetDetails.formulas.load15m": "Charge (15 min)",
"xpack.metricsData.assetDetails.formulas.load1m": "Charge (1 min)",
"xpack.metricsData.assetDetails.formulas.load5m": "Charge (5 min)",
"xpack.metricsData.assetDetails.formulas.logRate": "Taux de log",
"xpack.metricsData.assetDetails.formulas.memoryFree": "Sans mémoire",
"xpack.metricsData.assetDetails.formulas.memoryUsage": "Utilisation mémoire",
"xpack.metricsData.assetDetails.formulas.metric.label.cache": "cache",
"xpack.metricsData.assetDetails.formulas.metric.label.free": "gratuit",
"xpack.metricsData.assetDetails.formulas.metric.label.used": "utilisé",
"xpack.metricsData.assetDetails.formulas.normalizedLoad1m": "Charge normalisée",
"xpack.metricsData.assetDetails.formulas.rx": "Réseau entrant (RX)",
"xpack.metricsData.assetDetails.formulas.tx": "Réseau sortant (TX)",
"xpack.metricsData.assetDetails.metricsCharts.diskIOPS": "Entrées et sorties par seconde (IOPS) sur le disque",
"xpack.metricsData.assetDetails.metricsCharts.diskThroughput": "Rendement du disque",
"xpack.metricsData.assetDetails.metricsCharts.diskUsage.label.available": "Disponible",
"xpack.metricsData.assetDetails.metricsCharts.diskUsage.label.used": "Utilisé",
"xpack.metricsData.assetDetails.metricsCharts.diskUsageByMountingPoint": "Utilisation du disque par point de montage",
"xpack.metricsData.assetDetails.metricsCharts.kubernetes.nodeCpuCapacity": "Capacité CPU du nœud",
"xpack.metricsData.assetDetails.metricsCharts.load": "Charge",
"xpack.metricsData.assetDetails.metricsCharts.metric.label.cache": "Cache",
"xpack.metricsData.assetDetails.metricsCharts.metric.label.free": "Gratuit",
"xpack.metricsData.assetDetails.metricsCharts.metric.label.read": "Lire",
"xpack.metricsData.assetDetails.metricsCharts.metric.label.used": "Utilisé",
"xpack.metricsData.assetDetails.metricsCharts.metric.label.write": "Écrire",
"xpack.metricsData.assetDetails.metricsCharts.network": "Réseau",
"xpack.metricsData.assetDetails.metricsCharts.network.label.rx": "Entrant (RX)",
"xpack.metricsData.assetDetails.metricsCharts.network.label.tx": "Sortant (TX)",
"xpack.metricsData.assetDetails.metricsCharts.kubernetes.nodeDiskCapacity": "Capacité du disque du nœud",
"xpack.metricsData.assetDetails.metricsCharts.kubernetes.nodeMemoryCapacity": "Capacité de mémoire du nœud",
"xpack.metricsData.assetDetails.metricsCharts.kubernetes.nodePodCapacity": "Capacité de pod du nœud",
"xpack.metricsData.assetDetails.overview.kpi.subtitle.average": "Moyenne",
"xpack.infra.assetDetails.header.return": "Renvoyer",
"xpack.infra.assetDetails.metadata.tooltip.documentationLink": "host.name",
"xpack.infra.assetDetails.metadata.tooltip.metadata": "Métadonnées",
Expand Down Expand Up @@ -21199,6 +21150,55 @@
"xpack.infra.waffle.unableToSelectMetricErrorTitle": "Impossible de sélectionner les options ou la valeur pour l'indicateur.",
"xpack.infra.waffleTime.autoRefreshButtonLabel": "Actualisation automatique",
"xpack.infra.waffleTime.stopRefreshingButtonLabel": "Arrêter l'actualisation",
"xpack.metricsData.assetDetails.formulas.cpuUsage": "Utilisation CPU",
"xpack.metricsData.assetDetails.formulas.cpuUsage.iowaitLabel": "iowait",
"xpack.metricsData.assetDetails.formulas.cpuUsage.irqLabel": "irq",
"xpack.metricsData.assetDetails.formulas.cpuUsage.niceLabel": "nice",
"xpack.metricsData.assetDetails.formulas.cpuUsage.softirqLabel": "softirq",
"xpack.metricsData.assetDetails.formulas.cpuUsage.stealLabel": "steal",
"xpack.metricsData.assetDetails.formulas.cpuUsage.systemLabel": "system",
"xpack.metricsData.assetDetails.formulas.cpuUsage.userLabel": "utilisateur",
"xpack.metricsData.assetDetails.formulas.diskIORead": "Entrées et sorties par seconde en lecture sur le disque",
"xpack.metricsData.assetDetails.formulas.diskIOWrite": "Entrées et sorties par seconde en écriture sur le disque",
"xpack.metricsData.assetDetails.formulas.diskReadThroughput": "Rendement de lecture du disque",
"xpack.metricsData.assetDetails.formulas.diskSpaceAvailability": "Disponibilité de l'espace disque",
"xpack.metricsData.assetDetails.formulas.diskSpaceAvailable": "Espace disque disponible",
"xpack.metricsData.assetDetails.formulas.diskUsage": "Utilisation du disque",
"xpack.metricsData.assetDetails.formulas.diskWriteThroughput": "Rendement d’écriture du disque",
"xpack.metricsData.assetDetails.formulas.hostCount.hostsLabel": "Hôtes",
"xpack.metricsData.assetDetails.formulas.kubernetes.capacity": "Capacité",
"xpack.metricsData.assetDetails.formulas.kubernetes.used": "Utilisé",
"xpack.metricsData.assetDetails.formulas.load15m": "Charge (15 min)",
"xpack.metricsData.assetDetails.formulas.load1m": "Charge (1 min)",
"xpack.metricsData.assetDetails.formulas.load5m": "Charge (5 min)",
"xpack.metricsData.assetDetails.formulas.logRate": "Taux de log",
"xpack.metricsData.assetDetails.formulas.memoryFree": "Sans mémoire",
"xpack.metricsData.assetDetails.formulas.memoryUsage": "Utilisation mémoire",
"xpack.metricsData.assetDetails.formulas.metric.label.cache": "cache",
"xpack.metricsData.assetDetails.formulas.metric.label.free": "gratuit",
"xpack.metricsData.assetDetails.formulas.metric.label.used": "utilisé",
"xpack.metricsData.assetDetails.formulas.normalizedLoad1m": "Charge normalisée",
"xpack.metricsData.assetDetails.formulas.rx": "Réseau entrant (RX)",
"xpack.metricsData.assetDetails.formulas.tx": "Réseau sortant (TX)",
"xpack.metricsData.assetDetails.metricsCharts.diskIOPS": "Entrées et sorties par seconde (IOPS) sur le disque",
"xpack.metricsData.assetDetails.metricsCharts.diskThroughput": "Rendement du disque",
"xpack.metricsData.assetDetails.metricsCharts.diskUsage.label.available": "Disponible",
"xpack.metricsData.assetDetails.metricsCharts.diskUsage.label.used": "Utilisé",
"xpack.metricsData.assetDetails.metricsCharts.diskUsageByMountingPoint": "Utilisation du disque par point de montage",
"xpack.metricsData.assetDetails.metricsCharts.kubernetes.nodeCpuCapacity": "Capacité CPU du nœud",
"xpack.metricsData.assetDetails.metricsCharts.load": "Charge",
"xpack.metricsData.assetDetails.metricsCharts.metric.label.cache": "Cache",
"xpack.metricsData.assetDetails.metricsCharts.metric.label.free": "Gratuit",
"xpack.metricsData.assetDetails.metricsCharts.metric.label.read": "Lire",
"xpack.metricsData.assetDetails.metricsCharts.metric.label.used": "Utilisé",
"xpack.metricsData.assetDetails.metricsCharts.metric.label.write": "Écrire",
"xpack.metricsData.assetDetails.metricsCharts.network": "Réseau",
"xpack.metricsData.assetDetails.metricsCharts.network.label.rx": "Entrant (RX)",
"xpack.metricsData.assetDetails.metricsCharts.network.label.tx": "Sortant (TX)",
"xpack.metricsData.assetDetails.metricsCharts.kubernetes.nodeDiskCapacity": "Capacité du disque du nœud",
"xpack.metricsData.assetDetails.metricsCharts.kubernetes.nodeMemoryCapacity": "Capacité de mémoire du nœud",
"xpack.metricsData.assetDetails.metricsCharts.kubernetes.nodePodCapacity": "Capacité de pod du nœud",
"xpack.metricsData.assetDetails.overview.kpi.subtitle.average": "Moyenne",
"xpack.ingestPipelines.app.deniedPrivilegeDescription": "Pour utiliser l'option Ingérer des pipelines, vous devez avoir {privilegesCount, plural, one {ce privilège de cluster} many {ces privilèges de cluster} other {ces privilèges de cluster}} : {missingPrivileges}.",
"xpack.ingestPipelines.clone.loadSourcePipelineErrorTitle": "Impossible de charger {name}.",
"xpack.ingestPipelines.createFromCsv.errorMessage": "{message}",
Expand Down Expand Up @@ -43616,4 +43616,4 @@
"xpack.serverlessObservability.nav.projectSettings": "Paramètres de projet",
"xpack.serverlessObservability.nav.visualizations": "Visualisations"
}
}
}
Loading

0 comments on commit 7d3cbd2

Please sign in to comment.