diff --git a/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_es_usage.ts b/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_es_usage.ts index 4f6b67452b101..fbb4daba34532 100644 --- a/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_es_usage.ts +++ b/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_es_usage.ts @@ -7,7 +7,7 @@ import { ElasticsearchClient } from '@kbn/core/server'; import { get } from 'lodash'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { StackProductUsage } from '../types'; interface ESIndicesBucket { @@ -37,49 +37,47 @@ export async function fetchESUsage( 'hits.hits._source.cluster_stats.nodes.count.total', 'aggregations.indices.buckets', ], - body: { - size: 1, - sort: [ - { - timestamp: { - order: 'desc', - unmapped_type: 'long', - }, + size: 1, + sort: [ + { + timestamp: { + order: 'desc', + unmapped_type: 'long', }, - ], - query: { - bool: { - must: [ - { - term: { - type: { - value: 'cluster_stats', - }, + }, + ], + query: { + bool: { + must: [ + { + term: { + type: { + value: 'cluster_stats', }, }, - { - term: { - cluster_uuid: { - value: clusterUuid, - }, + }, + { + term: { + cluster_uuid: { + value: clusterUuid, }, }, - { - range: { - timestamp: { - gte: 'now-1h', - }, + }, + { + range: { + timestamp: { + gte: 'now-1h', }, }, - ], - }, - }, - aggs: { - indices: { - terms: { - field: '_index', - size: 2, }, + ], + }, + }, + aggs: { + indices: { + terms: { + field: '_index', + size: 2, }, }, }, diff --git a/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_license_type.ts b/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_license_type.ts index 86761262c886f..4d30e4f0b021b 100644 --- a/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_license_type.ts +++ b/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_license_type.ts @@ -7,7 +7,7 @@ import { get } from 'lodash'; import { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../common/constants'; import { getCcsIndexPattern } from '../../../lib/alerts/get_ccs_index_pattern'; @@ -23,35 +23,33 @@ export async function fetchLicenseType( const params: estypes.SearchRequest = { index, filter_path: ['hits.hits._source.license'], - body: { - size: 1, - sort: [ - { - timestamp: { - order: 'desc', - unmapped_type: 'long', - }, + size: 1, + sort: [ + { + timestamp: { + order: 'desc', + unmapped_type: 'long', }, - ], - query: { - bool: { - must: [ - { - term: { - cluster_uuid: { - value: clusterUuid, - }, + }, + ], + query: { + bool: { + must: [ + { + term: { + cluster_uuid: { + value: clusterUuid, }, }, - { - term: { - type: { - value: 'cluster_stats', - }, + }, + { + term: { + type: { + value: 'cluster_stats', }, }, - ], - }, + }, + ], }, }, }; diff --git a/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_stack_product_usage.test.ts b/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_stack_product_usage.test.ts index 3daf0c511139f..1bd7b8ba31f96 100644 --- a/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_stack_product_usage.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_stack_product_usage.test.ts @@ -54,10 +54,10 @@ describe('fetchStackProductUsage', () => { ] ); const params = searchMock.mock.calls[0][0]; - expect(params.body.query.bool.must[0].term.type.value).toBe('kibana_stats'); - expect(params.body.query.bool.must[1].term.cluster_uuid.value).toBe(clusterUuid); - expect(params.body.query.bool.must[2].range.timestamp.gte).toBe('now-1h'); - expect(params.body.query.bool.must[3].term.type.value).toBe('foo'); + expect(params.query.bool.must[0].term.type.value).toBe('kibana_stats'); + expect(params.query.bool.must[1].term.cluster_uuid.value).toBe(clusterUuid); + expect(params.query.bool.must[2].range.timestamp.gte).toBe('now-1h'); + expect(params.query.bool.must[3].term.type.value).toBe('foo'); }); it('should get the usage data', async () => { diff --git a/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_stack_product_usage.ts b/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_stack_product_usage.ts index 90ec4aedd67e8..bfce72d885a0b 100644 --- a/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_stack_product_usage.ts +++ b/x-pack/platform/plugins/private/monitoring/server/kibana_monitoring/collectors/lib/fetch_stack_product_usage.ts @@ -7,7 +7,7 @@ import { get } from 'lodash'; import { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { MonitoringConfig } from '../../../config'; import { StackProductUsage } from '../types'; @@ -44,48 +44,46 @@ export async function fetchStackProductUsage( index, ignore_unavailable: true, filter_path: ['aggregations.uuids.buckets'], - body: { - size: 0, - query: { - bool: { - must: [ - { - term: { - type: { - value: type, - }, + size: 0, + query: { + bool: { + must: [ + { + term: { + type: { + value: type, }, }, - { - term: { - cluster_uuid: { - value: clusterUuid, - }, + }, + { + term: { + cluster_uuid: { + value: clusterUuid, }, }, - { - range: { - timestamp: { - gte: 'now-1h', - }, + }, + { + range: { + timestamp: { + gte: 'now-1h', }, }, - ...filters, - ], - }, - }, - aggs: { - uuids: { - terms: { - field: uuidPath, - size, }, - aggs: { - indices: { - terms: { - field: '_index', - size: 2, - }, + ...filters, + ], + }, + }, + aggs: { + uuids: { + terms: { + field: uuidPath, + size, + }, + aggs: { + indices: { + terms: { + field: '_index', + size: 2, }, }, }, diff --git a/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_available_ccs.test.ts b/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_available_ccs.test.ts index 2fbaac7549ce3..dfedc24122917 100644 --- a/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_available_ccs.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_available_ccs.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; import { fetchAvailableCcs } from './fetch_available_ccs'; diff --git a/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_cluster_health.test.ts b/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_cluster_health.test.ts index 1dc192b2ed92b..fa61cfa3e00f5 100644 --- a/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_cluster_health.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_cluster_health.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; import { fetchClusterHealth } from './fetch_cluster_health'; diff --git a/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_clusters.test.ts b/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_clusters.test.ts index 2e6f2c1daf959..b2366fbccb424 100644 --- a/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_clusters.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_clusters.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; import { fetchClusters } from './fetch_clusters'; diff --git a/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_cpu_usage_node_stats.test.ts b/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_cpu_usage_node_stats.test.ts index ddd9b79d09cb4..8981f336ff90c 100644 --- a/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_cpu_usage_node_stats.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_cpu_usage_node_stats.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; import { fetchCpuUsageNodeStats } from './fetch_cpu_usage_node_stats'; diff --git a/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_elasticsearch_versions.test.ts b/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_elasticsearch_versions.test.ts index ff41b38c130ea..440f0654e9944 100644 --- a/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_elasticsearch_versions.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/lib/alerts/fetch_elasticsearch_versions.test.ts @@ -7,7 +7,7 @@ import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; import { fetchElasticsearchVersions } from './fetch_elasticsearch_versions'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; jest.mock('../../static_globals', () => ({ Globals: { diff --git a/x-pack/platform/plugins/private/monitoring/server/lib/elasticsearch_settings/cluster.test.ts b/x-pack/platform/plugins/private/monitoring/server/lib/elasticsearch_settings/cluster.test.ts index 985ad2357648a..79587fae24e8a 100644 --- a/x-pack/platform/plugins/private/monitoring/server/lib/elasticsearch_settings/cluster.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/lib/elasticsearch_settings/cluster.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { ClusterGetSettingsResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { ClusterGetSettingsResponse } from '@elastic/elasticsearch/lib/api/types'; import { checkClusterSettings } from '.'; import { LegacyRequest } from '../../types'; diff --git a/x-pack/platform/plugins/private/monitoring/server/lib/elasticsearch_settings/cluster.ts b/x-pack/platform/plugins/private/monitoring/server/lib/elasticsearch_settings/cluster.ts index e4433d700aad5..f42defa5ea013 100644 --- a/x-pack/platform/plugins/private/monitoring/server/lib/elasticsearch_settings/cluster.ts +++ b/x-pack/platform/plugins/private/monitoring/server/lib/elasticsearch_settings/cluster.ts @@ -6,7 +6,7 @@ */ import { get } from 'lodash'; -import { ClusterGetSettingsResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { ClusterGetSettingsResponse } from '@elastic/elasticsearch/lib/api/types'; import { findReason } from './find_reason'; import { ClusterSettingsReasonResponse, LegacyRequest } from '../../types'; diff --git a/x-pack/platform/plugins/private/monitoring/server/routes/api/v1/elasticsearch_settings/check/internal_monitoring.ts b/x-pack/platform/plugins/private/monitoring/server/routes/api/v1/elasticsearch_settings/check/internal_monitoring.ts index 65726a56d8473..824efa62e7a26 100644 --- a/x-pack/platform/plugins/private/monitoring/server/routes/api/v1/elasticsearch_settings/check/internal_monitoring.ts +++ b/x-pack/platform/plugins/private/monitoring/server/routes/api/v1/elasticsearch_settings/check/internal_monitoring.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { RequestHandlerContext } from '@kbn/core/server'; import { prefixIndexPatternWithCcs } from '../../../../../../common/ccs_utils'; import { diff --git a/x-pack/platform/plugins/private/monitoring/server/static_globals.ts b/x-pack/platform/plugins/private/monitoring/server/static_globals.ts index 429ec8693a3e7..2bcacb5c45a9a 100644 --- a/x-pack/platform/plugins/private/monitoring/server/static_globals.ts +++ b/x-pack/platform/plugins/private/monitoring/server/static_globals.ts @@ -6,7 +6,7 @@ */ import { CoreSetup, ElasticsearchClient, Logger, PluginInitializerContext } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { MonitoringConfig } from './config'; import { PluginsSetup } from './types'; import { mbSafeQuery } from './lib/mb_safe_query'; diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_beats_stats.test.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_beats_stats.test.ts index 879b5fcd3d6bb..8394842364f99 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_beats_stats.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_beats_stats.test.ts @@ -37,7 +37,7 @@ describe('Get Beats Stats', () => { searchMock.returns(Promise.resolve({})); await fetchBeatsStats(callCluster, clusterUuids, start, end, {} as any); const { args } = searchMock.firstCall; - const [{ body }] = args; + const [body] = args; expect(body.from).toEqual(0); expect(body.size).toEqual(10000); @@ -47,7 +47,7 @@ describe('Get Beats Stats', () => { searchMock.returns(Promise.resolve({})); await fetchBeatsStats(callCluster, clusterUuids, start, end, { page: 1 } as any); const { args } = searchMock.firstCall; - const [{ body }] = args; + const [body] = args; expect(body.from).toEqual(10000); expect(body.size).toEqual(10000); @@ -57,7 +57,7 @@ describe('Get Beats Stats', () => { searchMock.returns(Promise.resolve({})); await fetchBeatsStats(callCluster, clusterUuids, start, end, { page: 2 } as any); const { args } = searchMock.firstCall; - const [{ body }] = args; + const [body] = args; expect(body.from).toEqual(20000); expect(body.size).toEqual(10000); diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_beats_stats.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_beats_stats.ts index 9a0a8bba0153d..109b1485f8a40 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_beats_stats.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_beats_stats.ts @@ -7,7 +7,7 @@ import { get } from 'lodash'; import { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { createQuery } from './create_query'; import { INDEX_PATTERN_BEATS } from '../../common/constants'; @@ -340,25 +340,23 @@ async function fetchBeatsByType( 'hits.hits._source.beats_state.state', 'hits.hits._source.beats_state.beat.type', ], - body: { - query: createQuery({ - start, - end, - filters: [ - { terms: { cluster_uuid: clusterUuids } }, - { - bool: { - must_not: { term: { [`${type}.beat.type`]: 'apm-server' } }, - must: { term: { type } }, - }, + query: createQuery({ + start, + end, + filters: [ + { terms: { cluster_uuid: clusterUuids } }, + { + bool: { + must_not: { term: { [`${type}.beat.type`]: 'apm-server' } }, + must: { term: { type } }, }, - ], - }) as estypes.QueryDslQueryContainer, - from: page * HITS_SIZE, - collapse: { field: `${type}.beat.uuid` }, - sort: [{ [`${type}.timestamp`]: { order: 'desc', unmapped_type: 'long' } }], - size: HITS_SIZE, - }, + }, + ], + }) as estypes.QueryDslQueryContainer, + from: page * HITS_SIZE, + collapse: { field: `${type}.beat.uuid` }, + sort: [{ [`${type}.timestamp`]: { order: 'desc', unmapped_type: 'long' } }], + size: HITS_SIZE, }; const results = await callCluster.search(params); diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_cluster_uuids.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_cluster_uuids.ts index ed553c3ca4e1c..ffd4c7dbe49f8 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_cluster_uuids.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_cluster_uuids.ts @@ -8,7 +8,7 @@ import { get } from 'lodash'; import moment from 'moment'; import { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { createQuery } from './create_query'; import { INDEX_PATTERN_ELASTICSEARCH, @@ -43,29 +43,27 @@ export async function fetchClusterUuids( index: INDEX_PATTERN_ELASTICSEARCH, ignore_unavailable: true, filter_path: 'aggregations.cluster_uuids.buckets.key', - body: { - size: 0, - query: createQuery({ - start, - end, - filters: [ - { - bool: { - should: [ - { term: { type: 'cluster_stats' } }, - { term: { 'metricset.name': 'cluster_stats' } }, - ], - }, - }, - ], - }) as estypes.QueryDslQueryContainer, - aggs: { - cluster_uuids: { - terms: { - field: 'cluster_uuid', - size: maxBucketSize, + size: 0, + query: createQuery({ + start, + end, + filters: [ + { + bool: { + should: [ + { term: { type: 'cluster_stats' } }, + { term: { 'metricset.name': 'cluster_stats' } }, + ], }, }, + ], + }) as estypes.QueryDslQueryContainer, + aggs: { + cluster_uuids: { + terms: { + field: 'cluster_uuid', + size: maxBucketSize, + }, }, }, }; diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_es_stats.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_es_stats.ts index 4eecebdb177fc..ba977d78a3f2e 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_es_stats.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_es_stats.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import moment from 'moment'; import { INDEX_PATTERN_ELASTICSEARCH } from '../../common/constants'; @@ -66,39 +66,37 @@ export async function fetchElasticsearchStats( 'hits.hits._source.stack_stats', 'hits.hits._source.elasticsearch', ], - body: { - size: maxBucketSize, - query: { - bool: { - filter: [ - /* - * Note: Unlike most places, we don't care about the old _type: cluster_stats because it would NOT - * have the license in it (that used to be in the .monitoring-data-2 index in cluster_info) - */ - { - bool: { - should: [ - { term: { type: 'cluster_stats' } }, - { term: { 'metricset.name': 'cluster_stats' } }, - ], - }, + size: maxBucketSize, + query: { + bool: { + filter: [ + /* + * Note: Unlike most places, we don't care about the old _type: cluster_stats because it would NOT + * have the license in it (that used to be in the .monitoring-data-2 index in cluster_info) + */ + { + bool: { + should: [ + { term: { type: 'cluster_stats' } }, + { term: { 'metricset.name': 'cluster_stats' } }, + ], }, - { terms: { cluster_uuid: clusterUuids } }, - { - range: { - timestamp: { - format: 'epoch_millis', - gte: moment.utc(start).valueOf(), - lte: moment.utc(end).valueOf(), - }, + }, + { terms: { cluster_uuid: clusterUuids } }, + { + range: { + timestamp: { + format: 'epoch_millis', + gte: moment.utc(start).valueOf(), + lte: moment.utc(end).valueOf(), }, }, - ], - }, + }, + ], }, - collapse: { field: 'cluster_uuid' }, - sort: { timestamp: { order: 'desc', unmapped_type: 'long' } }, }, + collapse: { field: 'cluster_uuid' }, + sort: { timestamp: { order: 'desc', unmapped_type: 'long' } }, }; return await callCluster.search(params); diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_high_level_stats.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_high_level_stats.ts index e8b53a1ed1adc..0f9aa4647d036 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_high_level_stats.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_high_level_stats.ts @@ -7,7 +7,7 @@ import { get } from 'lodash'; import { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { createQuery } from './create_query'; import { INDEX_PATTERN_KIBANA, @@ -317,20 +317,18 @@ export async function fetchHighLevelStats< `hits.hits._source.${product}_stats.cloud.region`, `hits.hits._source.${product}_stats.cloud.zone`, ], - body: { - size: maxBucketSize, - query: createQuery({ - start, - end, - type: `${product}_stats`, - filters, - }) as estypes.QueryDslQueryContainer, - collapse: { - // a more ideal field would be the concatenation of the uuid + transport address for duped UUIDs (copied installations) - field: `${product}_stats.${product}.uuid`, - }, - sort: [{ timestamp: { order: 'desc', unmapped_type: 'long' } }], + size: maxBucketSize, + query: createQuery({ + start, + end, + type: `${product}_stats`, + filters, + }) as estypes.QueryDslQueryContainer, + collapse: { + // a more ideal field would be the concatenation of the uuid + transport address for duped UUIDs (copied installations) + field: `${product}_stats.${product}.uuid`, }, + sort: [{ timestamp: { order: 'desc', unmapped_type: 'long' } }], }; const response = await callCluster.search(params, { diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_kibana_stats.test.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_kibana_stats.test.ts index 5474880986238..35480cc6b5c98 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_kibana_stats.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_kibana_stats.test.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { getUsageStats, combineStats, diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_kibana_stats.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_kibana_stats.ts index cc6a23a0646e1..6ac30711aff58 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_kibana_stats.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_kibana_stats.ts @@ -7,7 +7,7 @@ import moment from 'moment'; import { isEmpty } from 'lodash'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { ElasticsearchClient } from '@kbn/core/server'; import { KIBANA_SYSTEM_ID, TELEMETRY_COLLECTION_INTERVAL } from '../../common/constants'; import { diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_licenses.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_licenses.ts index 98f3932984546..9a3d1f41cec5e 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_licenses.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/get_licenses.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { LicenseGetLicenseInformation } from '@elastic/elasticsearch/lib/api/types'; import { INDEX_PATTERN_ELASTICSEARCH, USAGE_FETCH_INTERVAL } from '../../common/constants'; @@ -42,32 +42,30 @@ export async function fetchLicenses( index: INDEX_PATTERN_ELASTICSEARCH, ignore_unavailable: true, filter_path: ['hits.hits._source.cluster_uuid', 'hits.hits._source.license'], - body: { - size: maxBucketSize, - query: { - bool: { - filter: [ - /* - * Note: Unlike most places, we don't care about the old _type: cluster_stats because it would NOT - * have the license in it (that used to be in the .monitoring-data-2 index in cluster_info) - */ - { term: { type: 'cluster_stats' } }, - { terms: { cluster_uuid: clusterUuids } }, - { - range: { - timestamp: { - format: 'epoch_millis', - gte: timestamp - USAGE_FETCH_INTERVAL, - lte: timestamp, - }, + size: maxBucketSize, + query: { + bool: { + filter: [ + /* + * Note: Unlike most places, we don't care about the old _type: cluster_stats because it would NOT + * have the license in it (that used to be in the .monitoring-data-2 index in cluster_info) + */ + { term: { type: 'cluster_stats' } }, + { terms: { cluster_uuid: clusterUuids } }, + { + range: { + timestamp: { + format: 'epoch_millis', + gte: timestamp - USAGE_FETCH_INTERVAL, + lte: timestamp, }, }, - ], - }, + }, + ], }, - collapse: { field: 'cluster_uuid' }, - sort: { timestamp: { order: 'desc', unmapped_type: 'long' } }, }, + collapse: { field: 'cluster_uuid' }, + sort: { timestamp: { order: 'desc', unmapped_type: 'long' } }, }; return await callCluster.search(params); diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_agent_monitoring.test.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_agent_monitoring.test.ts index 7bce1a37158c9..f383520b8324a 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_agent_monitoring.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_agent_monitoring.test.ts @@ -82,7 +82,7 @@ describe('LogstashAgentMonitoring', () => { {} as any ); const { args } = searchMock.firstCall; - const [{ body }] = args; + const [body] = args; expect(body.from).toEqual(0); expect(body.size).toEqual(10000); @@ -125,7 +125,7 @@ describe('LogstashAgentMonitoring', () => { {} as any ); const { args } = searchMock.firstCall; - const [{ body }] = args; + const [body] = args; expect(body.query).toEqual(expected); }); }); diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_agent_monitoring.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_agent_monitoring.ts index 9c40bf11b67e5..d80eb0fcee832 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_agent_monitoring.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_agent_monitoring.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import moment from 'moment'; import { createQuery } from './create_query'; import { mapToList } from './get_high_level_stats'; @@ -201,32 +201,30 @@ export class LogstashAgentMonitoring implements LogstashMonitoring { index: INDEX_PATTERN_LOGSTASH_METRICS_NODE, ignore_unavailable: true, filter_path: filterPath, - body: { - query: createQuery({ - filters: [ - { - bool: { - should: [{ term: { 'data_stream.dataset': 'logstash.node' } }], - }, + query: createQuery({ + filters: [ + { + bool: { + should: [{ term: { 'data_stream.dataset': 'logstash.node' } }], }, - { - range: { - '@timestamp': { - format: 'epoch_millis', - gte: moment.utc(start).valueOf(), - lte: moment.utc(end).valueOf(), - }, + }, + { + range: { + '@timestamp': { + format: 'epoch_millis', + gte: moment.utc(start).valueOf(), + lte: moment.utc(end).valueOf(), }, }, - ], - }) as estypes.QueryDslQueryContainer, - collapse: { - field: 'host.id', - }, - sort: [{ '@timestamp': { order: 'desc', unmapped_type: 'long' } }], - from: page * HITS_SIZE, - size: HITS_SIZE, + }, + ], + }) as estypes.QueryDslQueryContainer, + collapse: { + field: 'host.id', }, + sort: [{ '@timestamp': { order: 'desc', unmapped_type: 'long' } }], + from: page * HITS_SIZE, + size: HITS_SIZE, }; const results = await callCluster.search(params, { @@ -284,14 +282,12 @@ export class LogstashAgentMonitoring implements LogstashMonitoring { index: INDEX_PATTERN_LOGSTASH_METRICS_PLUGINS, ignore_unavailable: true, filter_path: ['hits.hits._source.logstash.pipeline'], - body: { - query: createQuery({ - filters, - }) as estypes.QueryDslQueryContainer, - collapse: { field: `logstash.pipeline.plugin.${pluginType}.id` }, - sort: [{ '@timestamp': { order: 'desc', unmapped_type: 'long' } }], - size: HITS_SIZE, - }, + query: createQuery({ + filters, + }) as estypes.QueryDslQueryContainer, + collapse: { field: `logstash.pipeline.plugin.${pluginType}.id` }, + sort: [{ '@timestamp': { order: 'desc', unmapped_type: 'long' } }], + size: HITS_SIZE, }; const results = await callCluster.search(params, { diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_metricbeat_monitoring.test.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_metricbeat_monitoring.test.ts index 4142ee74ddf70..da8f9aaaa12b6 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_metricbeat_monitoring.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_metricbeat_monitoring.test.ts @@ -100,7 +100,7 @@ describe('LogstashMetricbeatMonitoring', () => { {} as any ); const { args } = searchMock.firstCall; - const [{ body }] = args; + const [body] = args; expect(body.from).toEqual(0); expect(body.size).toEqual(10000); @@ -137,7 +137,7 @@ describe('LogstashMetricbeatMonitoring', () => { {} as any ); const { args } = searchMock.firstCall; - const [{ body }] = args; + const [body] = args; expect(body.query).toEqual(expected); }); }); diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_metricbeat_monitoring.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_metricbeat_monitoring.ts index c00c37ad59784..b3b1f9910a559 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_metricbeat_monitoring.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_metricbeat_monitoring.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { createQuery } from './create_query'; import { mapToList } from './get_high_level_stats'; import { incrementByKey } from './get_high_level_stats'; @@ -271,28 +271,26 @@ export class LogstashMetricbeatMonitoring implements LogstashMonitoring { index: this.indexPattern.stats, ignore_unavailable: true, filter_path: filterPath, - body: { - query: createQuery({ - start, - end, - filters: [ - { - bool: { - should: [ - { term: { 'metricset.name': 'node_stats' } }, - { term: { 'data_stream.dataset': 'logstash.stack_monitoring.node_stats' } }, - ], - }, + query: createQuery({ + start, + end, + filters: [ + { + bool: { + should: [ + { term: { 'metricset.name': 'node_stats' } }, + { term: { 'data_stream.dataset': 'logstash.stack_monitoring.node_stats' } }, + ], }, - ], - }) as estypes.QueryDslQueryContainer, - collapse: { - field: 'logstash.node.stats.logstash.uuid', - }, - sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }], - from: page * HITS_SIZE, - size: HITS_SIZE, + }, + ], + }) as estypes.QueryDslQueryContainer, + collapse: { + field: 'logstash.node.stats.logstash.uuid', }, + sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }], + from: page * HITS_SIZE, + size: HITS_SIZE, }; const results = await callCluster.search(params, { @@ -335,28 +333,26 @@ export class LogstashMetricbeatMonitoring implements LogstashMonitoring { index: this.indexPattern.state, ignore_unavailable: true, filter_path: filterPath, - body: { - query: createQuery({ - // metricbeat occasionally sends state metrics - // so, not using start and end periods as we need node state info to fill plugin usages - filters: [ - { terms: { 'logstash.node.state.pipeline.ephemeral_id': ephemeralIds } }, - { - bool: { - should: [ - { term: { 'metricset.name': 'node' } }, - { term: { 'data_stream.dataset': 'logstash.stack_monitoring.node' } }, - ], - }, + query: createQuery({ + // metricbeat occasionally sends state metrics + // so, not using start and end periods as we need node state info to fill plugin usages + filters: [ + { terms: { 'logstash.node.state.pipeline.ephemeral_id': ephemeralIds } }, + { + bool: { + should: [ + { term: { 'metricset.name': 'node' } }, + { term: { 'data_stream.dataset': 'logstash.stack_monitoring.node' } }, + ], }, - ], - }) as estypes.QueryDslQueryContainer, - collapse: { - field: 'logstash.node.state.pipeline.ephemeral_id', - }, - sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }], - size: ephemeralIds.length, + }, + ], + }) as estypes.QueryDslQueryContainer, + collapse: { + field: 'logstash.node.state.pipeline.ephemeral_id', }, + sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }], + size: ephemeralIds.length, }; const results = await callCluster.search(params, { diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_self_monitoring.test.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_self_monitoring.test.ts index 0617b3cfda09e..7017bfc9f84ac 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_self_monitoring.test.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_self_monitoring.test.ts @@ -87,7 +87,7 @@ describe('LogstashSelfMonitoring', () => { {} as any ); const { args } = searchMock.firstCall; - const [{ body }] = args; + const [body] = args; expect(body.from).toEqual(0); expect(body.size).toEqual(10000); @@ -130,7 +130,7 @@ describe('LogstashSelfMonitoring', () => { {} as any ); const { args } = searchMock.firstCall; - const [{ body }] = args; + const [body] = args; expect(body.query).toEqual(expected); }); }); diff --git a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_self_monitoring.ts b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_self_monitoring.ts index 352f764186d39..9fb35c948e705 100644 --- a/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_self_monitoring.ts +++ b/x-pack/platform/plugins/private/monitoring/server/telemetry_collection/logstash_self_monitoring.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { createQuery } from './create_query'; import { mapToList } from './get_high_level_stats'; import { incrementByKey } from './get_high_level_stats'; @@ -257,26 +257,24 @@ export class LogstashSelfMonitoring implements LogstashMonitoring { index: INDEX_PATTERN_LOGSTASH_MONITORING, ignore_unavailable: true, filter_path: filterPath, - body: { - query: createQuery({ - start, - end, - filters: [ - { term: { cluster_uuid: clusterUuid } }, - { - bool: { - should: [{ term: { type: 'logstash_stats' } }], - }, + query: createQuery({ + start, + end, + filters: [ + { term: { cluster_uuid: clusterUuid } }, + { + bool: { + should: [{ term: { type: 'logstash_stats' } }], }, - ], - }) as estypes.QueryDslQueryContainer, - from: page * HITS_SIZE, - collapse: { - field: 'logstash_stats.logstash.uuid', - }, - sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }], - size: HITS_SIZE, + }, + ], + }) as estypes.QueryDslQueryContainer, + from: page * HITS_SIZE, + collapse: { + field: 'logstash_stats.logstash.uuid', }, + sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }], + size: HITS_SIZE, }; const results = await callCluster.search(params, { @@ -321,25 +319,23 @@ export class LogstashSelfMonitoring implements LogstashMonitoring { index: INDEX_PATTERN_LOGSTASH_MONITORING, ignore_unavailable: true, filter_path: filterPath, - body: { - query: createQuery({ - start, - end, - filters: [ - { terms: { 'logstash_state.pipeline.ephemeral_id': ephemeralIds } }, - { - bool: { - should: [{ term: { type: 'logstash_state' } }], - }, + query: createQuery({ + start, + end, + filters: [ + { terms: { 'logstash_state.pipeline.ephemeral_id': ephemeralIds } }, + { + bool: { + should: [{ term: { type: 'logstash_state' } }], }, - ], - }) as estypes.QueryDslQueryContainer, - collapse: { - field: 'logstash_state.pipeline.ephemeral_id', - }, - sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }], - size: ephemeralIds.length, + }, + ], + }) as estypes.QueryDslQueryContainer, + collapse: { + field: 'logstash_state.pipeline.ephemeral_id', }, + sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }], + size: ephemeralIds.length, }; const results = await callCluster.search(params, {