[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>
This commit is contained in:
Chris Roberson 2021-01-12 13:15:08 -05:00 committed by GitHub
parent 103e8f91c8
commit 33603e749d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 12 deletions

View file

@ -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;

View file

@ -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',
},
});

View file

@ -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);
}

View file

@ -10,6 +10,15 @@ describe('Elasticsearch Nodes Settings', () => {
const getReq = (response) => {
return {
server: {
newPlatform: {
setup: {
plugins: {
cloud: {
isCloudEnabled: false,
},
},
},
},
plugins: {
elasticsearch: {
getCluster() {