Skip to content

Commit

Permalink
[Stack Monitoring] health api support for data ingested from package (e…
Browse files Browse the repository at this point in the history
…lastic#138964)

* query for data_stream datasets

* support package collection mode

* build index with metrics pattern

* trailing comma

* use getNewIndexPatterns everywhere

* Include new stack_monitoring infix in healthcheck dataset name

Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Mat Schaffer <[email protected]>
  • Loading branch information
3 people authored and Mpdreamz committed Sep 6, 2022
1 parent e13e71a commit ddcd52b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 12 deletions.
26 changes: 14 additions & 12 deletions x-pack/plugins/monitoring/server/routes/api/v1/_health/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -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 };
Expand All @@ -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 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
],
},
},
},
],
},
},
Expand All @@ -52,6 +68,14 @@ describe(__filename, () => {
},
},
},
node_two: {
shard: {
package: {
index: '.ds-metrics-elasticsearch.shard-default-2022.08.16-000001',
lastSeen: '2022-08-06',
},
},
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum CollectionMode {
Internal = 'internal-monitoring',
Metricbeat7 = 'metricbeat-7',
Metricbeat8 = 'metricbeat-8',
Package = 'package',
Unknown = 'unknown',
}

Expand Down Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,6 +78,11 @@ export const persistentMetricsetsQuery = ({ timeout }: QueryOptions) => {
'metricset.name': 'shard',
},
},
{
term: {
'data_stream.dataset': getElasticsearchDataset('shard'),
},
},
];

const logstashStateMatches = [
Expand All @@ -85,6 +96,11 @@ export const persistentMetricsetsQuery = ({ timeout }: QueryOptions) => {
'metricset.name': 'node',
},
},
{
term: {
'data_stream.dataset': getLogstashDataset('node'),
},
},
];

const metricsetsAggregations = {
Expand Down Expand Up @@ -260,6 +276,11 @@ const clusterAggregation = {
'metricset.name': 'cluster_stats',
},
},
{
term: {
'data_stream.dataset': getElasticsearchDataset('cluster_stats'),
},
},
],
},
},
Expand All @@ -279,6 +300,11 @@ const clusterAggregation = {
'metricset.name': 'ccr',
},
},
{
term: {
'data_stream.dataset': getElasticsearchDataset('ccr'),
},
},
],
},
},
Expand All @@ -298,6 +324,11 @@ const clusterAggregation = {
'metricset.name': 'index',
},
},
{
term: {
'data_stream.dataset': getElasticsearchDataset('index'),
},
},
],
},
},
Expand All @@ -317,6 +348,11 @@ const clusterAggregation = {
'metricset.name': 'index_summary',
},
},
{
term: {
'data_stream.dataset': getElasticsearchDataset('index_summary'),
},
},
],
},
},
Expand All @@ -336,6 +372,11 @@ const clusterAggregation = {
'metricset.name': 'index_recovery',
},
},
{
term: {
'data_stream.dataset': getElasticsearchDataset('index_recovery'),
},
},
],
},
},
Expand Down Expand Up @@ -364,6 +405,11 @@ const esAggregation = {
'metricset.name': 'node_stats',
},
},
{
term: {
'data_stream.dataset': getElasticsearchDataset('node_stats'),
},
},
],
},
},
Expand Down Expand Up @@ -391,6 +437,11 @@ const kibanaAggregation = {
'metricset.name': 'stats',
},
},
{
term: {
'data_stream.dataset': getKibanaDataset('stats'),
},
},
],
},
},
Expand Down Expand Up @@ -418,6 +469,11 @@ const logstashAggregation = {
'metricset.name': 'node_stats',
},
},
{
term: {
'data_stream.dataset': getLogstashDataset('node_stats'),
},
},
],
},
},
Expand Down

0 comments on commit ddcd52b

Please sign in to comment.