Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ObsUX] [APM] Migrate APM from styled-components to @emotion #204222

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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|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[\/\\]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|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[\/\\]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)[\/\\]/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line has been messed up with the recent platform migration. I don't think there are observability plugins within security solutions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has been a source of conflicts since the start of the relocation of modules.
I've just created #204785 to cleanup / simplify the file and hopefully avoid more headaches.

/x-pack[\/\\]test[\/\\]plugin_functional[\/\\]plugins[\/\\]resolver_test[\/\\]/,
/x-pack[\/\\]packages[\/\\]elastic_assistant[\/\\]/,
/x-pack[\/\\]solutions[\/\\]security[\/\\]packages[\/\\]ecs_data_quality_dashboard[\/\\]/,
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.vis.euiColorVis0;
MiriamAparicio marked this conversation as resolved.
Show resolved Hide resolved
case ServiceHealthStatus.warning:
return theme.eui.euiColorVis5;
return euiTheme.colors.vis.euiColorVis5;
case ServiceHealthStatus.critical:
return theme.eui.euiColorVis9;
return euiTheme.colors.vis.euiColorVis9;
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.vis.euiColorVis0;
case ServiceHealthStatus.warning:
return theme.eui.euiColorVis5_behindText;
return euiTheme.colors.vis.euiColorVis5;
case ServiceHealthStatus.critical:
return theme.eui.euiColorVis9_behindText;
return euiTheme.colors.vis.euiColorVis9;
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 { 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 === 'DARK' ? DARK_THEME : LIGHT_THEME}
MiriamAparicio marked this conversation as resolved.
Show resolved Hide resolved
/>
<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`
marginleft: ${euiTheme.size.xs};
MiriamAparicio marked this conversation as resolved.
Show resolved Hide resolved
`}
/>
</EuiToolTip>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

import React, { useCallback, useMemo, useState } from 'react';
import { debounce } from 'lodash';
import { EuiBasicTable, EuiBasicTableColumn } from '@elastic/eui';
import { EuiBasicTable, EuiBasicTableColumn, useEuiTheme } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import type { EuiTableSortingType } from '@elastic/eui/src/components/basic_table/table_types';
import type { Criteria } from '@elastic/eui/src/components/basic_table/basic_table';
import { useUiTracker } from '@kbn/observability-shared-plugin/public';
import { FETCH_STATUS } from '../../../hooks/use_fetcher';
import { useTheme } from '../../../hooks/use_theme';
import type { FieldValuePair } from '../../../../common/correlations/types';

const PAGINATION_SIZE_OPTIONS = [5, 10, 20, 50];
Expand Down Expand Up @@ -43,7 +42,7 @@ export function CorrelationsTable<T extends FieldValuePair>({
sorting,
rowHeader,
}: CorrelationsTableProps<T>) {
const euiTheme = useTheme();
const { euiTheme } = useEuiTheme();
const trackApmEvent = useUiTracker({ app: 'apm' });
const trackSelectSignificantCorrelationTerm = useCallback(
() => debounce(() => trackApmEvent({ metric: 'select_significant_term' }), 1000),
Expand Down Expand Up @@ -105,7 +104,7 @@ export function CorrelationsTable<T extends FieldValuePair>({
selectedTerm.fieldValue === term.fieldValue &&
selectedTerm.fieldName === term.fieldName
? {
backgroundColor: euiTheme.eui.euiColorLightestShade,
backgroundColor: euiTheme.colors.lightestShade,
}
: null,
};
Expand Down
Loading