From 7483e5746442201fef53c737f924773ffd12f0a5 Mon Sep 17 00:00:00 2001 From: klacabane Date: Wed, 17 Aug 2022 01:32:45 +0200 Subject: [PATCH 1/6] query for data_stream datasets --- .../monitored_clusters_query.ts | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/monitored_clusters_query.ts b/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/monitored_clusters_query.ts index 5baf6e11c4082..4390fac74f964 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/monitored_clusters_query.ts +++ b/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/monitored_clusters_query.ts @@ -9,6 +9,11 @@ import { TimeRange } from '../../../../../../common/http_api/shared'; const MAX_BUCKET_SIZE = 100; +const getDataset = (product: string) => (metricset: string) => `${product}.${metricset}`; +const getElasticsearchDataset = getDataset('elasticsearch'); +const getKibanaDataset = getDataset('kibana'); +const getLogstashDataset = getDataset('logstash'); + interface QueryOptions { timeRange?: TimeRange; timeout: number; // in seconds @@ -72,6 +77,11 @@ export const persistentMetricsetsQuery = ({ timeout }: QueryOptions) => { 'metricset.name': 'shard', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('shard'), + }, + }, ]; const logstashStateMatches = [ @@ -85,6 +95,11 @@ export const persistentMetricsetsQuery = ({ timeout }: QueryOptions) => { 'metricset.name': 'node', }, }, + { + term: { + 'data_stream.dataset': getLogstashDataset('node'), + }, + }, ]; const metricsetsAggregations = { @@ -260,6 +275,11 @@ const clusterAggregation = { 'metricset.name': 'cluster_stats', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('cluster_stats'), + }, + }, ], }, }, @@ -279,6 +299,11 @@ const clusterAggregation = { 'metricset.name': 'ccr', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('ccr'), + }, + }, ], }, }, @@ -298,6 +323,11 @@ const clusterAggregation = { 'metricset.name': 'index', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('index'), + }, + }, ], }, }, @@ -317,6 +347,11 @@ const clusterAggregation = { 'metricset.name': 'index_summary', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('index_summary'), + }, + }, ], }, }, @@ -336,6 +371,11 @@ const clusterAggregation = { 'metricset.name': 'index_recovery', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('index_recovery'), + }, + }, ], }, }, @@ -364,6 +404,11 @@ const esAggregation = { 'metricset.name': 'node_stats', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('node_stats'), + }, + }, ], }, }, @@ -391,6 +436,11 @@ const kibanaAggregation = { 'metricset.name': 'stats', }, }, + { + term: { + 'data_stream.dataset': getKibanaDataset('stats'), + }, + }, ], }, }, @@ -418,6 +468,11 @@ const logstashAggregation = { 'metricset.name': 'node_stats', }, }, + { + term: { + 'data_stream.dataset': getLogstashDataset('node_stats'), + }, + }, ], }, }, From fa607c0fe33f44fa083ae5163f17c68d67119ba2 Mon Sep 17 00:00:00 2001 From: klacabane Date: Wed, 17 Aug 2022 01:49:18 +0200 Subject: [PATCH 2/6] support package collection mode --- .../build_monitored_clusters.test.ts | 24 +++++++++++++++++++ .../build_monitored_clusters.ts | 3 +++ 2 files changed, 27 insertions(+) diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/build_monitored_clusters.test.ts b/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/build_monitored_clusters.test.ts index 9248af4cae823..d8ec5303c8f15 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/build_monitored_clusters.test.ts +++ b/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/build_monitored_clusters.test.ts @@ -34,6 +34,22 @@ describe(__filename, () => { }, }, }, + { + key: 'node_two', + shard: { + by_index: { + buckets: [ + { + key: '.ds-metrics-elasticsearch.shard-default-2022.08.16-000001', + last_seen: { + value: 123, + value_as_string: '2022-08-06', + }, + }, + ], + }, + }, + }, ], }, }, @@ -52,6 +68,14 @@ describe(__filename, () => { }, }, }, + node_two: { + shard: { + package: { + index: '.ds-metrics-elasticsearch.shard-default-2022.08.16-000001', + lastSeen: '2022-08-06', + }, + }, + }, }, }, }); diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/build_monitored_clusters.ts b/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/build_monitored_clusters.ts index 6a5c0fa8f796a..4b7a9f1c49856 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/build_monitored_clusters.ts +++ b/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/build_monitored_clusters.ts @@ -13,6 +13,7 @@ enum CollectionMode { Internal = 'internal-monitoring', Metricbeat7 = 'metricbeat-7', Metricbeat8 = 'metricbeat-8', + Package = 'package', Unknown = 'unknown', } @@ -42,11 +43,13 @@ const metricbeatMonitoring7Pattern = /(.*:)?\.monitoring-(es|kibana|beats|logstash|ent-search)-7.*-mb.*/; const metricbeatMonitoring8Pattern = /(.*:)?\.ds-\.monitoring-(es|kibana|beats|logstash|ent-search)-8-mb.*/; +const packagePattern = /(.*:)?\.ds-metrics-(elasticsearch|kibana|logstash)\..*/; const getCollectionMode = (index: string): CollectionMode => { if (internalMonitoringPattern.test(index)) return CollectionMode.Internal; if (metricbeatMonitoring7Pattern.test(index)) return CollectionMode.Metricbeat7; if (metricbeatMonitoring8Pattern.test(index)) return CollectionMode.Metricbeat8; + if (packagePattern.test(index)) return CollectionMode.Package; return CollectionMode.Unknown; }; From 8ca4a8330552108c20325c0317fb4b4a9f3cb759 Mon Sep 17 00:00:00 2001 From: klacabane Date: Wed, 17 Aug 2022 02:18:36 +0200 Subject: [PATCH 3/6] build index with metrics pattern --- .../server/routes/api/v1/_health/index.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts b/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts index 0cee2108e2ede..83bc912bf5248 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts +++ b/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts @@ -8,9 +8,12 @@ import type { LegacyRequest, MonitoringCore } from '../../../../types'; import type { MonitoringConfig } from '../../../../config'; import { createValidationFunction } from '../../../../lib/create_route_validation_function'; +import { + getNewIndexPatterns, + getLegacyIndexPattern, +} from '../../../../lib/cluster/get_index_patterns'; import { getHealthRequestQueryRT } from '../../../../../common/http_api/_health'; import type { TimeRange } from '../../../../../common/http_api/shared'; -import { INDEX_PATTERN, INDEX_PATTERN_ENTERPRISE_SEARCH } from '../../../../../common/constants'; import { fetchMonitoredClusters } from './monitored_clusters'; import { fetchMetricbeatErrors } from './metricbeat'; @@ -21,13 +24,7 @@ const DEFAULT_QUERY_TIMEOUT_SECONDS = 15; export function registerV1HealthRoute(server: MonitoringCore) { const validateQuery = createValidationFunction(getHealthRequestQueryRT); - - const withCCS = (indexPattern: string) => { - if (server.config.ui.ccs.enabled) { - return `${indexPattern},*:${indexPattern}`; - } - return indexPattern; - }; + const { config } = server; server.route({ method: 'get', @@ -44,7 +41,7 @@ export function registerV1HealthRoute(server: MonitoringCore) { const timeout = req.query.timeout || DEFAULT_QUERY_TIMEOUT_SECONDS; const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring'); - const settings = extractSettings(server.config); + const settings = extractSettings(config); const fetchArgs: FetchParameters = { timeout, @@ -53,11 +50,20 @@ export function registerV1HealthRoute(server: MonitoringCore) { logger, }; + const monitoringIndex = [ + getNewIndexPatterns({ config, moduleType: 'elasticsearch' }), + getNewIndexPatterns({ config, moduleType: 'kibana' }), + getNewIndexPatterns({ config, moduleType: 'logstash' }), + getLegacyIndexPattern({ config, moduleType: 'beats' }), + , + ].join(','); + const entSearchIndex = getLegacyIndexPattern({ config, moduleType: 'enterprisesearch' }); + const monitoredClustersFn = () => fetchMonitoredClusters({ ...fetchArgs, - monitoringIndex: withCCS(INDEX_PATTERN), - entSearchIndex: withCCS(INDEX_PATTERN_ENTERPRISE_SEARCH), + monitoringIndex, + entSearchIndex, }).catch((err: Error) => { logger.error(`_health: failed to retrieve monitored clusters:\n${err.stack}`); return { error: err.message }; @@ -66,7 +72,7 @@ export function registerV1HealthRoute(server: MonitoringCore) { const metricbeatErrorsFn = () => fetchMetricbeatErrors({ ...fetchArgs, - metricbeatIndex: server.config.ui.metricbeat.index, + metricbeatIndex: config.ui.metricbeat.index, }).catch((err: Error) => { logger.error(`_health: failed to retrieve metricbeat data:\n${err.stack}`); return { error: err.message }; From 8c39be9faa2b4f91e316113d2e052ddd17034497 Mon Sep 17 00:00:00 2001 From: klacabane Date: Wed, 17 Aug 2022 02:21:22 +0200 Subject: [PATCH 4/6] trailing comma --- x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts b/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts index 83bc912bf5248..8a7231cca090d 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts +++ b/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts @@ -55,7 +55,6 @@ export function registerV1HealthRoute(server: MonitoringCore) { getNewIndexPatterns({ config, moduleType: 'kibana' }), getNewIndexPatterns({ config, moduleType: 'logstash' }), getLegacyIndexPattern({ config, moduleType: 'beats' }), - , ].join(','); const entSearchIndex = getLegacyIndexPattern({ config, moduleType: 'enterprisesearch' }); From aa2d98b056b1d66978f2e0e0ce41a1a4e46cf808 Mon Sep 17 00:00:00 2001 From: klacabane Date: Thu, 25 Aug 2022 18:05:43 +0200 Subject: [PATCH 5/6] use getNewIndexPatterns everywhere --- .../monitoring/server/routes/api/v1/_health/index.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts b/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts index 8a7231cca090d..a19e7a6133a09 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts +++ b/x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts @@ -8,10 +8,7 @@ import type { LegacyRequest, MonitoringCore } from '../../../../types'; import type { MonitoringConfig } from '../../../../config'; import { createValidationFunction } from '../../../../lib/create_route_validation_function'; -import { - getNewIndexPatterns, - getLegacyIndexPattern, -} from '../../../../lib/cluster/get_index_patterns'; +import { getNewIndexPatterns } from '../../../../lib/cluster/get_index_patterns'; import { getHealthRequestQueryRT } from '../../../../../common/http_api/_health'; import type { TimeRange } from '../../../../../common/http_api/shared'; @@ -54,9 +51,9 @@ export function registerV1HealthRoute(server: MonitoringCore) { getNewIndexPatterns({ config, moduleType: 'elasticsearch' }), getNewIndexPatterns({ config, moduleType: 'kibana' }), getNewIndexPatterns({ config, moduleType: 'logstash' }), - getLegacyIndexPattern({ config, moduleType: 'beats' }), + getNewIndexPatterns({ config, moduleType: 'beats' }), ].join(','); - const entSearchIndex = getLegacyIndexPattern({ config, moduleType: 'enterprisesearch' }); + const entSearchIndex = getNewIndexPatterns({ config, moduleType: 'enterprisesearch' }); const monitoredClustersFn = () => fetchMonitoredClusters({ From 296cb0d719c9af981bdaeb298d9d043f1a11bab1 Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Tue, 6 Sep 2022 22:08:50 +0900 Subject: [PATCH 6/6] Include new stack_monitoring infix in healthcheck dataset name --- .../v1/_health/monitored_clusters/monitored_clusters_query.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/monitored_clusters_query.ts b/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/monitored_clusters_query.ts index 4390fac74f964..056039c19a7dc 100644 --- a/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/monitored_clusters_query.ts +++ b/x-pack/plugins/monitoring/server/routes/api/v1/_health/monitored_clusters/monitored_clusters_query.ts @@ -9,7 +9,8 @@ import { TimeRange } from '../../../../../../common/http_api/shared'; const MAX_BUCKET_SIZE = 100; -const getDataset = (product: string) => (metricset: string) => `${product}.${metricset}`; +const getDataset = (product: string) => (metricset: string) => + `${product}.stack_monitoring.${metricset}`; const getElasticsearchDataset = getDataset('elasticsearch'); const getKibanaDataset = getDataset('kibana'); const getLogstashDataset = getDataset('logstash');