-
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.
Browse files
Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
1ba7d22
commit 5516dc6
Showing
22 changed files
with
665 additions
and
51 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
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
45 changes: 45 additions & 0 deletions
45
x-pack/plugins/apm/public/components/app/RumDashboard/CsmSharedContext/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,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, { createContext, useMemo, useState } from 'react'; | ||
|
||
interface SharedData { | ||
totalPageViews: number; | ||
} | ||
|
||
interface Index { | ||
sharedData: SharedData; | ||
setSharedData: (data: SharedData) => void; | ||
} | ||
|
||
const defaultContext: Index = { | ||
sharedData: { totalPageViews: 0 }, | ||
setSharedData: (d) => { | ||
throw new Error( | ||
'setSharedData was not initialized, set it when you invoke the context' | ||
); | ||
}, | ||
}; | ||
|
||
export const CsmSharedContext = createContext(defaultContext); | ||
|
||
export function CsmSharedContextProvider({ | ||
children, | ||
}: { | ||
children: JSX.Element[]; | ||
}) { | ||
const [newData, setNewData] = useState<SharedData>({ totalPageViews: 0 }); | ||
|
||
const setSharedData = React.useCallback((data: SharedData) => { | ||
setNewData(data); | ||
}, []); | ||
|
||
const value = useMemo(() => { | ||
return { sharedData: newData, setSharedData }; | ||
}, [newData, setSharedData]); | ||
|
||
return <CsmSharedContext.Provider value={value} children={children} />; | ||
} |
138 changes: 138 additions & 0 deletions
138
x-pack/plugins/apm/public/components/app/RumDashboard/ImpactfulMetrics/JSErrors.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,138 @@ | ||
/* | ||
* 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, { useContext, useState } from 'react'; | ||
import { | ||
EuiBasicTable, | ||
EuiFlexItem, | ||
EuiFlexGroup, | ||
EuiSpacer, | ||
EuiTitle, | ||
EuiStat, | ||
EuiToolTip, | ||
} from '@elastic/eui'; | ||
import numeral from '@elastic/numeral'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useUrlParams } from '../../../../hooks/useUrlParams'; | ||
import { useFetcher } from '../../../../hooks/useFetcher'; | ||
import { I18LABELS } from '../translations'; | ||
import { CsmSharedContext } from '../CsmSharedContext'; | ||
|
||
export function JSErrors() { | ||
const { urlParams, uiFilters } = useUrlParams(); | ||
|
||
const { start, end, serviceName } = urlParams; | ||
|
||
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 5 }); | ||
|
||
const { data, status } = useFetcher( | ||
(callApmApi) => { | ||
if (start && end && serviceName) { | ||
return callApmApi({ | ||
pathname: '/api/apm/rum-client/js-errors', | ||
params: { | ||
query: { | ||
start, | ||
end, | ||
uiFilters: JSON.stringify(uiFilters), | ||
pageSize: String(pagination.pageSize), | ||
pageIndex: String(pagination.pageIndex), | ||
}, | ||
}, | ||
}); | ||
} | ||
return Promise.resolve(null); | ||
}, | ||
[start, end, serviceName, uiFilters, pagination] | ||
); | ||
|
||
const { | ||
sharedData: { totalPageViews }, | ||
} = useContext(CsmSharedContext); | ||
|
||
const items = (data?.items ?? []).map(({ errorMessage, count }) => ({ | ||
errorMessage, | ||
percent: i18n.translate('xpack.apm.rum.jsErrors.percent', { | ||
defaultMessage: '{pageLoadPercent} %', | ||
values: { pageLoadPercent: ((count / totalPageViews) * 100).toFixed(1) }, | ||
}), | ||
})); | ||
|
||
const cols = [ | ||
{ | ||
field: 'errorMessage', | ||
name: I18LABELS.errorMessage, | ||
}, | ||
{ | ||
name: I18LABELS.impactedPageLoads, | ||
field: 'percent', | ||
align: 'right' as const, | ||
}, | ||
]; | ||
|
||
const onTableChange = ({ | ||
page, | ||
}: { | ||
page: { size: number; index: number }; | ||
}) => { | ||
setPagination({ | ||
pageIndex: page.index, | ||
pageSize: page.size, | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<EuiTitle size="xs"> | ||
<h3>{I18LABELS.jsErrors}</h3> | ||
</EuiTitle> | ||
<EuiSpacer size="s" /> | ||
<EuiFlexGroup> | ||
<EuiFlexItem grow={false}> | ||
<EuiStat | ||
titleSize="s" | ||
title={ | ||
<EuiToolTip content={data?.totalErrors ?? 0}> | ||
<>{numeral(data?.totalErrors ?? 0).format('0 a')}</> | ||
</EuiToolTip> | ||
} | ||
description={I18LABELS.totalErrors} | ||
isLoading={status !== 'success'} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiStat | ||
titleSize="s" | ||
title={i18n.translate('xpack.apm.rum.jsErrors.errorRateValue', { | ||
defaultMessage: '{errorRate} %', | ||
values: { | ||
errorRate: ( | ||
((data?.totalErrorPages ?? 0) / totalPageViews) * | ||
100 | ||
).toFixed(0), | ||
}, | ||
})} | ||
description={I18LABELS.errorRate} | ||
isLoading={status !== 'success'} | ||
/> | ||
</EuiFlexItem>{' '} | ||
</EuiFlexGroup> | ||
<EuiSpacer size="s" /> | ||
<EuiBasicTable | ||
loading={status !== 'success'} | ||
responsive={false} | ||
compressed={true} | ||
columns={cols} | ||
items={items} | ||
onChange={onTableChange} | ||
pagination={{ | ||
...pagination, | ||
totalItemCount: data?.totalErrorGroups ?? 0, | ||
}} | ||
/> | ||
</> | ||
); | ||
} |
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/apm/public/components/app/RumDashboard/ImpactfulMetrics/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,22 @@ | ||
/* | ||
* 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 { EuiFlexItem, EuiPanel, EuiFlexGroup, EuiSpacer } from '@elastic/eui'; | ||
import { JSErrors } from './JSErrors'; | ||
|
||
export function ImpactfulMetrics() { | ||
return ( | ||
<EuiPanel> | ||
<EuiSpacer size="xs" /> | ||
<EuiFlexGroup wrap> | ||
<EuiFlexItem style={{ flexBasis: 650 }}> | ||
<JSErrors /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
} |
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.