-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
instantiate_client.ts
40 lines (35 loc) · 1.47 KB
/
instantiate_client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* 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.
*/
import { Logger, ElasticsearchClientConfig, ICustomClusterClient } from 'kibana/server';
// @ts-ignore
import { monitoringBulk } from '../kibana_monitoring/lib/monitoring_bulk';
import { MonitoringElasticsearchConfig } from '../types';
/* Provide a dedicated Elasticsearch client for Monitoring
* The connection options can be customized for the Monitoring application
* This allows the app to connect to a dedicated monitoring cluster even if
* Kibana itself is connected to a production cluster.
*/
export function instantiateClient(
elasticsearchConfig: any,
log: Logger,
createClient: (
type: string,
clientConfig?: Partial<ElasticsearchClientConfig>
) => ICustomClusterClient
) {
const isMonitoringCluster = hasMonitoringCluster(elasticsearchConfig);
const cluster = createClient('monitoring', {
...(isMonitoringCluster ? elasticsearchConfig : {}),
plugins: [monitoringBulk],
logQueries: Boolean(elasticsearchConfig.logQueries),
});
const configSource = isMonitoringCluster ? 'monitoring' : 'production';
log.info(`config sourced from: ${configSource} cluster`);
return cluster;
}
export function hasMonitoringCluster(config: MonitoringElasticsearchConfig) {
return Boolean(config.hosts && config.hosts[0]);
}