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

Support for multiple Elasticsearch nodes and sniffing #21928

Merged
merged 43 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bd542c2
Node sniffing
jbudz Jul 16, 2018
9bb693f
update monitoring
jbudz Oct 16, 2018
1e021a1
cleaning
jbudz Oct 16, 2018
9c76c88
remove tests
jbudz Oct 16, 2018
55743a0
rewrite tests using the proxy
jbudz Oct 16, 2018
9d33df9
fix monitoring mocha tests
jbudz Oct 16, 2018
10d3933
fix payload
jbudz Oct 16, 2018
99b4927
Merge branch 'master' into node-sniffing
jbudz Oct 16, 2018
8a37e35
return full error
jbudz Oct 16, 2018
1207572
default interval false
jbudz Oct 16, 2018
2898bba
add sniff settings to monitoring
jbudz Oct 16, 2018
227620a
add docs for sniff settings
jbudz Oct 16, 2018
d20ef23
re-add index search integration test
jbudz Oct 16, 2018
e5087e5
catch parse error
jbudz Oct 16, 2018
cf548b0
capital
jbudz Oct 16, 2018
b08264b
Merge branch 'master' into node-sniffing
jbudz Oct 16, 2018
4df060e
Merge branch 'master' into node-sniffing
jbudz Oct 18, 2018
f9a56c8
Merge branch 'master' into node-sniffing
jbudz Nov 7, 2018
6261799
fix merge
jbudz Nov 7, 2018
cc22e30
Merge branch 'master' into node-sniffing
jbudz Nov 19, 2018
05a63c6
hapi upgrade
jbudz Nov 19, 2018
35cd2e9
return
jbudz Nov 19, 2018
722a1b7
pass by prefix
jbudz Nov 19, 2018
337bd82
Merge branch 'master' into node-sniffing
jbudz Nov 26, 2018
80d0941
Merge branch 'master' into node-sniffing
jbudz Nov 28, 2018
ff92ded
rm empty test fille
jbudz Dec 3, 2018
283d5b4
Merge branch 'master' into node-sniffing
jbudz Dec 3, 2018
9da7585
split error handling
jbudz Dec 3, 2018
e119c8e
Merge branch 'master' into node-sniffing
jbudz Dec 10, 2018
172fc41
fix merge
jbudz Dec 10, 2018
a989832
update recent elasticsearch.url references
jbudz Dec 10, 2018
bae59ef
prettier vs eslint
jbudz Dec 10, 2018
d41fdbf
Merge branch 'master' into node-sniffing
jbudz Dec 10, 2018
09600e8
Merge branch 'master' into node-sniffing
jbudz Dec 10, 2018
3d1f707
transport.request, include query params
jbudz Dec 11, 2018
878ed05
mega comment
jbudz Dec 12, 2018
6c8f1f4
revert elasticsearchUrl
jbudz Dec 12, 2018
48127e7
Merge branch 'master' into node-sniffing
jbudz Dec 14, 2018
146a5d1
safe hosts
jbudz Dec 14, 2018
699f66f
more docs es.url references
jbudz Dec 14, 2018
275a0e4
Merge branch 'master' into node-sniffing
jbudz Dec 17, 2018
070ecd6
remove unused ml/esServerUrl
jbudz Dec 17, 2018
2bf1e65
log if both set
jbudz Dec 17, 2018
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
4 changes: 2 additions & 2 deletions config/kibana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
# The Kibana server's name. This is used for display purposes.
#server.name: "your-hostname"

# The URL of the Elasticsearch instance to use for all your queries.
#elasticsearch.url: "http://localhost:9200"
# The URLs of the Elasticsearch instances to use for all your queries.
#elasticsearch.hosts: ["http://localhost:9200"]

# When this setting's value is true Kibana uses the hostname specified in the server.host
# setting. When the value of this setting is false, Kibana uses the hostname of the host
Expand Down
2 changes: 1 addition & 1 deletion docs/monitoring/monitoring-kibana.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ and {ref}/cluster-update-settings.html[Cluster update settings].
more information, see <<monitoring-settings-kb,Monitoring settings in {kib}>>.

. Identify where to send monitoring data. {kib} automatically
sends metrics to the {es} cluster specified in the `elasticsearch.url` setting
sends metrics to the {es} cluster specified in the `elasticsearch.hosts` setting
in the `kibana.yml` file. This property has a default value of
`http://localhost:9200`. +
+
Expand Down
4 changes: 2 additions & 2 deletions docs/monitoring/monitoring-troubleshooting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ The *Monitoring* page in {kib} is empty.

. Confirm that {kib} is seeking monitoring data from the appropriate {es} URL.
By default, data is retrieved from the cluster specified in the
`elasticsearch.url` setting in the `kibana.yml` file. If you want to retrieve it
from a different monitoring cluster, set `xpack.monitoring.elasticsearch.url`.
`elasticsearch.hosts` setting in the `kibana.yml` file. If you want to retrieve it
from a different monitoring cluster, set `xpack.monitoring.elasticsearch.hosts`.
See <<monitoring-settings-kb>>.

. Confirm that there is monitoring data available at that URL. It is stored in
Expand Down
4 changes: 2 additions & 2 deletions docs/monitoring/viewing-metrics.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ a gold license, you can send data from multiple clusters to the same monitoring
cluster and view them all through the same instance of {kib}.

By default, data is retrieved from the cluster specified in the
`elasticsearch.url` value in the `kibana.yml` file. If you want to retrieve it
from a different cluster, set `xpack.monitoring.elasticsearch.url`.
`elasticsearch.hosts` value in the `kibana.yml` file. If you want to retrieve it
from a different cluster, set `xpack.monitoring.elasticsearch.hosts`.

To learn more about typical monitoring architectures,
see {stack-ov}/how-monitoring-works.html[How monitoring works] and
Expand Down
8 changes: 4 additions & 4 deletions docs/security/securing-communications/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ must have a proxy that provides an HTTPS endpoint for {es}.

--

.. Specify the HTTPS protocol in the `elasticsearch.url` setting in the {kib}
.. Specify the HTTPS protocol in the `elasticsearch.hosts` setting in the {kib}
configuration file, `kibana.yml`:
+
--
[source,yaml]
--------------------------------------------------------------------------------
elasticsearch.url: "https://<your_elasticsearch_host>.com:9200"
elasticsearch.hosts: ["https://<your_elasticsearch_host>.com:9200"]
--------------------------------------------------------------------------------
--

Expand Down Expand Up @@ -100,13 +100,13 @@ must have a proxy that provides an HTTPS endpoint for {es}.

--

.. Specify the HTTPS URL in the `xpack.monitoring.elasticsearch.url` setting in
.. Specify the HTTPS URL in the `xpack.monitoring.elasticsearch.hosts` setting in
the {kib} configuration file, `kibana.yml`
+
--
[source,yaml]
--------------------------------------------------------------------------------
xpack.monitoring.elasticsearch.url: "https://<your_monitoring_cluster>:9200"
xpack.monitoring.elasticsearch.hosts: ["https://<your_monitoring_cluster>:9200"]
--------------------------------------------------------------------------------
--

Expand Down
4 changes: 2 additions & 2 deletions docs/settings/monitoring-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ Set to `true` (default) to enable {monitoring} in {kib}. Unlike the
monitoring back-end does not run and {kib} stats are not sent to the monitoring
cluster.

`xpack.monitoring.elasticsearch.url`::
`xpack.monitoring.elasticsearch.hosts`::
Specifies the location of the {es} cluster where your monitoring data is stored.
By default, this is the same as the `elasticsearch.url`. This setting enables
By default, this is the same as `elasticsearch.hosts`. This setting enables
you to use a single {kib} instance to search and visualize data in your
production cluster as well as monitor data sent to a dedicated monitoring
cluster.
Expand Down
4 changes: 2 additions & 2 deletions docs/setup/docker.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ services:
image: {docker-image}
environment:
SERVER_NAME: kibana.example.org
ELASTICSEARCH_URL: http://elasticsearch.example.org
ELASTICSEARCH_HOSTS: http://elasticsearch.example.org
----------------------------------------------------------

Since environment variables are translated to CLI arguments, they take
Expand All @@ -117,7 +117,7 @@ images:
[horizontal]
`server.name`:: `kibana`
`server.host`:: `"0"`
`elasticsearch.url`:: `http://elasticsearch:9200`
`elasticsearch.hosts`:: `http://elasticsearch:9200`
`xpack.monitoring.ui.container.elasticsearch.enabled`:: `true`

NOTE: The setting `xpack.monitoring.ui.container.elasticsearch.enabled` is not
Expand Down
6 changes: 3 additions & 3 deletions docs/setup/production.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ http.port: 9200
transport.host: <external ip>
transport.tcp.port: 9300 - 9400
--------
. Make sure Kibana is configured to point to your local client node. In `kibana.yml`, the `elasticsearch.url` should be set to
`localhost:9200`.
. Make sure Kibana is configured to point to your local client node. In `kibana.yml`, the `elasticsearch.hosts` setting should be set to
`["localhost:9200"]`.
+
--------
# The Elasticsearch instance to use for all your queries.
elasticsearch.url: "http://localhost:9200"
elasticsearch.hosts: ["http://localhost:9200"]
--------
10 changes: 8 additions & 2 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Elasticsearch. This value must be a positive integer.

`elasticsearch.shardTimeout:`:: *Default: 30000* Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable.

`elasticsearch.sniffInterval:`:: *Default: false* Time in milliseconds between requests to check Elasticsearch for an updated list of nodes.

`elasticsearch.sniffOnStart:`:: *Default: false* Attempt to find other Elasticsearch nodes on startup.

`elasticsearch.sniffOnConectionFault:`:: *Default: false* Update the list of Elasticsearch nodes immediately following a connection fault.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, looks like some bits fell out. Connection is missing an 'n' in the setting name.


`elasticsearch.ssl.certificate:` and `elasticsearch.ssl.key:`:: Optional settings that provide the paths to the PEM-format SSL
certificate and key files. These files are used to verify the identity of Kibana to Elasticsearch and are required when `xpack.ssl.verification_mode` in Elasticsearch is set to either `certificate` or `full`.

Expand All @@ -57,8 +63,8 @@ requests for end-users being executed as the identity tied to the configured cer
`elasticsearch.startupTimeout:`:: *Default: 5000* Time in milliseconds to wait for Elasticsearch at Kibana startup before
retrying.

`elasticsearch.url:`:: *Default: "http://localhost:9200"* The URL of the Elasticsearch instance to use for all your
queries.
`elasticsearch.hosts:`:: *Default: "http://localhost:9200"* The URLs of the Elasticsearch instances to use for all your
queries. All nodes listed here must be on the same cluster.

`elasticsearch.username:` and `elasticsearch.password:`:: If your Elasticsearch is protected with basic authentication,
these settings provide the username and password that the Kibana server uses to perform maintenance on the Kibana index at
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-plugin-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Generated plugins receive a handful of scripts that can be used during developme
Start kibana and have it include this plugin. You can pass any arguments that you would normally send to `bin/kibana`

```
yarn start --elasticsearch.url http://localhost:9220
yarn start --elasticsearch.hosts http://localhost:9220
```

- `yarn build`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ See the [kibana contributing guide](https://github.com/elastic/kibana/blob/maste
Start kibana and have it include this plugin. You can pass any arguments that you would normally send to `bin/kibana`

```
yarn start --elasticsearch.url http://localhost:9220
yarn start --elasticsearch.hosts http://localhost:9220
```

- `yarn build`
Expand Down
4 changes: 2 additions & 2 deletions src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function applyConfigOverrides(rawConfig, opts, extraCliOptions) {
}
}

if (opts.elasticsearch) set('elasticsearch.url', opts.elasticsearch);
if (opts.elasticsearch) set('elasticsearch.hosts', opts.elasticsearch.split(','));
if (opts.port) set('server.port', opts.port);
if (opts.host) set('server.host', opts.host);
if (opts.quiet) set('logging.quiet', true);
Expand Down Expand Up @@ -144,7 +144,7 @@ export default function (program) {
command
.description('Run the kibana server')
.collectUnknownOptions()
.option('-e, --elasticsearch <uri>', 'Elasticsearch instance')
.option('-e, --elasticsearch <uri1,uri2>', 'Elasticsearch instances')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly had no idea we supported this.

Copy link
Contributor

@tylersmalley tylersmalley Dec 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but thoughts on removing this in 7.0? I assume these options came before you could pass arbitrary config options through the CLI.

.option(
'-c, --config <path>',
'Path to the config file, can be changed with the CONFIG_PATH environment variable as well. ' +
Expand Down
23 changes: 17 additions & 6 deletions src/legacy/core_plugins/console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
*/

import Boom from 'boom';
import { resolveApi } from './api_server/server';
import { resolve, join, sep } from 'path';
import { has, isEmpty } from 'lodash';
import setHeaders from '../elasticsearch/lib/set_headers';
import url from 'url';
import { has, isEmpty, head } from 'lodash';

import { resolveApi } from './api_server/server';
import { addExtensionSpecFilePath } from './api_server/spec';
import setHeaders from '../elasticsearch/lib/set_headers';

import {
ProxyConfigCollection,
Expand All @@ -37,7 +39,7 @@ export default function (kibana) {
const apps = [];
return new kibana.Plugin({
id: 'console',
require: [ 'elasticsearch' ],
require: ['elasticsearch'],

config: function (Joi) {
return Joi.object({
Expand Down Expand Up @@ -89,7 +91,7 @@ export default function (kibana) {
const proxyPathFilters = options.proxyFilter.map(str => new RegExp(str));

server.route(createProxyRoute({
baseUrl: config.get('elasticsearch.url'),
baseUrl: head(config.get('elasticsearch.hosts')),
pathFilters: proxyPathFilters,
getConfigForReq(req, uri) {
const whitelist = config.get('elasticsearch.requestHeadersWhitelist');
Expand Down Expand Up @@ -132,7 +134,16 @@ export default function (kibana) {

injectDefaultVars(server) {
return {
elasticsearchUrl: server.config().get('elasticsearch.url')
elasticsearchUrl: url.format(
Object.assign(
url.parse(
head(
server.config().get('elasticsearch.hosts')
)
),
{ auth: false }
)
)
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const RowParser = require('./row_parser');
const InputMode = require('./mode/input');
const utils = require('../utils');
const es = require('../es');
import chrome from 'ui/chrome';
const chrome = require('ui/chrome');

const smartResize = require('../smart_resize');

Expand Down Expand Up @@ -564,6 +564,7 @@ export default function SenseEditor($el) {
const esMethod = req.method;
const esData = req.data;

// this is the first url defined in elasticsearch.hosts
const elasticsearchBaseUrl = chrome.getInjected('elasticsearchUrl');
const url = es.constructESUrl(elasticsearchBaseUrl, esPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('plugins/console', function () {
}
};

server.config().get.withArgs('elasticsearch.url').returns('http://localhost:9200');
server.config().get.withArgs('elasticsearch.hosts').returns(['http://localhost:9200']);
server.config().get.withArgs('elasticsearch.ssl.verificationMode').returns('full');
});

Expand All @@ -58,20 +58,20 @@ describe('plugins/console', function () {
});

it(`uses https.Agent when url's protocol is https`, function () {
setElasticsearchConfig('url', 'https://localhost:9200');
setElasticsearchConfig('hosts', ['https://localhost:9200']);
const { agent } = getElasticsearchProxyConfig(server);
expect(agent).to.be.a(https.Agent);
});

it(`uses http.Agent when url's protocol is http`, function () {
setElasticsearchConfig('url', 'http://localhost:9200');
setElasticsearchConfig('hosts', ['http://localhost:9200']);
const { agent } = getElasticsearchProxyConfig(server);
expect(agent).to.be.a(http.Agent);
});

describe('ssl', function () {
beforeEach(function () {
setElasticsearchConfig('url', 'https://localhost:9200');
setElasticsearchConfig('hosts', ['https://localhost:9200']);
});

it('sets rejectUnauthorized to false when verificationMode is none', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const readFile = (file) => readFileSync(file, 'utf8');

const createAgent = (server) => {
const config = server.config();
const target = url.parse(config.get('elasticsearch.url'));

const target = url.parse(
_.head(config.get('elasticsearch.hosts'))
);
if (!/^https/.test(target.protocol)) return new http.Agent();

const agentOptions = {};
Expand Down
31 changes: 25 additions & 6 deletions src/legacy/core_plugins/elasticsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ import { createDataCluster } from './lib/create_data_cluster';
import { createAdminCluster } from './lib/create_admin_cluster';
import { clientLogger } from './lib/client_logger';
import { createClusters } from './lib/create_clusters';
import filterHeaders from './lib/filter_headers';

import { createProxy } from './lib/create_proxy';
import filterHeaders from './lib/filter_headers';

const DEFAULT_REQUEST_HEADERS = [ 'authorization' ];
const DEFAULT_REQUEST_HEADERS = ['authorization'];

export default function (kibana) {
return new kibana.Plugin({
Expand All @@ -46,7 +45,10 @@ export default function (kibana) {

return Joi.object({
enabled: Joi.boolean().default(true),
url: Joi.string().uri({ scheme: ['http', 'https'] }).default('http://localhost:9200'),
sniffOnStart: Joi.boolean().default(false),
sniffInterval: Joi.number().allow(false).default(false),
sniffOnConnectionFault: Joi.boolean().default(false),
hosts: Joi.array().items(Joi.string().uri({ scheme: ['http', 'https'] })).single().default('http://localhost:9200'),
pickypg marked this conversation as resolved.
Show resolved Hide resolved
preserveHost: Joi.boolean().default(true),
username: Joi.string(),
password: Joi.string(),
Expand Down Expand Up @@ -86,9 +88,27 @@ export default function (kibana) {
};
};

const url = () => {
return (settings, log) => {
const deprecatedUrl = get(settings, 'url');
const hosts = get(settings, 'hosts.length');
if (!deprecatedUrl) {
return;
}
if (hosts) {
log('Deprecated config key "elasticsearch.url" conflicts with "elasticsearch.hosts". Ignoring "elasticsearch.url"');
} else {
set(settings, 'hosts', [deprecatedUrl]);
log('Config key "elasticsearch.url" is deprecated. It has been replaced with "elasticsearch.hosts"');
}
unset(settings, 'url');
};
};

return [
rename('ssl.ca', 'ssl.certificateAuthorities'),
rename('ssl.cert', 'ssl.certificate'),
url(),
sslVerify(),
];
},
Expand All @@ -115,8 +135,7 @@ export default function (kibana) {
createDataCluster(server);
createAdminCluster(server);

createProxy(server, 'POST', '/{index}/_search');
createProxy(server, 'POST', '/_msearch');
createProxy(server);

// Set up the health check service and start it.
const { start, waitUntilReady } = healthCheck(this, server);
Expand Down

This file was deleted.

Loading