-
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.
[Uptime] Annotate waterfall chart with additional metrics (#103642)
Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
dbad35f
commit 00bb597
Showing
15 changed files
with
390 additions
and
19 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
102 changes: 102 additions & 0 deletions
102
...time/public/components/monitor/synthetics/step_detail/use_step_waterfall_metrics.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,102 @@ | ||
/* | ||
* 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 { renderHook } from '@testing-library/react-hooks'; | ||
import { | ||
BROWSER_TRACE_NAME, | ||
BROWSER_TRACE_START, | ||
BROWSER_TRACE_TYPE, | ||
useStepWaterfallMetrics, | ||
} from './use_step_waterfall_metrics'; | ||
import * as reduxHooks from 'react-redux'; | ||
import * as searchHooks from '../../../../../../observability/public/hooks/use_es_search'; | ||
|
||
describe('useStepWaterfallMetrics', () => { | ||
jest | ||
.spyOn(reduxHooks, 'useSelector') | ||
.mockReturnValue({ settings: { heartbeatIndices: 'heartbeat-*' } }); | ||
|
||
it('returns result as expected', () => { | ||
// @ts-ignore | ||
const searchHook = jest.spyOn(searchHooks, 'useEsSearch').mockReturnValue({ | ||
loading: false, | ||
data: { | ||
hits: { | ||
total: { value: 2, relation: 'eq' }, | ||
hits: [ | ||
{ | ||
fields: { | ||
[BROWSER_TRACE_TYPE]: ['mark'], | ||
[BROWSER_TRACE_NAME]: ['navigationStart'], | ||
[BROWSER_TRACE_START]: [3456789], | ||
}, | ||
}, | ||
{ | ||
fields: { | ||
[BROWSER_TRACE_TYPE]: ['mark'], | ||
[BROWSER_TRACE_NAME]: ['domContentLoaded'], | ||
[BROWSER_TRACE_START]: [4456789], | ||
}, | ||
}, | ||
], | ||
}, | ||
} as any, | ||
}); | ||
|
||
const { result } = renderHook( | ||
(props) => | ||
useStepWaterfallMetrics({ | ||
checkGroup: '44D-444FFF-444-FFF-3333', | ||
hasNavigationRequest: true, | ||
stepIndex: 1, | ||
}), | ||
{} | ||
); | ||
|
||
expect(searchHook).toHaveBeenCalledWith( | ||
{ | ||
body: { | ||
_source: false, | ||
fields: ['browser.*'], | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ | ||
term: { | ||
'synthetics.step.index': 1, | ||
}, | ||
}, | ||
{ | ||
term: { | ||
'monitor.check_group': '44D-444FFF-444-FFF-3333', | ||
}, | ||
}, | ||
{ | ||
term: { | ||
'synthetics.type': 'step/metrics', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
size: 1000, | ||
}, | ||
index: 'heartbeat-*', | ||
}, | ||
['heartbeat-*', '44D-444FFF-444-FFF-3333', true] | ||
); | ||
expect(result.current).toEqual({ | ||
loading: false, | ||
metrics: [ | ||
{ | ||
id: 'domContentLoaded', | ||
offset: 1000, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
100 changes: 100 additions & 0 deletions
100
...ins/uptime/public/components/monitor/synthetics/step_detail/use_step_waterfall_metrics.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,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 { useSelector } from 'react-redux'; | ||
import { createEsParams, useEsSearch } from '../../../../../../observability/public'; | ||
import { selectDynamicSettings } from '../../../../state/selectors'; | ||
import { MarkerItems } from '../waterfall/context/waterfall_chart'; | ||
|
||
export interface Props { | ||
checkGroup: string; | ||
stepIndex: number; | ||
hasNavigationRequest?: boolean; | ||
} | ||
export const BROWSER_TRACE_TYPE = 'browser.relative_trace.type'; | ||
export const BROWSER_TRACE_NAME = 'browser.relative_trace.name'; | ||
export const BROWSER_TRACE_START = 'browser.relative_trace.start.us'; | ||
export const NAVIGATION_START = 'navigationStart'; | ||
|
||
export const useStepWaterfallMetrics = ({ checkGroup, hasNavigationRequest, stepIndex }: Props) => { | ||
const { settings } = useSelector(selectDynamicSettings); | ||
|
||
const heartbeatIndices = settings?.heartbeatIndices || ''; | ||
|
||
const { data, loading } = useEsSearch( | ||
hasNavigationRequest | ||
? createEsParams({ | ||
index: heartbeatIndices!, | ||
body: { | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ | ||
term: { | ||
'synthetics.step.index': stepIndex, | ||
}, | ||
}, | ||
{ | ||
term: { | ||
'monitor.check_group': checkGroup, | ||
}, | ||
}, | ||
{ | ||
term: { | ||
'synthetics.type': 'step/metrics', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
fields: ['browser.*'], | ||
size: 1000, | ||
_source: false, | ||
}, | ||
}) | ||
: {}, | ||
[heartbeatIndices, checkGroup, hasNavigationRequest] | ||
); | ||
|
||
if (!hasNavigationRequest) { | ||
return { metrics: [], loading: false }; | ||
} | ||
|
||
const metrics: MarkerItems = []; | ||
|
||
if (data && hasNavigationRequest) { | ||
const metricDocs = data.hits.hits as unknown as Array<{ fields: any }>; | ||
let navigationStart = 0; | ||
let navigationStartExist = false; | ||
|
||
metricDocs.forEach(({ fields }) => { | ||
if (fields[BROWSER_TRACE_TYPE]?.[0] === 'mark') { | ||
const { [BROWSER_TRACE_NAME]: metricType, [BROWSER_TRACE_START]: metricValue } = fields; | ||
if (metricType?.[0] === NAVIGATION_START) { | ||
navigationStart = metricValue?.[0]; | ||
navigationStartExist = true; | ||
} | ||
} | ||
}); | ||
|
||
if (navigationStartExist) { | ||
metricDocs.forEach(({ fields }) => { | ||
if (fields[BROWSER_TRACE_TYPE]?.[0] === 'mark') { | ||
const { [BROWSER_TRACE_NAME]: metricType, [BROWSER_TRACE_START]: metricValue } = fields; | ||
if (metricType?.[0] !== NAVIGATION_START) { | ||
metrics.push({ | ||
id: metricType?.[0], | ||
offset: (metricValue?.[0] - navigationStart) / 1000, | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
return { metrics, loading }; | ||
}; |
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
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.