-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Tribe node support #9132
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
Merged
Merged
Tribe node support #9132
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
0d2f294
Adds support for Tribe nodes
tylersmalley 881d5df
Merge branch 'master' of github.com:elastic/kibana into tribe-node-su…
spalger 0ac6c11
@spalger review feedback
tylersmalley 8068031
[tribe] Use class syntax on new data sources
jbudz c541bf0
[tribe] Use includes instead of indexOf in call_client
jbudz 654779e
[tribe] DocRequest --> AbstractDocRequest
jbudz 4deefdd
[tribe] Fix AbstractDoc test rename
jbudz 0cfffb7
Removes factory objects and adds addClientPlugin to Cluster (#9467)
tylersmalley 8930f7d
Merge remote-tracking branch 'upstream/master' into tribe-node-support
tylersmalley 9cd3ea5
Merge remote-tracking branch 'upstream/master' into tribe-node-support
tylersmalley 7eaf1d8
Resolves eslint error
tylersmalley ebd06ae
Use properties on the instance instead of class properties
tylersmalley 30cbf87
[tribe] Remove disabled dev tools app, do not bundle console when tri…
jbudz 10277a7
Merge branch 'master' into tribe-node-support
jbudz 77af89d
[tribe] Use destructuring, don't reassign args
jbudz 1e4f1e6
[tribe] Use class syntax for client request wrapper
jbudz e3b4fd7
[tribe] callAsKibanaUser -> callWithInternalUser
jbudz e21723b
[tribe] Remove clients from module context, service is a singleton
jbudz 51672fa
[tribe] Use instance property shorthand for admin and data DocRequests
jbudz fb866a8
Removes questions
tylersmalley b0fbd65
Fixes typo in tests
tylersmalley 0d52a04
Correctly names test case
tylersmalley 256738d
Merge branch 'master' into tribe-node-support
jbudz 927e775
Revert "Use properties on the instance instead of class properties"
jbudz 9855321
Adds tests for create_{admin,data}_cluster
tylersmalley ae39e60
Merge branch 'master' of github.com:elastic/kibana into tribe-node-su…
spalger 97ff6ce
Persists clusters to server
tylersmalley ad85ab3
[tribe] Move cluster config requests to distinct getters
jbudz 8a8c18f
Adds getClient and removes addClientPlugin
tylersmalley fd72137
Expose createClient, consolidate config parsing
tylersmalley f52c887
Removes createClients from Cluster
tylersmalley b5ce38a
Prevent status change from red to red
tylersmalley 40a4a4b
Updates esvm:tribe ports to be consistant with dev
tylersmalley 27c0fcd
Merge remote-tracking branch 'upstream/master' into tribe-node-support
tylersmalley d0610a3
[tribe] Get ssl.ca from serverConfig
jbudz f177300
[tribe/esvm] Remove plugin configuration
jbudz 1707383
Removes unused variable
tylersmalley ec854cf
Merge remote-tracking branch 'upstream/master' into tribe-node-support
tylersmalley a6496a6
[tribe] Named exports for creating clusters
jbudz 7dd8d79
[tribe] Named exports for client logger, cluster
jbudz 2c1f7e3
[tribe] Named exports for health check
jbudz cc90a92
Remove invalid comment
tylersmalley 978d467
[tribe] Comment explaining difference between admin and data browser …
jbudz cb5736a
Rename ES checks to be consistant with functionality
tylersmalley 08cb58c
Organize NOOP functions
tylersmalley 94e4364
Removing function comments
tylersmalley 1b818da
Explicitly check for presence of url in tribe
tylersmalley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
src/core_plugins/elasticsearch/lib/__tests__/cluster.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import expect from 'expect.js'; | ||
| import { Cluster } from '../cluster'; | ||
| import sinon from 'sinon'; | ||
| import { errors as esErrors } from 'elasticsearch'; | ||
| import { set, partial, cloneDeep } from 'lodash'; | ||
| import Boom from 'boom'; | ||
|
|
||
| describe('plugins/elasticsearch', function () { | ||
| describe('cluster', function () { | ||
| let cluster; | ||
| const config = { | ||
| url: 'http://localhost:9200', | ||
| ssl: { verify: false }, | ||
| requestHeadersWhitelist: [ 'authorization' ] | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| cluster = new Cluster(config); | ||
| }); | ||
|
|
||
| it('persists the config', () => { | ||
| expect(cluster._config).to.eql(config); | ||
| }); | ||
|
|
||
| it('exposes error definitions', () => { | ||
| expect(cluster.errors).to.be(esErrors); | ||
| }); | ||
|
|
||
| it('closes the clients', () => { | ||
| cluster._client.close = sinon.spy(); | ||
| cluster._noAuthClient.close = sinon.spy(); | ||
| cluster.close(); | ||
|
|
||
| sinon.assert.calledOnce(cluster._client.close); | ||
| sinon.assert.calledOnce(cluster._noAuthClient.close); | ||
| }); | ||
|
|
||
| it('protects the config from changes', () => { | ||
| const localRequestHeadersWhitelist = cluster.getRequestHeadersWhitelist(); | ||
| expect(localRequestHeadersWhitelist.length).to.not.equal(config.requestHeadersWhitelist); | ||
| }); | ||
|
|
||
| describe('callWithInternalUser', () => { | ||
| let client; | ||
|
|
||
| beforeEach(() => { | ||
| client = cluster._client = sinon.stub(); | ||
| set(client, 'nodes.info', sinon.stub().returns(Promise.resolve())); | ||
| }); | ||
|
|
||
| it('should return a function', () => { | ||
| expect(cluster.callWithInternalUser).to.be.a('function'); | ||
| }); | ||
|
|
||
| it('throws an error for an invalid endpoint', () => { | ||
| const fn = partial(cluster.callWithInternalUser, 'foo'); | ||
| expect(fn).to.throwException(/called with an invalid endpoint: foo/); | ||
| }); | ||
|
|
||
| it('calls the client with params', () => { | ||
| const params = { foo: 'Foo' }; | ||
| cluster.callWithInternalUser('nodes.info', params); | ||
|
|
||
| sinon.assert.calledOnce(client.nodes.info); | ||
| expect(client.nodes.info.getCall(0).args[0]).to.eql(params); | ||
| }); | ||
| }); | ||
|
|
||
| describe('callWithRequest', () => { | ||
| let client; | ||
|
|
||
| beforeEach(() => { | ||
| client = cluster._noAuthClient = sinon.stub(); | ||
| set(client, 'nodes.info', sinon.stub().returns(Promise.resolve())); | ||
| }); | ||
|
|
||
| it('should return a function', () => { | ||
| expect(cluster.callWithRequest).to.be.a('function'); | ||
| }); | ||
|
|
||
| it('throws an error for an invalid endpoint', () => { | ||
| const fn = partial(cluster.callWithRequest, {}, 'foo'); | ||
| expect(fn).to.throwException(/called with an invalid endpoint: foo/); | ||
| }); | ||
|
|
||
| it('calls the client with params', () => { | ||
| const params = { foo: 'Foo' }; | ||
| cluster.callWithRequest({}, 'nodes.info', params); | ||
|
|
||
| sinon.assert.calledOnce(client.nodes.info); | ||
| expect(client.nodes.info.getCall(0).args[0]).to.eql(params); | ||
| }); | ||
|
|
||
| it('passes only whitelisted headers', () => { | ||
| const headers = { authorization: 'Basic TEST' }; | ||
| const request = { headers: Object.assign({}, headers, { foo: 'Foo' }) }; | ||
|
|
||
| cluster.callWithRequest(request, 'nodes.info'); | ||
|
|
||
| sinon.assert.calledOnce(client.nodes.info); | ||
| expect(client.nodes.info.getCall(0).args[0]).to.eql({ | ||
| headers: headers | ||
| }); | ||
| }); | ||
|
|
||
| describe('wrap401Errors', () => { | ||
| let handler; | ||
| const error = new Error('Authentication required'); | ||
| error.statusCode = 401; | ||
|
|
||
| beforeEach(() => { | ||
| handler = sinon.stub(); | ||
| }); | ||
|
|
||
| it('ensures WWW-Authenticate header', async () => { | ||
| set(client, 'mock.401', sinon.stub().returns(Promise.reject(error))); | ||
| await cluster.callWithRequest({}, 'mock.401', {}, { wrap401Errors: true }).catch(handler); | ||
|
|
||
| sinon.assert.calledOnce(handler); | ||
| expect(handler.getCall(0).args[0].output.headers['WWW-Authenticate']).to.eql('Basic realm="Authorization Required"'); | ||
| }); | ||
|
|
||
| it('persists WWW-Authenticate header', async () => { | ||
| set(error, 'body.error.header[WWW-Authenticate]', 'Basic realm="Test"'); | ||
| set(client, 'mock.401', sinon.stub().returns(Promise.reject(error))); | ||
| await cluster.callWithRequest({}, 'mock.401', {}, { wrap401Errors: true }).catch(handler); | ||
|
|
||
| sinon.assert.calledOnce(handler); | ||
| expect(handler.getCall(0).args[0].output.headers['WWW-Authenticate']).to.eql('Basic realm="Test"'); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
66 changes: 66 additions & 0 deletions
66
src/core_plugins/elasticsearch/lib/__tests__/create_admin_cluster.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import expect from 'expect.js'; | ||
| import sinon from 'sinon'; | ||
| import { bindKey, set, get, partial } from 'lodash'; | ||
| import { createAdminCluster } from '../create_admin_cluster'; | ||
|
|
||
| describe('plugins/elasticsearch', function () { | ||
| describe('create_admin_cluster', function () { | ||
| let cluster; | ||
| let server; | ||
|
|
||
| beforeEach(() => { | ||
| const config = { | ||
| elasticsearch: { | ||
| url: 'http://localhost:9200', | ||
| logQueries: true | ||
| } | ||
| }; | ||
|
|
||
| server = sinon.spy(); | ||
|
|
||
| cluster = { | ||
| close: sinon.spy() | ||
| }; | ||
|
|
||
| set(server, 'plugins.elasticsearch.createCluster', sinon.mock().returns(cluster)); | ||
| set(server, 'on', sinon.spy()); | ||
|
|
||
| server.config = () => { | ||
| return { get: partial(get, config) }; | ||
| }; | ||
|
|
||
| createAdminCluster(server); | ||
| }); | ||
|
|
||
| it('creates the cluster', () => { | ||
| const { createCluster } = server.plugins.elasticsearch; | ||
|
|
||
| sinon.assert.calledOnce(createCluster); | ||
| expect(createCluster.getCall(0).args[0]).to.eql('admin'); | ||
| expect(createCluster.getCall(0).args[1].url).to.eql('http://localhost:9200'); | ||
| }); | ||
|
|
||
| it('sets client logger for cluster options', () => { | ||
| const { createCluster } = server.plugins.elasticsearch; | ||
| const firstCall = createCluster.getCall(0); | ||
| const Log = firstCall.args[1].log; | ||
| const logger = new Log; | ||
|
|
||
| sinon.assert.calledOnce(createCluster); | ||
| expect(firstCall.args[0]).to.eql('admin'); | ||
| expect(firstCall.args[1].url).to.eql('http://localhost:9200'); | ||
| expect(logger.tags).to.eql(['admin']); | ||
| expect(logger.logQueries).to.eql(true); | ||
| }); | ||
|
|
||
| it('close cluster of server close', () => { | ||
| const clusterClose = server.on.getCall(0).args[1]; | ||
|
|
||
| clusterClose(); | ||
|
|
||
| sinon.assert.calledOnce(cluster.close); | ||
| sinon.assert.calledOnce(server.on); | ||
| expect(server.on.getCall(0).args[0]).to.eql('close'); | ||
| }); | ||
| }); | ||
| }); |
50 changes: 50 additions & 0 deletions
50
src/core_plugins/elasticsearch/lib/__tests__/create_clusters.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import expect from 'expect.js'; | ||
| import { createClusters } from '../create_clusters'; | ||
| import { Cluster } from '../cluster'; | ||
| import sinon from 'sinon'; | ||
| import { partial } from 'lodash'; | ||
|
|
||
| describe('plugins/elasticsearch', function () { | ||
| describe('createClusters', function () { | ||
| let clusters; | ||
| let server; | ||
|
|
||
| beforeEach(() => { | ||
| server = { | ||
| plugins: { | ||
| elasticsearch: {} | ||
| }, | ||
| expose: sinon.mock() | ||
| }; | ||
|
|
||
| clusters = createClusters(server); | ||
| }); | ||
|
|
||
| describe('createCluster', () => { | ||
| let cluster; | ||
| const config = { | ||
| url: 'http://localhost:9200', | ||
| ssl: { | ||
| verify: false | ||
| } | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| cluster = clusters.create('admin', config); | ||
| }); | ||
|
|
||
| it('returns a cluster', () => { | ||
| expect(cluster).to.be.a(Cluster); | ||
| }); | ||
|
|
||
| it('persists the cluster', () => { | ||
| expect(clusters.get('admin')).to.be.a(Cluster); | ||
| }); | ||
|
|
||
| it('throws if cluster already exists', () => { | ||
| const fn = partial(clusters.create, 'admin', config); | ||
| expect(fn).to.throwException(/cluster \'admin\' already exists/); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the code that gets the testing stuff to work and set up the test data and admin clusters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't necessary for testing to work but it isolated the code the made it easier to test.
Both of these call
server.plugins.elasticsearch.createCluster()which expose the data and admin clusters to the rest of the application. They are then accessible viaserver.plugins.elasticsearch.getCluster()There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah okay makes sense, I initially thought they were actually creating the clusters (booting the instances up). Resolved.