Skip to content

Commit

Permalink
[monitoring] only create license check if separate monitoring cluster (
Browse files Browse the repository at this point in the history
  • Loading branch information
jbudz authored Mar 22, 2019
1 parent ed2874b commit 4d60e86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import expect from 'expect.js';
import sinon from 'sinon';
import { get, noop } from 'lodash';
import { exposeClient } from '../instantiate_client';
import { exposeClient, hasMonitoringCluster } from '../instantiate_client';

function getMockServerFromConnectionUrl(monitoringClusterUrl) {
const server = {
Expand Down Expand Up @@ -136,4 +136,16 @@ describe('Instantiate Client', () => {
expect(createClientOptions.password).to.eql('monitoring-p@ssw0rd!-internal-test');
});
});

describe('hasMonitoringCluster', () => {
it('returns true if monitoring is configured', () => {
const server = getMockServerFromConnectionUrl('http://monitoring-cluster.test:9200'); // pass null for URL to create the client using prod config
expect(hasMonitoringCluster(server)).to.be(true);
});

it('returns false if monitoring is not configured', () => {
const server = getMockServerFromConnectionUrl(null);
expect(hasMonitoringCluster(server)).to.be(false);
});
});
});
22 changes: 8 additions & 14 deletions x-pack/plugins/monitoring/server/es_client/instantiate_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,22 @@ import { LOGGING_TAG } from '../../common/constants';
*/

export function exposeClient(server) {
const monitoringEsConfig = server.config().get('xpack.monitoring.elasticsearch');

let config;
let configSource;
if (!Boolean(monitoringEsConfig.hosts && monitoringEsConfig.hosts.length)) {
config = {};
configSource = 'production';
} else {
config = { ...monitoringEsConfig };
configSource = 'monitoring';
}

const config = hasMonitoringCluster(server) ? server.config().get('xpack.monitoring.elasticsearch') : {};
const cluster = server.plugins.elasticsearch.createCluster('monitoring', {
...config,
plugins: [monitoringBulk],
logQueries: Boolean(monitoringEsConfig.logQueries),
logQueries: Boolean(config.logQueries),
});

server.events.on('stop', bindKey(cluster, 'close'));

const configSource = hasMonitoringCluster(server) ? 'monitoring' : 'production';
server.log([LOGGING_TAG, 'es-client'], `config sourced from: ${configSource} cluster`);
}

export function hasMonitoringCluster(server) {
const hosts = server.config().get('xpack.monitoring.elasticsearch.hosts');
return Boolean(hosts && hosts.length);
}


export const instantiateClient = once(exposeClient);
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
*/

import { checkLicenseGenerator } from './cluster_alerts/check_license';
import { hasMonitoringCluster } from './es_client/instantiate_client';
import { LOGGING_TAG } from '../common/constants';

/*
* Expose xpackInfo for the Monitoring cluster as server.plugins.monitoring.info
*/
export const initMonitoringXpackInfo = async server => {
const config = server.config();
const xpackInfoOptions = {
const xpackInfo = hasMonitoringCluster(server) ? server.plugins.xpack_main.createXPackInfo({
clusterSource: 'monitoring',
pollFrequencyInMillis: config.get('xpack.monitoring.xpack_api_polling_frequency_millis')
};
const xpackInfo = server.plugins.xpack_main.createXPackInfo(xpackInfoOptions);
}) : server.plugins.xpack_main.info;

xpackInfo.feature('monitoring').registerLicenseCheckResultsGenerator(checkLicenseGenerator);
server.expose('info', xpackInfo);
Expand Down

0 comments on commit 4d60e86

Please sign in to comment.