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..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,9 +8,9 @@ import type { LegacyRequest, MonitoringCore } from '../../../../types'; import type { MonitoringConfig } from '../../../../config'; import { createValidationFunction } from '../../../../lib/create_route_validation_function'; +import { getNewIndexPatterns } 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 +21,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 +38,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 +47,19 @@ export function registerV1HealthRoute(server: MonitoringCore) { logger, }; + const monitoringIndex = [ + getNewIndexPatterns({ config, moduleType: 'elasticsearch' }), + getNewIndexPatterns({ config, moduleType: 'kibana' }), + getNewIndexPatterns({ config, moduleType: 'logstash' }), + getNewIndexPatterns({ config, moduleType: 'beats' }), + ].join(','); + const entSearchIndex = getNewIndexPatterns({ 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 +68,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 }; 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; }; 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..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,6 +9,12 @@ import { TimeRange } from '../../../../../../common/http_api/shared'; const MAX_BUCKET_SIZE = 100; +const getDataset = (product: string) => (metricset: string) => + `${product}.stack_monitoring.${metricset}`; +const getElasticsearchDataset = getDataset('elasticsearch'); +const getKibanaDataset = getDataset('kibana'); +const getLogstashDataset = getDataset('logstash'); + interface QueryOptions { timeRange?: TimeRange; timeout: number; // in seconds @@ -72,6 +78,11 @@ export const persistentMetricsetsQuery = ({ timeout }: QueryOptions) => { 'metricset.name': 'shard', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('shard'), + }, + }, ]; const logstashStateMatches = [ @@ -85,6 +96,11 @@ export const persistentMetricsetsQuery = ({ timeout }: QueryOptions) => { 'metricset.name': 'node', }, }, + { + term: { + 'data_stream.dataset': getLogstashDataset('node'), + }, + }, ]; const metricsetsAggregations = { @@ -260,6 +276,11 @@ const clusterAggregation = { 'metricset.name': 'cluster_stats', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('cluster_stats'), + }, + }, ], }, }, @@ -279,6 +300,11 @@ const clusterAggregation = { 'metricset.name': 'ccr', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('ccr'), + }, + }, ], }, }, @@ -298,6 +324,11 @@ const clusterAggregation = { 'metricset.name': 'index', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('index'), + }, + }, ], }, }, @@ -317,6 +348,11 @@ const clusterAggregation = { 'metricset.name': 'index_summary', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('index_summary'), + }, + }, ], }, }, @@ -336,6 +372,11 @@ const clusterAggregation = { 'metricset.name': 'index_recovery', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('index_recovery'), + }, + }, ], }, }, @@ -364,6 +405,11 @@ const esAggregation = { 'metricset.name': 'node_stats', }, }, + { + term: { + 'data_stream.dataset': getElasticsearchDataset('node_stats'), + }, + }, ], }, }, @@ -391,6 +437,11 @@ const kibanaAggregation = { 'metricset.name': 'stats', }, }, + { + term: { + 'data_stream.dataset': getKibanaDataset('stats'), + }, + }, ], }, }, @@ -418,6 +469,11 @@ const logstashAggregation = { 'metricset.name': 'node_stats', }, }, + { + term: { + 'data_stream.dataset': getLogstashDataset('node_stats'), + }, + }, ], }, },