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

[APM] Adding comparison latency chart #91339

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7695ae9
adding time comparison to latency chart
cauemarcondes Feb 13, 2021
004ba52
adding time comparison to latency chart
cauemarcondes Feb 13, 2021
f0132d1
fixing TS
cauemarcondes Feb 13, 2021
e33ef14
fixing api test
cauemarcondes Feb 14, 2021
5161ced
Merge branch 'master' of github.com:elastic/kibana into apm-time-comp…
cauemarcondes Feb 15, 2021
a54b36c
addressing PR comments
cauemarcondes Feb 15, 2021
6bbf6c9
Merge branch 'master' of github.com:elastic/kibana into apm-time-comp…
cauemarcondes Feb 18, 2021
286e5e5
adding api test
cauemarcondes Feb 19, 2021
c2e3740
addressing PR comments
cauemarcondes Feb 22, 2021
16dbeea
Merge branch 'master' into apm-time-comparison-latency-chart
kibanamachine Feb 22, 2021
6a4bf87
Merge branch 'master' of github.com:elastic/kibana into apm-time-comp…
cauemarcondes Feb 25, 2021
559bce1
Merge branch 'apm-time-comparison-latency-chart' of github.com:cauema…
cauemarcondes Feb 25, 2021
afa9514
fixing api test
cauemarcondes Feb 25, 2021
92832b6
Merge branch 'master' into apm-time-comparison-latency-chart
kibanamachine Feb 26, 2021
5e4eb97
Merge branch 'master' into apm-time-comparison-latency-chart
kibanamachine Feb 28, 2021
8a20d23
Merge branch 'master' into apm-time-comparison-latency-chart
kibanamachine Mar 4, 2021
ee9e73c
Merge branch 'master' into apm-time-comparison-latency-chart
kibanamachine Mar 8, 2021
648f0f4
rounding date diff
cauemarcondes Mar 8, 2021
6d9d249
addressing PR comments
cauemarcondes Mar 8, 2021
186b3d4
fixing api test
cauemarcondes Mar 9, 2021
e7ae141
Merge branch 'master' of github.com:elastic/kibana into apm-time-comp…
cauemarcondes Mar 9, 2021
23b99c0
refactoring
cauemarcondes Mar 9, 2021
6788723
fixing ts issue
cauemarcondes Mar 9, 2021
22d1a9f
fixing offset function
cauemarcondes Mar 9, 2021
91598bc
fixing offset function
cauemarcondes Mar 9, 2021
f67dc7f
addressing PR comments
cauemarcondes Mar 10, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { LatencyAggregationType } from '../../../../../common/latency_aggregatio
import { getDurationFormatter } from '../../../../../common/utils/formatters';
import { useLicenseContext } from '../../../../context/license/use_license_context';
import { useUrlParams } from '../../../../context/url_params_context/use_url_params';
import { useTheme } from '../../../../hooks/use_theme';
import { useTransactionLatencyChartsFetcher } from '../../../../hooks/use_transaction_latency_chart_fetcher';
import { TimeseriesChart } from '../../../shared/charts/timeseries_chart';
import {
Expand All @@ -21,6 +22,7 @@ import {
} from '../../../shared/charts/transaction_charts/helper';
import { MLHeader } from '../../../shared/charts/transaction_charts/ml_header';
import * as urlHelpers from '../../../shared/Links/url_helpers';
import { getComparisonChartTheme } from '../../time_comparison/get_time_range_comparison';

interface Props {
height?: number;
Expand All @@ -34,18 +36,25 @@ const options: Array<{ value: LatencyAggregationType; text: string }> = [

export function LatencyChart({ height }: Props) {
const history = useHistory();
const theme = useTheme();
const comparisonChartTheme = getComparisonChartTheme(theme);
const { urlParams } = useUrlParams();
const { latencyAggregationType } = urlParams;
const { latencyAggregationType, comparisonEnabled } = urlParams;
const license = useLicenseContext();

const {
latencyChartsData,
latencyChartsStatus,
} = useTransactionLatencyChartsFetcher();

const { latencyTimeseries, anomalyTimeseries, mlJobId } = latencyChartsData;
const {
currentPeriod,
previousPeriod,
anomalyTimeseries,
mlJobId,
} = latencyChartsData;

const latencyMaxY = getMaxY(latencyTimeseries);
const latencyMaxY = getMaxY(currentPeriod);
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
const latencyFormatter = getDurationFormatter(latencyMaxY);

return (
Expand Down Expand Up @@ -99,7 +108,11 @@ export function LatencyChart({ height }: Props) {
height={height}
fetchStatus={latencyChartsStatus}
id="latencyChart"
timeseries={latencyTimeseries}
customTheme={comparisonChartTheme}
timeseries={[
...currentPeriod,
...(comparisonEnabled && previousPeriod ? [previousPeriod] : []),
Copy link
Member

Choose a reason for hiding this comment

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

are we using this flag in other places when deciding to pass the data to the component? not saying we shouldn't, but it should be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dgieselaar yes, the comparisonEnabled will be used on all charts to pass or not the previousPeriod data to the chart component.

]}
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
yLabelFormat={getResponseTimeTickFormatter(latencyFormatter)}
anomalyTimeseries={anomalyTimeseries}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,34 @@ import { useUrlParams } from '../context/url_params_context/use_url_params';
import { useApmServiceContext } from '../context/apm_service/use_apm_service_context';
import { getLatencyChartSelector } from '../selectors/latency_chart_selectors';
import { useTheme } from './use_theme';
import { getTimeRangeComparison } from '../components/shared/time_comparison/get_time_range_comparison';

export function useTransactionLatencyChartsFetcher() {
const { serviceName } = useParams<{ serviceName?: string }>();
const { transactionType } = useApmServiceContext();
const theme = useTheme();
const {
urlParams: { start, end, transactionName, latencyAggregationType },
urlParams: {
start,
end,
transactionName,
latencyAggregationType,
comparisonType,
},
uiFilters,
} = useUrlParams();

const {
comparisonStart = undefined,
comparisonEnd = undefined,
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
} = comparisonType
? getTimeRangeComparison({
start,
end,
comparisonType,
})
: {};

const { data, error, status } = useFetcher(
(callApmApi) => {
if (
Expand All @@ -43,6 +61,8 @@ export function useTransactionLatencyChartsFetcher() {
transactionName,
uiFilters: JSON.stringify(uiFilters),
latencyAggregationType,
comparisonStart,
comparisonEnd,
},
},
});
Expand All @@ -56,6 +76,8 @@ export function useTransactionLatencyChartsFetcher() {
transactionType,
uiFilters,
latencyAggregationType,
comparisonStart,
comparisonEnd,
]
);

Expand Down
128 changes: 66 additions & 62 deletions x-pack/plugins/apm/public/selectors/latency_chart_selector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ const theme = {
euiColorVis5: 'red',
euiColorVis7: 'black',
euiColorVis9: 'yellow',
euiColorLightestShade: 'green',
},
} as EuiTheme;

const latencyChartData = {
overallAvgDuration: 1,
latencyTimeseries: [{ x: 1, y: 10 }],
currentPeriod: {
overallAvgDuration: 1,
latencyTimeseries: [{ x: 1, y: 10 }],
},
previousPeriod: {
overallAvgDuration: 1,
latencyTimeseries: [{ x: 1, y: 10 }],
},
anomalyTimeseries: {
jobId: '1',
anomalyBoundaries: [{ x: 1, y: 2, y0: 1 }],
Expand All @@ -36,21 +43,21 @@ describe('getLatencyChartSelector', () => {
it('returns default values when data is undefined', () => {
const latencyChart = getLatencyChartSelector({ theme });
expect(latencyChart).toEqual({
latencyTimeseries: [],
currentPeriod: [],
mlJobId: undefined,
anomalyTimeseries: undefined,
});
});

it('returns average timeseries', () => {
const { anomalyTimeseries, ...latencyWithouAnomaly } = latencyChartData;
const { anomalyTimeseries, ...latencyWithoutAnomaly } = latencyChartData;
const latencyTimeseries = getLatencyChartSelector({
latencyChart: latencyWithouAnomaly as LatencyChartsResponse,
latencyChart: latencyWithoutAnomaly as LatencyChartsResponse,
theme,
latencyAggregationType: LatencyAggregationType.avg,
});
expect(latencyTimeseries).toEqual({
latencyTimeseries: [
currentPeriod: [
{
title: 'Average',
data: [{ x: 1, y: 10 }],
Expand All @@ -59,46 +66,65 @@ describe('getLatencyChartSelector', () => {
color: 'blue',
},
],
previousPeriod: {
color: 'green',
data: [{ x: 1, y: 10 }],
type: 'area',
title: 'Previous period',
},
});
});

it('returns 95th percentile timeseries', () => {
const { anomalyTimeseries, ...latencyWithouAnomaly } = latencyChartData;
const { anomalyTimeseries, ...latencyWithoutAnomaly } = latencyChartData;
const latencyTimeseries = getLatencyChartSelector({
latencyChart: latencyWithouAnomaly as LatencyChartsResponse,
latencyChart: latencyWithoutAnomaly as LatencyChartsResponse,
theme,
latencyAggregationType: LatencyAggregationType.p95,
});
expect(latencyTimeseries).toEqual({
latencyTimeseries: [
currentPeriod: [
{
title: '95th percentile',
data: [{ x: 1, y: 10 }],
titleShort: '95th',
data: [{ x: 1, y: 10 }],
type: 'linemark',
color: 'red',
},
],
previousPeriod: {
data: [{ x: 1, y: 10 }],
type: 'area',
color: 'green',
title: 'Previous period',
},
});
});

it('returns 99th percentile timeseries', () => {
const { anomalyTimeseries, ...latencyWithouAnomaly } = latencyChartData;
const { anomalyTimeseries, ...latencyWithoutAnomaly } = latencyChartData;
const latencyTimeseries = getLatencyChartSelector({
latencyChart: latencyWithouAnomaly as LatencyChartsResponse,
latencyChart: latencyWithoutAnomaly as LatencyChartsResponse,
theme,
latencyAggregationType: LatencyAggregationType.p99,
});

expect(latencyTimeseries).toEqual({
latencyTimeseries: [
currentPeriod: [
{
title: '99th percentile',
data: [{ x: 1, y: 10 }],
titleShort: '99th',
data: [{ x: 1, y: 10 }],
type: 'linemark',
color: 'black',
},
],
previousPeriod: {
data: [{ x: 1, y: 10 }],
type: 'area',
color: 'green',
title: 'Previous period',
},
});
});
});
Expand All @@ -111,76 +137,54 @@ describe('getLatencyChartSelector', () => {
latencyAggregationType: LatencyAggregationType.p99,
});
expect(latencyTimeseries).toEqual({
currentPeriod: [
{
title: '99th percentile',
titleShort: '99th',
data: [{ x: 1, y: 10 }],
type: 'linemark',
color: 'black',
},
],
previousPeriod: {
data: [{ x: 1, y: 10 }],
type: 'area',
color: 'green',
title: 'Previous period',
},
mlJobId: '1',
anomalyTimeseries: {
boundaries: [
{
color: 'rgba(0,0,0,0)',
areaSeriesStyle: {
point: {
opacity: 0,
},
},
data: [
{
x: 1,
y: 1,
},
],
type: 'area',
fit: 'lookahead',
hideLegend: true,
hideTooltipValue: true,
stackAccessors: ['y'],
areaSeriesStyle: { point: { opacity: 0 } },
title: 'anomalyBoundariesLower',
type: 'area',
data: [{ x: 1, y: 1 }],
color: 'rgba(0,0,0,0)',
},
{
color: 'rgba(0,0,255,0.5)',
areaSeriesStyle: {
point: {
opacity: 0,
},
},
data: [
{
x: 1,
y: 1,
},
],
type: 'area',
fit: 'lookahead',
hideLegend: true,
hideTooltipValue: true,
stackAccessors: ['y'],
areaSeriesStyle: { point: { opacity: 0 } },
title: 'anomalyBoundariesUpper',
type: 'area',
data: [{ x: 1, y: 1 }],
color: 'rgba(0,0,255,0.5)',
},
],
scores: {
color: 'yellow',
data: [
{
x: 1,
x0: 2,
},
],
title: 'anomalyScores',
type: 'rectAnnotation',
data: [{ x: 1, x0: 2 }],
color: 'yellow',
},
},
latencyTimeseries: [
{
color: 'black',
data: [
{
x: 1,
y: 10,
},
],
title: '99th percentile',
titleShort: '99th',
type: 'linemark',
},
],
mlJobId: '1',
});
});
});
Expand Down
Loading