Skip to content

Commit

Permalink
[ObsUX] [APM] Migrate APM from styled-components to @emotion (#204222)
Browse files Browse the repository at this point in the history
Closes #202765

### Summary
While working on the visual refresh for the new EUI theme Borealis we
figured that was a good time to do the recommended migration from
`styled-components` to `@emotion`

### What has been done

- Migrate apm plugin from `styled-components` to `@emotion`
- Eui Visual Refresh for Borealis new theme
- All usage of color palette tokens and functions now pull from the
theme, and correctly update to use new colors when the theme changes
from Borealis to Amsterdam and vice versa
- All references to renamed tokens have been updated to use the new
token name
- Remove usage of deprecated `useEuiBackgroundColor`
- All usages of "success" colors have been updated to `accentSecondary`
and `textAccentSecondary` as needed

### Not this time

There are some color values on the server side, and the values are
static they would not update properly as dynamic tokens do. Eui guidance
right now is to keep these as they are for now (meaning to keep using
the JSON tokens).

### How to test
#### Running Kibana with the Borealis theme
In order to run Kibana with Borealis, you'll need to do the following:

- Set the following in kibana.dev.yml:
uiSettings.experimental.themeSwitcherEnabled: true
- Run Kibana with the following environment variable set:
KBN_OPTIMIZER_THEMES="borealislight,borealisdark,v8light,v8dark" yarn
start
- This will expose a toggle under Stack Management > Advanced Settings >
Theme version, which you can use to toggle between Amsterdam and
Borealis.
  • Loading branch information
MiriamAparicio authored Dec 18, 2024
1 parent 639143a commit fb0cb57
Show file tree
Hide file tree
Showing 122 changed files with 866 additions and 959 deletions.
4 changes: 2 additions & 2 deletions packages/kbn-babel-preset/styled_components_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = {
/packages[\/\\]kbn-ui-shared-deps-(npm|src)[\/\\]/,
/src[\/\\]plugins[\/\\](kibana_react)[\/\\]/,
/x-pack[\/\\]solutions[\/\\]observability[\/\\]plugins[\/\\](exploratory_view|investigate|investigate_app|observability|observability_ai_assistant_app|observability_ai_assistant_management|observability_solution|serverless_observability|streams|streams_app|synthetics|uptime|ux)[\/\\]/,
/x-pack[\/\\]plugins[\/\\](observability_solution\/apm|beats_management|fleet|observability_solution\/observability|observability_solution\/observability_shared|observability_solution\/exploratory_view|security_solution|timelines|observability_solution\/synthetics|observability_solution\/ux|observability_solution\/uptime)[\/\\]/,
/x-pack[\/\\]solutions[\/\\]security[\/\\]plugins[\/\\](observability_solution\/apm|beats_management|fleet|observability_solution\/infra|lists|observability_solution\/observability|observability_solution\/observability_shared|observability_solution\/exploratory_view|security_solution|timelines|observability_solution\/synthetics|observability_solution\/ux|observability_solution\/uptime)[\/\\]/,
/x-pack[\/\\]plugins[\/\\](beats_management|fleet|observability_solution\/observability|observability_solution\/observability_shared|observability_solution\/exploratory_view|security_solution|timelines|observability_solution\/synthetics|observability_solution\/ux|observability_solution\/uptime)[\/\\]/,
/x-pack[\/\\]solutions[\/\\]security[\/\\]plugins[\/\\](beats_management|fleet|lists|observability_solution\/observability|observability_solution\/observability_shared|observability_solution\/exploratory_view|security_solution|timelines|observability_solution\/synthetics|observability_solution\/ux|observability_solution\/uptime)[\/\\]/,
/x-pack[\/\\]test[\/\\]plugin_functional[\/\\]plugins[\/\\]resolver_test[\/\\]/,
/x-pack[\/\\]packages[\/\\]elastic_assistant[\/\\]/,
/x-pack[\/\\]solutions[\/\\]security[\/\\]packages[\/\\]ecs_data_quality_dashboard[\/\\]/,
Expand Down
1 change: 1 addition & 0 deletions x-pack/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/test/reporting/configs/failure_debug/
/plugins/reporting/.chromium/
/platform/plugins/shared/screenshotting/chromium/
/plugins/screenshotting/chromium/
/plugins/reporting/.phantom/
/.aws-config.json
/.env
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import { EuiTheme } from '@kbn/kibana-react-plugin/common';
import type { EuiThemeComputed } from '@elastic/eui';
import { ML_ANOMALY_SEVERITY } from '@kbn/ml-anomaly-utils/anomaly_severity';

export enum ServiceHealthStatus {
Expand Down Expand Up @@ -34,29 +34,35 @@ export function getServiceHealthStatus({ severity }: { severity: ML_ANOMALY_SEVE
}
}

export function getServiceHealthStatusColor(theme: EuiTheme, status: ServiceHealthStatus) {
export function getServiceHealthStatusColor(
euiTheme: EuiThemeComputed,
status: ServiceHealthStatus
) {
switch (status) {
case ServiceHealthStatus.healthy:
return theme.eui.euiColorVis0;
return euiTheme.colors.success;
case ServiceHealthStatus.warning:
return theme.eui.euiColorVis5;
return euiTheme.colors.warning;
case ServiceHealthStatus.critical:
return theme.eui.euiColorVis9;
return euiTheme.colors.danger;
case ServiceHealthStatus.unknown:
return theme.eui.euiColorMediumShade;
return euiTheme.colors.mediumShade;
}
}

export function getServiceHealthStatusBadgeColor(theme: EuiTheme, status: ServiceHealthStatus) {
export function getServiceHealthStatusBadgeColor(
euiTheme: EuiThemeComputed,
status: ServiceHealthStatus
) {
switch (status) {
case ServiceHealthStatus.healthy:
return theme.eui.euiColorVis0_behindText;
return euiTheme.colors.success;
case ServiceHealthStatus.warning:
return theme.eui.euiColorVis5_behindText;
return euiTheme.colors.warning;
case ServiceHealthStatus.critical:
return theme.eui.euiColorVis9_behindText;
return euiTheme.colors.danger;
case ServiceHealthStatus.unknown:
return theme.eui.euiColorMediumShade;
return euiTheme.colors.mediumShade;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {
GetApmTimeseriesFunctionResponse,
} from '../../server/assistant_functions/get_apm_timeseries';
import { Coordinate, TimeSeries } from '../../typings/timeseries';
import { ApmThemeProvider } from '../components/routing/app_root';
import {
ChartType,
getTimeSeriesColor,
Expand Down Expand Up @@ -54,101 +53,99 @@ export function registerGetApmTimeseriesFunction({

return (
<ChartPointerEventContextProvider>
<ApmThemeProvider>
<EuiFlexGroup direction="column">
{Object.values(groupedSeries).map((groupSeries) => {
const groupId = groupSeries[0].group;

const maxY = getMaxY(groupSeries);
const latencyFormatter = getDurationFormatter(maxY, 10, 1000);

let yLabelFormat: (value: number) => string;

const firstStat = groupSeries[0].stat;

switch (firstStat.timeseries.name) {
case 'transaction_throughput':
case 'exit_span_throughput':
case 'error_event_rate':
yLabelFormat = asTransactionRate;
break;

case 'transaction_latency':
case 'exit_span_latency':
yLabelFormat = getResponseTimeTickFormatter(latencyFormatter);
break;

case 'transaction_failure_rate':
case 'exit_span_failure_rate':
yLabelFormat = (y) => asPercent(y || 0, 100);
break;
}

const timeseries: Array<TimeSeries<Coordinate>> = groupSeries.map(
(series): TimeSeries<Coordinate> => {
let chartType: ChartType;

const data = series.data;

switch (series.stat.timeseries.name) {
case 'transaction_throughput':
case 'exit_span_throughput':
chartType = ChartType.THROUGHPUT;
break;

case 'transaction_failure_rate':
case 'exit_span_failure_rate':
chartType = ChartType.FAILED_TRANSACTION_RATE;
break;

case 'transaction_latency':
if (series.stat.timeseries.function === LatencyAggregationType.p99) {
chartType = ChartType.LATENCY_P99;
} else if (series.stat.timeseries.function === LatencyAggregationType.p95) {
chartType = ChartType.LATENCY_P95;
} else {
chartType = ChartType.LATENCY_AVG;
}
break;

case 'exit_span_latency':
<EuiFlexGroup direction="column">
{Object.values(groupedSeries).map((groupSeries) => {
const groupId = groupSeries[0].group;

const maxY = getMaxY(groupSeries);
const latencyFormatter = getDurationFormatter(maxY, 10, 1000);

let yLabelFormat: (value: number) => string;

const firstStat = groupSeries[0].stat;

switch (firstStat.timeseries.name) {
case 'transaction_throughput':
case 'exit_span_throughput':
case 'error_event_rate':
yLabelFormat = asTransactionRate;
break;

case 'transaction_latency':
case 'exit_span_latency':
yLabelFormat = getResponseTimeTickFormatter(latencyFormatter);
break;

case 'transaction_failure_rate':
case 'exit_span_failure_rate':
yLabelFormat = (y) => asPercent(y || 0, 100);
break;
}

const timeseries: Array<TimeSeries<Coordinate>> = groupSeries.map(
(series): TimeSeries<Coordinate> => {
let chartType: ChartType;

const data = series.data;

switch (series.stat.timeseries.name) {
case 'transaction_throughput':
case 'exit_span_throughput':
chartType = ChartType.THROUGHPUT;
break;

case 'transaction_failure_rate':
case 'exit_span_failure_rate':
chartType = ChartType.FAILED_TRANSACTION_RATE;
break;

case 'transaction_latency':
if (series.stat.timeseries.function === LatencyAggregationType.p99) {
chartType = ChartType.LATENCY_P99;
} else if (series.stat.timeseries.function === LatencyAggregationType.p95) {
chartType = ChartType.LATENCY_P95;
} else {
chartType = ChartType.LATENCY_AVG;
break;

case 'error_event_rate':
chartType = ChartType.ERROR_OCCURRENCES;
break;
}

return {
title: series.id,
type: 'line',
color: getTimeSeriesColor(chartType!).currentPeriodColor,
data,
};
}
break;

case 'exit_span_latency':
chartType = ChartType.LATENCY_AVG;
break;

case 'error_event_rate':
chartType = ChartType.ERROR_OCCURRENCES;
break;
}
);

return (
<EuiFlexItem grow={false} key={groupId}>
<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexItem>
<EuiText size="m">{groupId}</EuiText>
<TimeseriesChart
comparisonEnabled={false}
fetchStatus={FETCH_STATUS.SUCCESS}
id={groupId}
timeZone={timeZone}
timeseries={timeseries}
yLabelFormat={yLabelFormat!}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
);
})}
</EuiFlexGroup>
</ApmThemeProvider>

return {
title: series.id,
type: 'line',
color: getTimeSeriesColor(chartType!).currentPeriodColor,
data,
};
}
);

return (
<EuiFlexItem grow={false} key={groupId}>
<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexItem>
<EuiText size="m">{groupId}</EuiText>
<TimeseriesChart
comparisonEnabled={false}
fetchStatus={FETCH_STATUS.SUCCESS}
id={groupId}
timeZone={timeZone}
timeseries={timeseries}
yLabelFormat={yLabelFormat!}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
);
})}
</EuiFlexGroup>
</ChartPointerEventContextProvider>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
Axis,
BarSeries,
Chart,
LIGHT_THEME,
DARK_THEME,
LineAnnotation,
Position,
RectAnnotation,
Expand All @@ -20,15 +22,14 @@ import {
Tooltip,
niceTimeFormatter,
} from '@elastic/charts';
import { EuiSpacer } from '@elastic/eui';
import { COLOR_MODES_STANDARD, EuiSpacer, useEuiTheme } from '@elastic/eui';
import React, { useMemo } from 'react';
import { IUiSettingsClient } from '@kbn/core/public';
import { TimeUnitChar } from '@kbn/observability-plugin/common';
import { UI_SETTINGS } from '@kbn/data-plugin/public';
import moment from 'moment';
import { i18n } from '@kbn/i18n';
import { Coordinate } from '../../../../../typings/timeseries';
import { useTheme } from '../../../../hooks/use_theme';
import { getTimeZone } from '../../../shared/charts/helper/timezone';
import { TimeLabelForData, TIME_LABELS, getDomain } from './chart_preview_helper';
import { ALERT_PREVIEW_BUCKET_SIZE } from '../../utils/helper';
Expand All @@ -52,15 +53,15 @@ export function ChartPreview({
timeUnit = 'm',
totalGroups,
}: ChartPreviewProps) {
const theme = useTheme();
const theme = useEuiTheme();
const thresholdOpacity = 0.3;
const DEFAULT_DATE_FORMAT = 'Y-MM-DD HH:mm:ss';

const style = {
fill: theme.eui.euiColorVis2,
fill: theme.euiTheme.colors.vis.euiColorVis2,
line: {
strokeWidth: 2,
stroke: theme.eui.euiColorVis2,
stroke: theme.euiTheme.colors.vis.euiColorVis2,
opacity: 1,
},
opacity: thresholdOpacity,
Expand Down Expand Up @@ -121,6 +122,7 @@ export function ChartPreview({
legendPosition={'bottom'}
legendSize={legendSize}
locale={i18n.getLocale()}
theme={theme.colorMode === COLOR_MODES_STANDARD.dark ? DARK_THEME : LIGHT_THEME}
/>
<LineAnnotation
dataValues={[{ dataValue: threshold }]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { EuiButtonIcon, EuiToolTip } from '@elastic/eui';
import { EuiButtonIcon, EuiToolTip, useEuiTheme } from '@elastic/eui';
import React, { useCallback, useMemo, useState } from 'react';
import { i18n } from '@kbn/i18n';
import {
Expand All @@ -29,6 +29,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
import numeral from '@elastic/numeral';
import { css } from '@emotion/react';
import { termQuery } from '../../../../../common/utils/term_query';
import {
SERVICE_NAME,
Expand All @@ -40,7 +41,6 @@ import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plug
import { useFetchParams } from '../use_fetch_params';
import type { ApmPluginStartDeps } from '../../../../plugin';
import { useAdHocApmDataView } from '../../../../hooks/use_adhoc_apm_data_view';
import { useTheme } from '../../../../hooks/use_theme';
import { FETCH_STATUS, useFetcher } from '../../../../hooks/use_fetcher';

const HIGHLIGHTED_BUCKET_PROPS = {
Expand Down Expand Up @@ -205,7 +205,7 @@ export function FieldStatsPopover({
const field = dataView?.getFieldByName(fieldName);

const closePopover = useCallback(() => setInfoOpen(false), []);
const theme = useTheme();
const { euiTheme } = useEuiTheme();

const params = useFetchParams();

Expand Down Expand Up @@ -280,7 +280,9 @@ export function FieldStatsPopover({
}
)}
data-test-subj={'apmCorrelationsContextPopoverButton'}
style={{ marginLeft: theme.eui.euiSizeXS }}
css={css`
margin-left: ${euiTheme.size.xs};
`}
/>
</EuiToolTip>
);
Expand Down
Loading

0 comments on commit fb0cb57

Please sign in to comment.