kibana/x-pack/plugins/monitoring/server/lib/elasticsearch/ccr.ts
Sandra G eb17b10203
[Stack Monitoring] compatibility for agent data streams (#119112)
* update queries for elasticsearch package

* fix unit test

* add gitCcs helper function

* modify rest of es queries

* update logstash and kibana queries to use new createQuery

* change beats and apm to use new createQuery

* update changeQuery and remove old one

* make getIndexPattern take request to check for ccs

* fix unit test

* fix unit tests

* update queries and createQuery

* don't add metric constant without dataset in query

* fix types

* fix type

* comment out mb tests

* fix unit test

* fix unit test

* fix

* fix function param

* change to getMetrics name

* change to node_stats

* comment out metricbeat tests

* fix types

* improve types and readability for test

* remove passing of data stream type for now

* add tests for createQuery changes

* update getNewIndexPatterns to take one dataset

* add unit test for getNewIndexPatterns

* fix types

* remove metrics from filter, update tests

* update createNewIndexPatterns to accept new config instead of legacy

* update alert queries to include datas stream index patterns

* update comment

* fix defaulting ccs to * for non cluster requests

* update elasticsearch enterprise module

* update unit test

* remove data_stream.type from queries

* change entsearch to metricbeat module name enterprisesearch

* undo ccs cluster stats change

* fix import

* update alert queries

* fix unit test

* update unit test

* change shard size query to use filter

* change must to filter fix

* update findSupportedBasicLicenseCluster index pattern

* add ccs param to cluster request functions

* update queries for ccs in get_clusters_from_request

* update getBeatsForClusters query

* update clusters apm query

* update enterprisesearch query

* move index pattern to query in fetch for alerts, fix ccs

* remove metricbeat config from alert tests

* fix ts

* add metricset.name back to queries

* comment tests back in

* remove enterprise search checking for standalone cluster to fix test

* update es index metricset name from index_stats to index for mb data

* fix type

* fetchClusters creates index pattern

* fix type

* remove monitoring.ui.metricbeat.index from config and usage in getCollectionStatus

* fix type

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2022-01-20 17:13:23 -05:00

65 lines
2.2 KiB
TypeScript

/*
* 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 moment from 'moment';
// @ts-ignore
import { checkParam } from '../error_missing_required';
// @ts-ignore
import { ElasticsearchMetric } from '../metrics';
// @ts-ignore
import { createQuery } from '../create_query';
import { ElasticsearchResponse } from '../../../common/types/es';
import { LegacyRequest } from '../../types';
import { getNewIndexPatterns } from '../cluster/get_index_patterns';
import { Globals } from '../../static_globals';
export async function checkCcrEnabled(req: LegacyRequest, ccs: string) {
const dataset = 'cluster_stats';
const moduleType = 'elasticsearch';
const indexPatterns = getNewIndexPatterns({
config: Globals.app.config,
moduleType,
dataset,
ccs,
});
const start = moment.utc(req.payload.timeRange.min).valueOf();
const end = moment.utc(req.payload.timeRange.max).valueOf();
const clusterUuid = req.params.clusterUuid;
const metricFields = ElasticsearchMetric.getMetricFields();
const params = {
index: indexPatterns,
size: 1,
ignore_unavailable: true,
body: {
query: createQuery({
type: dataset,
dsDataset: `${moduleType}.${dataset}`,
metricset: dataset,
start,
end,
clusterUuid,
metric: metricFields,
}),
sort: [{ timestamp: { order: 'desc', unmapped_type: 'long' } }],
},
filter_path: [
'hits.hits._source.stack_stats.xpack.ccr',
'hits.hits._source.elasticsearch.cluster.stats.stack.xpack.ccr',
],
};
const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring');
const response: ElasticsearchResponse = await callWithRequest(req, 'search', params);
const legacyCcr = response.hits?.hits[0]?._source.stack_stats?.xpack?.ccr;
const mbCcr = response.hits?.hits[0]?._source?.elasticsearch?.cluster?.stats?.stack?.xpack?.ccr;
const isEnabled = legacyCcr?.enabled ?? mbCcr?.enabled;
const isAvailable = legacyCcr?.available ?? mbCcr?.available;
return Boolean(isEnabled && isAvailable);
}