Skip to content

Commit

Permalink
Support for multiple Elasticsearch nodes and sniffing (elastic#21928)
Browse files Browse the repository at this point in the history
* Node sniffing

* update monitoring

* cleaning

* remove tests

* rewrite tests using the proxy

* fix monitoring mocha tests

* fix payload

* return full error

* default interval false

* add sniff settings to monitoring

* add docs for sniff settings

* re-add index search integration test

* catch parse error

* capital

* fix merge

* hapi upgrade

* return

* pass by prefix

* rm empty test fille

* split error handling

* fix merge

* update recent elasticsearch.url references

* prettier vs eslint

* transport.request, include query params

* mega comment

* revert elasticsearchUrl

* safe hosts

* more docs es.url references

* remove unused ml/esServerUrl

* log if both set
  • Loading branch information
jbudz committed Dec 18, 2018
1 parent ce3d215 commit 8f14ddf
Show file tree
Hide file tree
Showing 41 changed files with 245 additions and 440 deletions.
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.

`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 @@ -59,8 +65,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
8 changes: 4 additions & 4 deletions docs/setup/tribe.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Tribe nodes take all of the same configuration options used when configuring ela
are prefixed with `elasticsearch.tribe` and at a minimum requires a url:
[source,text]
----
elasticsearch.url: "<your_administration_node>"
elasticsearch.tribe.url: "<your_tribe_node>"
elasticsearch.hosts: ["<your_administration_node>"]
elasticsearch.tribe.hosts: ["<your_tribe_node>"]
----

When configured to use a tribe node, actions that modify Kibana's state will be sent to the node at `elasticsearch.url`. Searches and visualizations
will retrieve data from the node at `elasticsearch.tribe.url`. It's acceptable to use a node for `elasticsearch.url` that is part of one of the clusters that
When configured to use a tribe node, actions that modify Kibana's state will be sent to the nodes at `elasticsearch.hosts`. Searches and visualizations
will retrieve data from the nodes configured at `elasticsearch.tribe.hosts`. It's acceptable to use nodes for `elasticsearch.hosts` that is part of one of the clusters that
a tribe node is pointing to.

The full list of configurations can be found at {kibana-ref}/settings.html[Configuring
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 @@ -102,7 +102,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 @@ -141,7 +141,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')
.option(
'-c, --config <path>',
'Path to the config file, can be changed with the CONFIG_PATH environment variable as well. ' +
Expand Down
25 changes: 18 additions & 7 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,13 +39,13 @@ export default function (kibana) {
const apps = [];
return new kibana.Plugin({
id: 'console',
require: [ 'elasticsearch' ],
require: ['elasticsearch'],

isEnabled(config) {
// console must be disabled when tribe mode is configured
return (
config.get('console.enabled') &&
!config.get('elasticsearch.tribe.url')
!config.get('elasticsearch.tribe.hosts')
);
},

Expand Down Expand Up @@ -97,7 +99,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 @@ -140,7 +142,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
Loading

0 comments on commit 8f14ddf

Please sign in to comment.