-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[APM] Service groups - dynamic query refresh #140406
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
Changes from all commits
6469b13
1f0ad50
7a201df
8cd4942
c95ec06
a0275e5
d749c1a
9916a7d
e8ba4a0
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,6 +39,13 @@ const MAX_CONTAINER_HEIGHT = 600; | |||||||||||||
| const MODAL_HEADER_HEIGHT = 122; | ||||||||||||||
| const MODAL_FOOTER_HEIGHT = 80; | ||||||||||||||
|
|
||||||||||||||
| const suggestedFieldsWhitelist = [ | ||||||||||||||
| 'agent.name', | ||||||||||||||
| 'service.name', | ||||||||||||||
| 'service.language.name', | ||||||||||||||
| 'service.environment', | ||||||||||||||
| ]; | ||||||||||||||
|
|
||||||||||||||
| const Container = styled.div` | ||||||||||||||
| width: 600px; | ||||||||||||||
| height: ${MAX_CONTAINER_HEIGHT}px; | ||||||||||||||
|
|
@@ -144,6 +151,21 @@ export function SelectServices({ | |||||||||||||
| setStagedKuery(value); | ||||||||||||||
| }} | ||||||||||||||
| value={kuery} | ||||||||||||||
| suggestionFilter={(querySuggestion) => { | ||||||||||||||
| if ('field' in querySuggestion) { | ||||||||||||||
| const { | ||||||||||||||
| field: { | ||||||||||||||
| spec: { name: fieldName }, | ||||||||||||||
| }, | ||||||||||||||
| } = querySuggestion; | ||||||||||||||
|
Comment on lines
+156
to
+160
Contributor
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. nit: this is 100% personal preference but my brain always struggle a bit with nested destructurings. Feel free to leave as-is if you prefer that.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| return ( | ||||||||||||||
| fieldName.startsWith('label') || | ||||||||||||||
| suggestedFieldsWhitelist.includes(fieldName) | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| return true; | ||||||||||||||
| }} | ||||||||||||||
| /> | ||||||||||||||
| </EuiFlexItem> | ||||||||||||||
| <EuiFlexItem grow={false}> | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,12 @@ import { | |
| } from '@elastic/eui'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { isEmpty, sortBy } from 'lodash'; | ||
| import React, { useState, useCallback } from 'react'; | ||
| import React, { useState, useCallback, useMemo } from 'react'; | ||
| import { FETCH_STATUS, useFetcher } from '../../../../hooks/use_fetcher'; | ||
| import { ServiceGroupsListItems } from './service_groups_list'; | ||
| import { Sort } from './sort'; | ||
| import { RefreshServiceGroupsSubscriber } from '../refresh_service_groups_subscriber'; | ||
| import { getDateRange } from '../../../../context/url_params_context/helpers'; | ||
|
|
||
| export type ServiceGroupsSortType = 'recently_added' | 'alphabetical'; | ||
|
|
||
|
|
@@ -38,6 +39,31 @@ export function ServiceGroupsList() { | |
| [] | ||
| ); | ||
|
|
||
| const { start, end } = useMemo( | ||
| () => | ||
| getDateRange({ | ||
| rangeFrom: 'now-24h', | ||
| rangeTo: 'now', | ||
| }), | ||
| [] | ||
| ); | ||
|
Comment on lines
+42
to
+49
Contributor
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. This is on the service group overview page (aka the page listing all the service groups), right? @gbamparop and I talked about that we didn't currently have a timepicker, and we didn't see any need to add any. It also means that the lookback time-period for calculating the service counts is hardcoded to 24 hours. I think this is a fine compromise between simplicity and functionality. But we should remember to flag this to product (and possible docs to document it).
Contributor
Author
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. Correct, this is on the service group overview page. |
||
|
|
||
| const { data: servicesCountData = { servicesCounts: {} } } = useFetcher( | ||
| (callApmApi) => { | ||
| if (start && end) { | ||
| return callApmApi('GET /internal/apm/service_groups/services_count', { | ||
| params: { | ||
| query: { | ||
| start, | ||
| end, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
| }, | ||
| [start, end] | ||
| ); | ||
|
|
||
| const { serviceGroups } = data; | ||
|
|
||
| const isLoading = | ||
|
|
@@ -133,7 +159,11 @@ export function ServiceGroupsList() { | |
| </EuiFlexItem> | ||
| <EuiFlexItem> | ||
| {items.length ? ( | ||
| <ServiceGroupsListItems items={items} isLoading={isLoading} /> | ||
| <ServiceGroupsListItems | ||
| items={items} | ||
| servicesCounts={servicesCountData.servicesCounts} | ||
| isLoading={isLoading} | ||
| /> | ||
| ) : ( | ||
| <EuiEmptyPrompt | ||
| iconType="layers" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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 { ProcessorEvent } from '@kbn/observability-plugin/common'; | ||
| import { rangeQuery, kqlQuery } from '@kbn/observability-plugin/server'; | ||
| import { Setup } from '../../lib/helpers/setup_request'; | ||
| import { SERVICE_NAME } from '../../../common/elasticsearch_fieldnames'; | ||
|
|
||
| export async function getServicesCounts({ | ||
| setup, | ||
| kuery, | ||
| maxNumberOfServices, | ||
| start, | ||
| end, | ||
| }: { | ||
| setup: Setup; | ||
| kuery: string; | ||
| maxNumberOfServices: number; | ||
|
Contributor
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. Is
Contributor
Author
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. It is unused, we can add a size (service inventory and service map already have max size specified). |
||
| start: number; | ||
| end: number; | ||
| }) { | ||
| const { apmEventClient } = setup; | ||
|
|
||
| const response = await apmEventClient.search('get_services_count', { | ||
| apm: { | ||
| events: [ | ||
| ProcessorEvent.metric, | ||
| ProcessorEvent.transaction, | ||
| ProcessorEvent.span, | ||
| ProcessorEvent.error, | ||
| ], | ||
| }, | ||
| body: { | ||
| size: 0, | ||
| query: { | ||
| bool: { | ||
| filter: [...rangeQuery(start, end), ...kqlQuery(kuery)], | ||
| }, | ||
| }, | ||
| aggs: { | ||
| services_count: { | ||
| cardinality: { | ||
| field: SERVICE_NAME, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| return response?.aggregations?.services_count.value ?? 0; | ||
| } | ||
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.
Can you use allowlist here?