-
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.
[APM] Include services with only metric documents
Closes #92075.
- Loading branch information
1 parent
4ab0277
commit 3bf2864
Showing
6 changed files
with
231 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export function asMutableArray<T extends Readonly<any>>( | ||
arr: T | ||
): T extends Readonly<[...infer U]> ? U : unknown[] { | ||
return arr as any; | ||
} |
56 changes: 55 additions & 1 deletion
56
x-pack/plugins/apm/server/lib/services/__snapshots__/queries.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
82 changes: 82 additions & 0 deletions
82
x-pack/plugins/apm/server/lib/services/get_services/get_services_from_metric_documents.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,82 @@ | ||
/* | ||
* 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 { AgentName } from '../../../../typings/es_schemas/ui/fields/agent'; | ||
import { | ||
AGENT_NAME, | ||
SERVICE_ENVIRONMENT, | ||
SERVICE_NAME, | ||
} from '../../../../common/elasticsearch_fieldnames'; | ||
import { environmentQuery, rangeQuery } from '../../../../common/utils/queries'; | ||
import { ProcessorEvent } from '../../../../common/processor_event'; | ||
import { Setup, SetupTimeRange } from '../../helpers/setup_request'; | ||
import { withApmSpan } from '../../../utils/with_apm_span'; | ||
|
||
export function getServicesFromMetricDocuments({ | ||
environment, | ||
setup, | ||
maxNumServices, | ||
}: { | ||
setup: Setup & SetupTimeRange; | ||
environment?: string; | ||
maxNumServices: number; | ||
}) { | ||
return withApmSpan('get_services_from_metric_documents', async () => { | ||
const { apmEventClient, start, end, esFilter } = setup; | ||
|
||
const response = await apmEventClient.search({ | ||
apm: { | ||
events: [ProcessorEvent.metric], | ||
}, | ||
body: { | ||
size: 0, | ||
query: { | ||
bool: { | ||
filter: [ | ||
...rangeQuery(start, end), | ||
...environmentQuery(environment), | ||
...esFilter, | ||
], | ||
}, | ||
}, | ||
aggs: { | ||
services: { | ||
terms: { | ||
field: SERVICE_NAME, | ||
size: maxNumServices, | ||
}, | ||
aggs: { | ||
environments: { | ||
terms: { | ||
field: SERVICE_ENVIRONMENT, | ||
}, | ||
}, | ||
latest: { | ||
top_metrics: { | ||
metrics: { field: AGENT_NAME } as const, | ||
sort: { '@timestamp': 'desc' }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
return ( | ||
response.aggregations?.services.buckets.map((bucket) => { | ||
return { | ||
serviceName: bucket.key as string, | ||
environments: bucket.environments.buckets.map( | ||
(envBucket) => envBucket.key as string | ||
), | ||
agentName: bucket.latest.top[0].metrics[AGENT_NAME] as AgentName, | ||
}; | ||
}) ?? [] | ||
); | ||
}); | ||
} |
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