-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Infra] apm_data_access service to return host names (#189894)
closes [#188752](#188752) ## Summary This PR creates a service that will return host names collected by APM. **NOTE**: At first, we'll use this service to join the host names from APM with metrics collected by the system module to build the hosts with metrics lists - not necessarily to be used in the total hosts count functionality. This service may be adjusted as we start using it in Infra. --------- Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
beef9ba
commit b265604
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...ck/plugins/observability_solution/apm_data_access/server/services/get_host_names/index.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,66 @@ | ||
/* | ||
* 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 { estypes } from '@elastic/elasticsearch'; | ||
import { rangeQuery } from '@kbn/observability-plugin/server'; | ||
import { HOST_NAME } from '@kbn/apm-types/es_fields'; | ||
import { getBucketSize, type TimeRangeMetadata } from '../../../common'; | ||
import { getPreferredBucketSizeAndDataSource } from '../../../common/utils/get_preferred_bucket_size_and_data_source'; | ||
import { ApmDocumentType } from '../../../common/document_type'; | ||
import type { ApmDataAccessServicesParams } from '../get_services'; | ||
|
||
const MAX_SIZE = 1000; | ||
|
||
export interface HostNamesRequest { | ||
query: estypes.QueryDslQueryContainer; | ||
kuery?: string; | ||
start: number; | ||
end: number; | ||
size?: number; | ||
documentSources: TimeRangeMetadata['sources']; | ||
} | ||
|
||
const suitableTypes = [ApmDocumentType.TransactionMetric]; | ||
|
||
export function createGetHostNames({ apmEventClient }: ApmDataAccessServicesParams) { | ||
return async ({ start, end, size = MAX_SIZE, query, documentSources }: HostNamesRequest) => { | ||
const sourcesToUse = getPreferredBucketSizeAndDataSource({ | ||
sources: documentSources.filter((s) => suitableTypes.includes(s.documentType)), | ||
bucketSizeInSeconds: getBucketSize({ start, end, numBuckets: 50 }).bucketSize, | ||
}); | ||
|
||
const esResponse = await apmEventClient.search('get_apm_host_names', { | ||
apm: { | ||
sources: [ | ||
{ | ||
documentType: sourcesToUse.source.documentType, | ||
rollupInterval: sourcesToUse.source.rollupInterval, | ||
}, | ||
], | ||
}, | ||
body: { | ||
track_total_hits: false, | ||
size: 0, | ||
query: { | ||
bool: { | ||
filter: [query, ...rangeQuery(start, end)], | ||
}, | ||
}, | ||
aggs: { | ||
hostNames: { | ||
terms: { | ||
field: HOST_NAME, | ||
size: Math.min(size, MAX_SIZE), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
return esResponse.aggregations?.hostNames.buckets.map((bucket) => bucket.key as string) ?? []; | ||
}; | ||
} |
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