From 1d03b96ef76f59e7363961439e197a8418fad6d9 Mon Sep 17 00:00:00 2001 From: Chris Roberson Date: Thu, 9 Jan 2020 13:14:05 -0500 Subject: [PATCH] [Monitoring] Ensure setup mode work in a ccs environment (#54361) * Ensure setup mode work in a ccs environment * Missed this file --- .../server/lib/cluster/get_index_patterns.js | 4 +- .../api/v1/setup/cluster_setup_status.js | 3 +- .../routes/api/v1/setup/node_setup_status.js | 3 +- .../apis/monitoring/setup/collection/ccs.js | 42 +++++++++++++++++++ .../apis/monitoring/setup/collection/index.js | 1 + 5 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 x-pack/test/api_integration/apis/monitoring/setup/collection/ccs.js diff --git a/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_index_patterns.js b/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_index_patterns.js index 823495298e1e6..6e8eb3e3c71d3 100644 --- a/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_index_patterns.js +++ b/x-pack/legacy/plugins/monitoring/server/lib/cluster/get_index_patterns.js @@ -13,9 +13,7 @@ import { INDEX_ALERTS, } from '../../../common/constants'; -export function getIndexPatterns(server, additionalPatterns = {}) { - // wildcard means to search _all_ clusters - const ccs = '*'; +export function getIndexPatterns(server, additionalPatterns = {}, ccs = '*') { const config = server.config(); const esIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_ELASTICSEARCH, ccs); const kbnIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_KIBANA, ccs); diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js b/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js index 334fcc4ccc26f..2b6f3b6e71d0f 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js +++ b/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/cluster_setup_status.js @@ -34,6 +34,7 @@ export function clusterSetupStatusRoute(server) { skipLiveData: Joi.boolean().default(false), }), payload: Joi.object({ + ccs: Joi.string().optional(), timeRange: Joi.object({ min: Joi.date().required(), max: Joi.date().required(), @@ -49,7 +50,7 @@ export function clusterSetupStatusRoute(server) { // the monitoring data. `try/catch` makes it a little more explicit. try { await verifyMonitoringAuth(req); - const indexPatterns = getIndexPatterns(server); + const indexPatterns = getIndexPatterns(server, {}, req.payload.ccs); status = await getCollectionStatus( req, indexPatterns, diff --git a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js b/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js index 01715497cbec4..2a615b887500d 100644 --- a/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js +++ b/x-pack/legacy/plugins/monitoring/server/routes/api/v1/setup/node_setup_status.js @@ -34,6 +34,7 @@ export function nodeSetupStatusRoute(server) { skipLiveData: Joi.boolean().default(false), }), payload: Joi.object({ + ccs: Joi.string().optional(), timeRange: Joi.object({ min: Joi.date().required(), max: Joi.date().required(), @@ -49,7 +50,7 @@ export function nodeSetupStatusRoute(server) { // the monitoring data. `try/catch` makes it a little more explicit. try { await verifyMonitoringAuth(req); - const indexPatterns = getIndexPatterns(server); + const indexPatterns = getIndexPatterns(server, {}, req.payload.ccs); status = await getCollectionStatus( req, indexPatterns, diff --git a/x-pack/test/api_integration/apis/monitoring/setup/collection/ccs.js b/x-pack/test/api_integration/apis/monitoring/setup/collection/ccs.js new file mode 100644 index 0000000000000..4c32e311c6cf3 --- /dev/null +++ b/x-pack/test/api_integration/apis/monitoring/setup/collection/ccs.js @@ -0,0 +1,42 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export default function({ getService }) { + const supertest = getService('supertest'); + const esArchiver = getService('esArchiver'); + + describe('ccs', () => { + const archive = 'monitoring/setup/collection/detect_apm'; + const timeRange = { + min: '2019-04-16T00:00:00.741Z', + max: '2019-04-16T23:59:59.741Z', + }; + + before('load archive', () => { + return esArchiver.load(archive); + }); + + after('unload archive', () => { + return esArchiver.unload(archive); + }); + + it('should not fail with a ccs parameter for cluster', async () => { + await supertest + .post('/api/monitoring/v1/setup/collection/cluster?skipLiveData=true') + .set('kbn-xsrf', 'xxx') + .send({ timeRange, ccs: '*' }) + .expect(200); + }); + + it('should not fail with a ccs parameter for node', async () => { + await supertest + .post('/api/monitoring/v1/setup/collection/node/123?skipLiveData=true') + .set('kbn-xsrf', 'xxx') + .send({ timeRange, ccs: '*' }) + .expect(200); + }); + }); +} diff --git a/x-pack/test/api_integration/apis/monitoring/setup/collection/index.js b/x-pack/test/api_integration/apis/monitoring/setup/collection/index.js index 48d8b15ecbcad..01594babbc2f4 100644 --- a/x-pack/test/api_integration/apis/monitoring/setup/collection/index.js +++ b/x-pack/test/api_integration/apis/monitoring/setup/collection/index.js @@ -16,5 +16,6 @@ export default function({ loadTestFile }) { loadTestFile(require.resolve('./detect_logstash_management')); loadTestFile(require.resolve('./detect_apm')); loadTestFile(require.resolve('./security')); + loadTestFile(require.resolve('./ccs')); }); }