From 33603e749d24429cc73e519a94c777803072dbb5 Mon Sep 17 00:00:00 2001 From: Chris Roberson Date: Tue, 12 Jan 2021 13:15:08 -0500 Subject: [PATCH] [Monitoring] Cloud property not properly passed when no monitoring data found (#87649) * Fix parameter usage * Fix up incorrect usage again * Add another check * Fix tests Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../server/lib/elasticsearch_settings/cluster.js | 11 +++++++---- .../lib/elasticsearch_settings/cluster.test.js | 3 --- .../server/lib/elasticsearch_settings/nodes.js | 16 +++++++++++----- .../lib/elasticsearch_settings/nodes.test.js | 9 +++++++++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/cluster.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/cluster.js index ba6f622efce2..223bfb836f04 100644 --- a/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/cluster.js +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/cluster.js @@ -12,10 +12,13 @@ export function handleResponse(response, isCloudEnabled) { for (const source of sources) { const monitoringSettings = get(response[source], 'xpack.monitoring'); if (monitoringSettings !== undefined) { - const check = findReason(monitoringSettings, { - context: `cluster ${source}`, - isCloudEnabled, - }); + const check = findReason( + monitoringSettings, + { + context: `cluster ${source}`, + }, + isCloudEnabled + ); if (check.found) { return check; diff --git a/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/cluster.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/cluster.test.js index 41345499c61d..cd30ff2fd8a1 100644 --- a/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/cluster.test.js +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/cluster.test.js @@ -57,7 +57,6 @@ describe('Elasticsearch Cluster Settings', () => { reason: { context: `cluster ${source}`, data: '-1', - isCloudEnabled: false, property: 'xpack.monitoring.collection.interval', }, }); @@ -87,7 +86,6 @@ describe('Elasticsearch Cluster Settings', () => { reason: { context: `cluster ${source}`, data: 'Remote exporters indicate a possible misconfiguration: myCoolExporter', - isCloudEnabled: false, property: 'xpack.monitoring.exporters', }, }); @@ -117,7 +115,6 @@ describe('Elasticsearch Cluster Settings', () => { reason: { context: `cluster ${source}`, data: 'false', - isCloudEnabled: false, property: 'xpack.monitoring.enabled', }, }); diff --git a/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/nodes.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/nodes.js index a4f391d73f42..ecdcbeb694d1 100644 --- a/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/nodes.js +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/nodes.js @@ -7,15 +7,19 @@ import { get } from 'lodash'; import { findReason } from './find_reason'; -export function handleResponse({ nodes = {} } = {}) { +export function handleResponse({ nodes = {} } = {}, isCloudEnabled) { const nodeIds = Object.keys(nodes); for (const nodeId of nodeIds) { const nodeSettings = get(nodes, [nodeId, 'settings']); if (nodeSettings !== undefined) { const monitoringSettings = get(nodeSettings, 'xpack.monitoring'); - const check = findReason(monitoringSettings, { - context: `nodeId: ${nodeId}`, - }); + const check = findReason( + monitoringSettings, + { + context: `nodeId: ${nodeId}`, + }, + isCloudEnabled + ); if (check.found) { return check; @@ -28,11 +32,13 @@ export function handleResponse({ nodes = {} } = {}) { export async function checkNodesSettings(req) { const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('admin'); + const { cloud } = req.server.newPlatform.setup.plugins; + const isCloudEnabled = !!(cloud && cloud.isCloudEnabled); const response = await callWithRequest(req, 'transport.request', { method: 'GET', path: '/_nodes/settings', filter_path: ['nodes'], // NOTE: this doesn't seem to do anything when used with elasticsearch-js. In Console, it does work though }); - return handleResponse(response); + return handleResponse(response, isCloudEnabled); } diff --git a/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/nodes.test.js b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/nodes.test.js index a06afb531597..79e8eab02203 100644 --- a/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/nodes.test.js +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch_settings/nodes.test.js @@ -10,6 +10,15 @@ describe('Elasticsearch Nodes Settings', () => { const getReq = (response) => { return { server: { + newPlatform: { + setup: { + plugins: { + cloud: { + isCloudEnabled: false, + }, + }, + }, + }, plugins: { elasticsearch: { getCluster() {