-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Backends inventory & overview page routes #106223
Changes from all commits
9a91368
1c173ee
ed5967e
1d67ffd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} |
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like if this was changed we should update the others APIs too. Otherwise now we'll have two ways to get comparison data. |
||
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)} | ||
/> | ||
); | ||
} |
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are backends uniquely keyed by their name? Seems like it would be common to have more than one "postgres" or "redis". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, they can be different instances but we group them by |
||
|
||
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> | ||
); | ||
} |
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 />; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3