forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Performance comparison charts by browser
Show a chart with average page load broken down by user agent name on the RUM overview. I tested this by setting up a RUM agent on a sample app on my test cloud cluster. On the internal APM dev cluster you'll need to set the time range to about 90 days then look at the "client" app and find the time range where there are requests. Unfortunately with this sample data the only series you see is "Other" because there aren't a lot of requests. Fixes elastic#43342
- Loading branch information
Showing
17 changed files
with
569 additions
and
44 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
x-pack/legacy/plugins/apm/common/__snapshots__/elasticsearch_fieldnames.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
19 changes: 19 additions & 0 deletions
19
...y/plugins/apm/public/components/shared/charts/TransactionCharts/BrowserLineChart.test.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,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { BrowserLineChart } from './BrowserLineChart'; | ||
|
||
describe('BrowserLineChart', () => { | ||
describe('render', () => { | ||
it('renders', () => { | ||
const props = { series: [] }; | ||
|
||
expect(() => shallow(<BrowserLineChart {...props} />)).not.toThrowError(); | ||
}); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
...legacy/plugins/apm/public/components/shared/charts/TransactionCharts/BrowserLineChart.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,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiTitle } from '@elastic/eui'; | ||
import { TransactionLineChart } from './TransactionLineChart'; | ||
import { | ||
getMaxY, | ||
getResponseTimeTickFormatter, | ||
getResponseTimeTooltipFormatter | ||
} from '.'; | ||
import { getDurationFormatter } from '../../../../utils/formatters'; | ||
import { useAvgDurationByBrowser } from '../../../../hooks/useAvgDurationByBrowser'; | ||
|
||
export function BrowserLineChart() { | ||
const { data } = useAvgDurationByBrowser(); | ||
const maxY = getMaxY(data); | ||
const formatter = getDurationFormatter(maxY); | ||
const formatTooltipValue = getResponseTimeTooltipFormatter(formatter); | ||
const tickFormatY = getResponseTimeTickFormatter(formatter); | ||
|
||
return ( | ||
<> | ||
<EuiTitle size="xs"> | ||
<span> | ||
{i18n.translate( | ||
'xpack.apm.metrics.pageLoadCharts.avgPageLoadByBrowser', | ||
{ | ||
defaultMessage: 'Avg. page load duration distribution by browser' | ||
} | ||
)} | ||
</span> | ||
</EuiTitle> | ||
<TransactionLineChart | ||
formatTooltipValue={formatTooltipValue} | ||
series={data} | ||
tickFormatY={tickFormatY} | ||
/> | ||
</> | ||
); | ||
} |
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
33 changes: 33 additions & 0 deletions
33
x-pack/legacy/plugins/apm/public/hooks/useAvgDurationByBrowser.test.ts
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,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { renderHook } from 'react-hooks-testing-library'; | ||
import theme from '@elastic/eui/dist/eui_theme_light.json'; | ||
import * as useFetcherModule from './useFetcher'; | ||
import { useAvgDurationByBrowser } from './useAvgDurationByBrowser'; | ||
|
||
describe('useAvgDurationByBrowser', () => { | ||
it('returns data', () => { | ||
const data = [ | ||
{ title: 'Other', data: [{ x: 1572530100000, y: 130010.8947368421 }] } | ||
]; | ||
jest.spyOn(useFetcherModule, 'useFetcher').mockReturnValueOnce({ | ||
data, | ||
refetch: () => {}, | ||
status: 'success' as useFetcherModule.FETCH_STATUS | ||
}); | ||
const { result } = renderHook(() => useAvgDurationByBrowser()); | ||
|
||
expect(result.current.data).toEqual([ | ||
{ | ||
color: theme.euiColorVis0, | ||
data: [{ x: 1572530100000, y: 130010.8947368421 }], | ||
title: 'Other', | ||
type: 'linemark' | ||
} | ||
]); | ||
}); | ||
}); |
72 changes: 72 additions & 0 deletions
72
x-pack/legacy/plugins/apm/public/hooks/useAvgDurationByBrowser.ts
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,72 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import theme from '@elastic/eui/dist/eui_theme_light.json'; | ||
import { useFetcher } from './useFetcher'; | ||
import { useUrlParams } from './useUrlParams'; | ||
import { AvgDurationByBrowserAPIResponse } from '../../server/lib/transactions/avg_duration_by_browser'; | ||
import { TimeSeries } from '../../typings/timeseries'; | ||
|
||
const colors = [ | ||
theme.euiColorVis0, | ||
theme.euiColorVis1, | ||
theme.euiColorVis2, | ||
theme.euiColorVis3, | ||
theme.euiColorVis4, | ||
theme.euiColorVis5, | ||
theme.euiColorVis6, | ||
theme.euiColorVis7, | ||
theme.euiColorVis8, | ||
theme.euiColorVis9 | ||
]; | ||
|
||
function toTimeSeries(data: AvgDurationByBrowserAPIResponse): TimeSeries[] { | ||
if (!data) { | ||
return []; | ||
} | ||
|
||
return data.map((item, index) => { | ||
return { | ||
...item, | ||
color: colors[index % colors.length], | ||
type: 'linemark' | ||
}; | ||
}); | ||
} | ||
|
||
export function useAvgDurationByBrowser() { | ||
const { | ||
urlParams: { serviceName, start, end, transactionName }, | ||
uiFilters | ||
} = useUrlParams(); | ||
|
||
const { data, error, status } = useFetcher( | ||
callApmApi => { | ||
if (serviceName && start && end) { | ||
return callApmApi({ | ||
pathname: | ||
'/api/apm/services/{serviceName}/transaction_groups/avg_duration_by_browser', | ||
params: { | ||
path: { serviceName }, | ||
query: { | ||
start, | ||
end, | ||
transactionName, | ||
uiFilters: JSON.stringify(uiFilters) | ||
} | ||
} | ||
}); | ||
} | ||
}, | ||
[serviceName, start, end, transactionName, uiFilters] | ||
); | ||
|
||
return { | ||
data: toTimeSeries(data), | ||
status, | ||
error | ||
}; | ||
} |
Oops, something went wrong.