Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Monitoring] Fix issue with singular host config #67575

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ const serverWithUrl = {
},
},
};
const serverWithUrlAndSingleHost = {
monitoring: {
ui: {
elasticsearch: {
hosts: 'http://monitoring-cluster.test:9200',
username: 'monitoring-user-internal-test',
password: 'monitoring-p@ssw0rd!-internal-test',
ssl: {},
customHeaders: {
'x-custom-headers-test': 'connection-monitoring',
},
},
},
},
};

const createClient = sinon.stub();
const log = { info: sinon.stub() };
Expand Down Expand Up @@ -111,6 +126,18 @@ describe('Instantiate Client', () => {
expect(createClientOptions.username).to.eql('monitoring-user-internal-test');
expect(createClientOptions.password).to.eql('monitoring-p@ssw0rd!-internal-test');
});

it('should always use an array', () => {
instantiateClient(serverWithUrlAndSingleHost.monitoring.ui.elasticsearch, log, createClient);
const createClusterCall = createClient.getCall(0);
const createClientOptions = createClusterCall.args[1];

sinon.assert.calledOnce(createClient);
expect(createClusterCall.args[0]).to.be('monitoring');
expect(createClientOptions.hosts[0]).to.eql('http://monitoring-cluster.test:9200');
expect(createClientOptions.username).to.eql('monitoring-user-internal-test');
expect(createClientOptions.password).to.eql('monitoring-p@ssw0rd!-internal-test');
});
});

describe('hasMonitoringCluster', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export function instantiateClient(
) => ICustomClusterClient
) {
const isMonitoringCluster = hasMonitoringCluster(elasticsearchConfig);
// elasticsearch_client_config seems to assume we need an array here
if (isMonitoringCluster && !Array.isArray(elasticsearchConfig.hosts)) {
elasticsearchConfig.hosts = [elasticsearchConfig.hosts];
}
const cluster = createClient('monitoring', {
...(isMonitoringCluster ? elasticsearchConfig : {}),
plugins: [monitoringBulk],
Expand Down