-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Backends inventory & overview page routes
Adds inventory & overview pages for backends, and a latency chart for the latter.
- Loading branch information
1 parent
54717eb
commit 9a91368
Showing
23 changed files
with
687 additions
and
18 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
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,24 @@ | ||
/* | ||
* 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 moment from 'moment'; | ||
import { parseInterval } from '../../../../../src/plugins/data/common'; | ||
|
||
export function getOffsetInMs(start: number, offset?: string) { | ||
if (!offset) { | ||
return 0; | ||
} | ||
|
||
const interval = parseInterval(offset); | ||
|
||
if (!interval) { | ||
throw new Error(`Could not parse offset: ${offset}`); | ||
} | ||
|
||
const calculatedOffset = start - moment(start).subtract(interval).valueOf(); | ||
|
||
return calculatedOffset; | ||
} |
103 changes: 103 additions & 0 deletions
103
x-pack/plugins/apm/public/components/app/backend_detail_overview/backend_latency_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,103 @@ | ||
/* | ||
* 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 { getDurationFormatter } 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'; | ||
import { | ||
getMaxY, | ||
getResponseTimeTickFormatter, | ||
} from '../../shared/charts/transaction_charts/helper'; | ||
|
||
export function BackendLatencyChart({ 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/latency', | ||
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.backendLatencyChart.chartTitle', { | ||
defaultMessage: 'Latency', | ||
}), | ||
}); | ||
} | ||
|
||
if (data?.comparisonTimeseries) { | ||
specs.push({ | ||
data: data.comparisonTimeseries, | ||
type: 'area', | ||
color: theme.eui.euiColorMediumShade, | ||
title: i18n.translate( | ||
'xpack.apm.backendLatencyChart.previousPeriodLabel', | ||
{ defaultMessage: 'Previous period' } | ||
), | ||
}); | ||
} | ||
|
||
return specs; | ||
}, [data, theme.eui.euiColorVis0, theme.eui.euiColorMediumShade]); | ||
|
||
const maxY = getMaxY(timeseries); | ||
const latencyFormatter = getDurationFormatter(maxY); | ||
|
||
return ( | ||
<TimeseriesChart | ||
height={height} | ||
fetchStatus={status} | ||
id="latencyChart" | ||
customTheme={comparisonChartTheme} | ||
timeseries={timeseries} | ||
yLabelFormat={getResponseTimeTickFormatter(latencyFormatter)} | ||
/> | ||
); | ||
} |
59 changes: 59 additions & 0 deletions
59
x-pack/plugins/apm/public/components/app/backend_detail_overview/index.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,59 @@ | ||
/* | ||
* 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 { EuiFlexItem } from '@elastic/eui'; | ||
import { EuiPanel } from '@elastic/eui'; | ||
import { EuiFlexGroup } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { ApmBackendContextProvider } from '../../../context/apm_backend/apm_backend_context'; | ||
import { useBreadcrumb } from '../../../context/breadcrumbs/use_breadcrumb'; | ||
import { ChartPointerEventContextProvider } from '../../../context/chart_pointer_event/chart_pointer_event_context'; | ||
import { useApmParams } from '../../../hooks/use_apm_params'; | ||
import { useApmRouter } from '../../../hooks/use_apm_router'; | ||
import { ApmMainTemplate } from '../../routing/templates/apm_main_template'; | ||
import { SearchBar } from '../../shared/search_bar'; | ||
import { BackendLatencyChart } from './backend_latency_chart'; | ||
import { BackendInventoryTitle } from '../../routing/home'; | ||
|
||
export function BackendDetailOverview() { | ||
const { | ||
path: { backendName }, | ||
query, | ||
} = useApmParams('/backends/:backendName/overview'); | ||
|
||
const apmRouter = useApmRouter(); | ||
|
||
useBreadcrumb([ | ||
{ | ||
title: BackendInventoryTitle, | ||
href: apmRouter.link('/backends'), | ||
}, | ||
{ | ||
title: backendName, | ||
href: apmRouter.link('/backends/:backendName/overview', { | ||
path: { backendName }, | ||
query, | ||
}), | ||
}, | ||
]); | ||
|
||
return ( | ||
<ApmMainTemplate pageTitle={backendName}> | ||
<ApmBackendContextProvider> | ||
<SearchBar showTimeComparison /> | ||
<ChartPointerEventContextProvider> | ||
<EuiFlexGroup direction="column" gutterSize="s"> | ||
<EuiFlexItem> | ||
<EuiPanel hasBorder={true}> | ||
<BackendLatencyChart height={200} /> | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</ChartPointerEventContextProvider> | ||
</ApmBackendContextProvider> | ||
</ApmMainTemplate> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/apm/public/components/app/backend_inventory/index.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,13 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { SearchBar } from '../../shared/search_bar'; | ||
|
||
export function BackendInventory() { | ||
return <SearchBar showTimeComparison />; | ||
} |
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
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
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
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
Oops, something went wrong.