-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[APM]Create API to return data to be used on the Overview page #69137
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d207d55
Adding apm data fetcher
cauemarcondes b4ba6ff
removing error rate
cauemarcondes be59683
chaging observability dashboard routes
cauemarcondes 679ccd7
APM observability fetch data
cauemarcondes 1188e7f
fixing imports
cauemarcondes cca31e9
adding unit test
cauemarcondes 9a92fae
addressing PR comments
cauemarcondes 8baaa5e
adding processor event in the query, and refactoring theme
cauemarcondes 9e6924d
Merge branch 'master' of github.com:elastic/kibana into obs-apm-data
cauemarcondes ceff040
fixing ts issues
cauemarcondes 1d8d58f
fixing unit tests
cauemarcondes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
121 changes: 121 additions & 0 deletions
121
x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts
This file contains hidden or 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,121 @@ | ||
| /* | ||
| * 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 { fetchLandingPageData, hasData } from './observability_dashboard'; | ||
| import * as createCallApmApi from './createCallApmApi'; | ||
| import { getTheme } from '../../utils/get_theme'; | ||
|
|
||
| const theme = getTheme({ isDarkMode: false }); | ||
|
|
||
| describe('Observability dashboard data', () => { | ||
| const callApmApiMock = jest.spyOn(createCallApmApi, 'callApmApi'); | ||
| afterEach(() => { | ||
| callApmApiMock.mockClear(); | ||
| }); | ||
| describe('hasData', () => { | ||
| it('returns false when no data is available', async () => { | ||
| callApmApiMock.mockImplementation(() => Promise.resolve(false)); | ||
| const response = await hasData(); | ||
| expect(response).toBeFalsy(); | ||
| }); | ||
| it('returns true when data is available', async () => { | ||
| callApmApiMock.mockImplementation(() => Promise.resolve(true)); | ||
| const response = await hasData(); | ||
| expect(response).toBeTruthy(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('fetchLandingPageData', () => { | ||
| it('returns APM data with series and stats', async () => { | ||
| callApmApiMock.mockImplementation(() => | ||
| Promise.resolve({ | ||
| serviceCount: 10, | ||
| transactionCoordinates: [ | ||
| { x: 1, y: 1 }, | ||
| { x: 2, y: 2 }, | ||
| { x: 3, y: 3 }, | ||
| ], | ||
| }) | ||
| ); | ||
| const response = await fetchLandingPageData( | ||
| { | ||
| startTime: '1', | ||
| endTime: '2', | ||
| bucketSize: '3', | ||
| }, | ||
| { theme } | ||
| ); | ||
| expect(response).toEqual({ | ||
| title: 'APM', | ||
| appLink: '/app/apm', | ||
| stats: { | ||
| services: { | ||
| type: 'number', | ||
| label: 'Services', | ||
| value: 10, | ||
| }, | ||
| transactions: { | ||
| type: 'number', | ||
| label: 'Transactions', | ||
| value: 6, | ||
| color: '#6092c0', | ||
| }, | ||
| }, | ||
| series: { | ||
| transactions: { | ||
| label: 'Transactions', | ||
| coordinates: [ | ||
| { x: 1, y: 1 }, | ||
| { x: 2, y: 2 }, | ||
| { x: 3, y: 3 }, | ||
| ], | ||
| color: '#6092c0', | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| it('returns empty transaction coordinates', async () => { | ||
| callApmApiMock.mockImplementation(() => | ||
| Promise.resolve({ | ||
| serviceCount: 0, | ||
| transactionCoordinates: [], | ||
| }) | ||
| ); | ||
| const response = await fetchLandingPageData( | ||
| { | ||
| startTime: '1', | ||
| endTime: '2', | ||
| bucketSize: '3', | ||
| }, | ||
| { theme } | ||
| ); | ||
| expect(response).toEqual({ | ||
| title: 'APM', | ||
| appLink: '/app/apm', | ||
| stats: { | ||
| services: { | ||
| type: 'number', | ||
| label: 'Services', | ||
| value: 0, | ||
| }, | ||
| transactions: { | ||
| type: 'number', | ||
| label: 'Transactions', | ||
| value: 0, | ||
| color: '#6092c0', | ||
| }, | ||
| }, | ||
| series: { | ||
| transactions: { | ||
| label: 'Transactions', | ||
| coordinates: [], | ||
| color: '#6092c0', | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
cauemarcondes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
71 changes: 71 additions & 0 deletions
71
x-pack/plugins/apm/public/services/rest/observability_dashboard.ts
This file contains hidden or 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,71 @@ | ||
| /* | ||
| * 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 { i18n } from '@kbn/i18n'; | ||
| import { sum } from 'lodash'; | ||
| // eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
| import { FetchDataParams } from '../../../../observability/public/data_handler'; | ||
| import { ApmFetchDataResponse } from '../../../../observability/public/typings/fetch_data_response'; | ||
| import { callApmApi } from './createCallApmApi'; | ||
| import { Theme } from '../../utils/get_theme'; | ||
|
|
||
| interface Options { | ||
| theme: Theme; | ||
| } | ||
|
|
||
| export const fetchLandingPageData = async ( | ||
| { startTime, endTime, bucketSize }: FetchDataParams, | ||
| { theme }: Options | ||
| ): Promise<ApmFetchDataResponse> => { | ||
| const data = await callApmApi({ | ||
| pathname: '/api/apm/observability_dashboard', | ||
| params: { query: { start: startTime, end: endTime, bucketSize } }, | ||
| }); | ||
|
|
||
| const { serviceCount, transactionCoordinates } = data; | ||
|
|
||
| return { | ||
| title: i18n.translate('xpack.apm.observabilityDashboard.title', { | ||
| defaultMessage: 'APM', | ||
| }), | ||
| appLink: '/app/apm', | ||
| stats: { | ||
| services: { | ||
| type: 'number', | ||
| label: i18n.translate( | ||
| 'xpack.apm.observabilityDashboard.stats.services', | ||
| { defaultMessage: 'Services' } | ||
| ), | ||
| value: serviceCount, | ||
| }, | ||
| transactions: { | ||
| type: 'number', | ||
| label: i18n.translate( | ||
| 'xpack.apm.observabilityDashboard.stats.transactions', | ||
| { defaultMessage: 'Transactions' } | ||
| ), | ||
| value: sum(transactionCoordinates.map((coordinates) => coordinates.y)), | ||
| color: theme.euiColorVis1, | ||
| }, | ||
| }, | ||
| series: { | ||
| transactions: { | ||
| label: i18n.translate( | ||
| 'xpack.apm.observabilityDashboard.chart.transactions', | ||
| { defaultMessage: 'Transactions' } | ||
| ), | ||
| color: theme.euiColorVis1, | ||
| coordinates: transactionCoordinates, | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| export async function hasData() { | ||
| return await callApmApi({ | ||
| pathname: '/api/apm/observability_dashboard/has_data', | ||
| }); | ||
| } |
This file contains hidden or 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; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| import lightTheme from '@elastic/eui/dist/eui_theme_light.json'; | ||
| import darkTheme from '@elastic/eui/dist/eui_theme_dark.json'; | ||
|
|
||
| export type Theme = ReturnType<typeof getTheme>; | ||
|
|
||
| export function getTheme({ isDarkMode }: { isDarkMode: boolean }) { | ||
| return isDarkMode ? darkTheme : lightTheme; | ||
| } |
52 changes: 52 additions & 0 deletions
52
x-pack/plugins/apm/server/lib/observability_dashboard/get_service_count.ts
This file contains hidden or 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,52 @@ | ||
| /* | ||
| * 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 { ProcessorEvent } from '../../../common/processor_event'; | ||
| import { rangeFilter } from '../../../common/utils/range_filter'; | ||
| import { | ||
| SERVICE_NAME, | ||
| PROCESSOR_EVENT, | ||
| } from '../../../common/elasticsearch_fieldnames'; | ||
| import { Setup, SetupTimeRange } from '../helpers/setup_request'; | ||
|
|
||
| export async function getServiceCount({ | ||
| setup, | ||
| }: { | ||
| setup: Setup & SetupTimeRange; | ||
| }) { | ||
| const { client, indices, start, end } = setup; | ||
|
|
||
| const params = { | ||
| index: [ | ||
| indices['apm_oss.transactionIndices'], | ||
| indices['apm_oss.errorIndices'], | ||
| indices['apm_oss.metricsIndices'], | ||
| ], | ||
| body: { | ||
| size: 0, | ||
| query: { | ||
| bool: { | ||
| filter: [ | ||
| { range: rangeFilter(start, end) }, | ||
| { | ||
| terms: { | ||
| [PROCESSOR_EVENT]: [ | ||
| ProcessorEvent.error, | ||
| ProcessorEvent.transaction, | ||
| ProcessorEvent.metric, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| aggs: { serviceCount: { cardinality: { field: SERVICE_NAME } } }, | ||
| }, | ||
| }; | ||
|
|
||
| const { aggregations } = await client.search(params); | ||
| return aggregations?.serviceCount.value || 0; | ||
| } |
57 changes: 57 additions & 0 deletions
57
x-pack/plugins/apm/server/lib/observability_dashboard/get_transaction_coordinates.ts
This file contains hidden or 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,57 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| /* | ||
| * 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 { rangeFilter } from '../../../common/utils/range_filter'; | ||
| import { Coordinates } from '../../../../observability/public/typings/fetch_data_response'; | ||
| import { PROCESSOR_EVENT } from '../../../common/elasticsearch_fieldnames'; | ||
| import { Setup, SetupTimeRange } from '../helpers/setup_request'; | ||
| import { ProcessorEvent } from '../../../common/processor_event'; | ||
|
|
||
| export async function getTransactionCoordinates({ | ||
| setup, | ||
| bucketSize, | ||
| }: { | ||
| setup: Setup & SetupTimeRange; | ||
| bucketSize: string; | ||
| }): Promise<Coordinates[]> { | ||
| const { client, indices, start, end } = setup; | ||
|
|
||
| const { aggregations } = await client.search({ | ||
| index: indices['apm_oss.transactionIndices'], | ||
| body: { | ||
| size: 0, | ||
| query: { | ||
| bool: { | ||
| filter: [ | ||
| { term: { [PROCESSOR_EVENT]: ProcessorEvent.transaction } }, | ||
sorenlouv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { range: rangeFilter(start, end) }, | ||
| ], | ||
| }, | ||
| }, | ||
| aggs: { | ||
| distribution: { | ||
| date_histogram: { | ||
| field: '@timestamp', | ||
| fixed_interval: bucketSize, | ||
| min_doc_count: 0, | ||
| extended_bounds: { min: start, max: end }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| return ( | ||
| aggregations?.distribution.buckets.map((bucket) => ({ | ||
| x: bucket.key, | ||
| y: bucket.doc_count, | ||
| })) || [] | ||
| ); | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
x-pack/plugins/apm/server/lib/observability_dashboard/has_data.ts
This file contains hidden or 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,26 @@ | ||
| /* | ||
| * 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 { Setup } from '../helpers/setup_request'; | ||
|
|
||
| export async function hasData({ setup }: { setup: Setup }) { | ||
| const { client, indices } = setup; | ||
| try { | ||
| const params = { | ||
| index: [ | ||
| indices['apm_oss.transactionIndices'], | ||
| indices['apm_oss.errorIndices'], | ||
| indices['apm_oss.metricsIndices'], | ||
| ], | ||
| terminateAfter: 1, | ||
| size: 0, | ||
| }; | ||
|
|
||
| const response = await client.search(params); | ||
| return response.hits.total.value > 0; | ||
| } catch (e) { | ||
| return false; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.