-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Add throughput, error rate charts to backend detail page (#107379…
…) (#107618)
- Loading branch information
1 parent
a57b716
commit 4e42e5d
Showing
11 changed files
with
586 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...ck/plugins/apm/public/components/app/backend_detail_overview/backend_error_rate_chart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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 React, { useMemo } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { asPercent } from '../../../../common/utils/formatters'; | ||
import { useApmBackendContext } from '../../../context/apm_backend/use_apm_backend_context'; | ||
import { useUrlParams } from '../../../context/url_params_context/use_url_params'; | ||
import { useComparison } from '../../../hooks/use_comparison'; | ||
import { useFetcher } from '../../../hooks/use_fetcher'; | ||
import { useTimeRange } from '../../../hooks/use_time_range'; | ||
import { Coordinate, TimeSeries } from '../../../../typings/timeseries'; | ||
import { TimeseriesChart } from '../../shared/charts/timeseries_chart'; | ||
import { useTheme } from '../../../hooks/use_theme'; | ||
|
||
function yLabelFormat(y?: number | null) { | ||
return asPercent(y || 0, 1); | ||
} | ||
|
||
export function BackendErrorRateChart({ height }: { height: number }) { | ||
const { backendName } = useApmBackendContext(); | ||
|
||
const theme = useTheme(); | ||
|
||
const { start, end } = useTimeRange(); | ||
|
||
const { | ||
urlParams: { kuery, environment }, | ||
} = useUrlParams(); | ||
|
||
const { offset, comparisonChartTheme } = useComparison(); | ||
|
||
const { data, status } = useFetcher( | ||
(callApmApi) => { | ||
if (!start || !end) { | ||
return; | ||
} | ||
|
||
return callApmApi({ | ||
endpoint: 'GET /api/apm/backends/{backendName}/charts/error_rate', | ||
params: { | ||
path: { | ||
backendName, | ||
}, | ||
query: { | ||
start, | ||
end, | ||
offset, | ||
kuery, | ||
environment, | ||
}, | ||
}, | ||
}); | ||
}, | ||
[backendName, start, end, offset, kuery, environment] | ||
); | ||
|
||
const timeseries = useMemo(() => { | ||
const specs: Array<TimeSeries<Coordinate>> = []; | ||
|
||
if (data?.currentTimeseries) { | ||
specs.push({ | ||
data: data.currentTimeseries, | ||
type: 'linemark', | ||
color: theme.eui.euiColorVis7, | ||
title: i18n.translate('xpack.apm.backendErrorRateChart.chartTitle', { | ||
defaultMessage: 'Error rate', | ||
}), | ||
}); | ||
} | ||
|
||
if (data?.comparisonTimeseries) { | ||
specs.push({ | ||
data: data.comparisonTimeseries, | ||
type: 'area', | ||
color: theme.eui.euiColorMediumShade, | ||
title: i18n.translate( | ||
'xpack.apm.backendErrorRateChart.previousPeriodLabel', | ||
{ defaultMessage: 'Previous period' } | ||
), | ||
}); | ||
} | ||
|
||
return specs; | ||
}, [data, theme.eui.euiColorVis7, theme.eui.euiColorMediumShade]); | ||
|
||
return ( | ||
<TimeseriesChart | ||
height={height} | ||
fetchStatus={status} | ||
id="errorRateChart" | ||
customTheme={comparisonChartTheme} | ||
timeseries={timeseries} | ||
yLabelFormat={yLabelFormat} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...ck/plugins/apm/public/components/app/backend_detail_overview/backend_throughput_chart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* 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 React, { useMemo } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { asTransactionRate } from '../../../../common/utils/formatters'; | ||
import { useApmBackendContext } from '../../../context/apm_backend/use_apm_backend_context'; | ||
import { useUrlParams } from '../../../context/url_params_context/use_url_params'; | ||
import { useComparison } from '../../../hooks/use_comparison'; | ||
import { useFetcher } from '../../../hooks/use_fetcher'; | ||
import { useTimeRange } from '../../../hooks/use_time_range'; | ||
import { Coordinate, TimeSeries } from '../../../../typings/timeseries'; | ||
import { TimeseriesChart } from '../../shared/charts/timeseries_chart'; | ||
import { useTheme } from '../../../hooks/use_theme'; | ||
|
||
export function BackendThroughputChart({ height }: { height: number }) { | ||
const { backendName } = useApmBackendContext(); | ||
|
||
const theme = useTheme(); | ||
|
||
const { start, end } = useTimeRange(); | ||
|
||
const { | ||
urlParams: { kuery, environment }, | ||
} = useUrlParams(); | ||
|
||
const { offset, comparisonChartTheme } = useComparison(); | ||
|
||
const { data, status } = useFetcher( | ||
(callApmApi) => { | ||
if (!start || !end) { | ||
return; | ||
} | ||
|
||
return callApmApi({ | ||
endpoint: 'GET /api/apm/backends/{backendName}/charts/throughput', | ||
params: { | ||
path: { | ||
backendName, | ||
}, | ||
query: { | ||
start, | ||
end, | ||
offset, | ||
kuery, | ||
environment, | ||
}, | ||
}, | ||
}); | ||
}, | ||
[backendName, start, end, offset, kuery, environment] | ||
); | ||
|
||
const timeseries = useMemo(() => { | ||
const specs: Array<TimeSeries<Coordinate>> = []; | ||
|
||
if (data?.currentTimeseries) { | ||
specs.push({ | ||
data: data.currentTimeseries, | ||
type: 'linemark', | ||
color: theme.eui.euiColorVis0, | ||
title: i18n.translate('xpack.apm.backendThroughputChart.chartTitle', { | ||
defaultMessage: 'Throughput', | ||
}), | ||
}); | ||
} | ||
|
||
if (data?.comparisonTimeseries) { | ||
specs.push({ | ||
data: data.comparisonTimeseries, | ||
type: 'area', | ||
color: theme.eui.euiColorMediumShade, | ||
title: i18n.translate( | ||
'xpack.apm.backendThroughputChart.previousPeriodLabel', | ||
{ defaultMessage: 'Previous period' } | ||
), | ||
}); | ||
} | ||
|
||
return specs; | ||
}, [data, theme.eui.euiColorVis0, theme.eui.euiColorMediumShade]); | ||
|
||
return ( | ||
<TimeseriesChart | ||
height={height} | ||
fetchStatus={status} | ||
id="throughputChart" | ||
customTheme={comparisonChartTheme} | ||
timeseries={timeseries} | ||
yLabelFormat={asTransactionRate} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
x-pack/plugins/apm/public/components/routing/templates/backend_detail_template.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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 { EuiFlexGroup, EuiFlexItem, EuiTitle } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { useApmBackendContext } from '../../../context/apm_backend/use_apm_backend_context'; | ||
import { ApmMainTemplate } from './apm_main_template'; | ||
import { SpanIcon } from '../../shared/span_icon'; | ||
|
||
interface Props { | ||
title: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
export function BackendDetailTemplate({ title, children }: Props) { | ||
const { | ||
backendName, | ||
metadata: { data }, | ||
} = useApmBackendContext(); | ||
|
||
const metadata = data?.metadata; | ||
|
||
return ( | ||
<ApmMainTemplate | ||
pageHeader={{ | ||
pageTitle: ( | ||
<EuiFlexGroup alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiTitle size="l"> | ||
<h1>{backendName}</h1> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<SpanIcon | ||
type={metadata?.spanType} | ||
subtype={metadata?.spanSubtype} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
), | ||
}} | ||
> | ||
{children} | ||
</ApmMainTemplate> | ||
); | ||
} |
Oops, something went wrong.