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

[6.x] [savedObjects] Use index template (#14271) #15103

Merged
merged 1 commit into from
Nov 22, 2017
Merged
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
120 changes: 0 additions & 120 deletions src/core_plugins/elasticsearch/lib/__tests__/create_kibana_index.js

This file was deleted.

74 changes: 7 additions & 67 deletions src/core_plugins/elasticsearch/lib/__tests__/health_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,17 @@ describe('plugins/elasticsearch', () => {

it('should set the cluster green if everything is ready', function () {
cluster.callWithInternalUser.withArgs('ping').returns(Promise.resolve());
cluster.callWithInternalUser.withArgs('cluster.health', sinon.match.any).returns(
Promise.resolve({ timed_out: false, status: 'green' })
);

return health.run()
.then(function () {
sinon.assert.calledOnce(plugin.status.yellow);
expect(plugin.status.yellow.args[0][0]).to.be('Waiting for Elasticsearch');
sinon.assert.calledWithExactly(plugin.status.yellow, 'Waiting for Elasticsearch');

sinon.assert.calledOnce(cluster.callWithInternalUser.withArgs('ping'));
sinon.assert.calledTwice(cluster.callWithInternalUser.withArgs('nodes.info', sinon.match.any));
sinon.assert.calledOnce(cluster.callWithInternalUser.withArgs('cluster.health', sinon.match.any));
sinon.assert.notCalled(plugin.status.red);
sinon.assert.calledOnce(plugin.status.green);

expect(plugin.status.green.args[0][0]).to.be('Kibana index ready');
sinon.assert.calledWithExactly(plugin.status.green, 'Ready');
});
});

Expand All @@ -137,88 +132,33 @@ describe('plugins/elasticsearch', () => {
ping.onCall(0).returns(Promise.reject(new NoConnections()));
ping.onCall(1).returns(Promise.resolve());

cluster.callWithInternalUser.withArgs('cluster.health', sinon.match.any).returns(
Promise.resolve({ timed_out: false, status: 'green' })
);

return health.run()
.then(function () {
sinon.assert.calledOnce(plugin.status.yellow);
expect(plugin.status.yellow.args[0][0]).to.be('Waiting for Elasticsearch');
sinon.assert.calledWithExactly(plugin.status.yellow, 'Waiting for Elasticsearch');

sinon.assert.calledOnce(plugin.status.red);
expect(plugin.status.red.args[0][0]).to.be(
sinon.assert.calledWithExactly(
plugin.status.red,
`Unable to connect to Elasticsearch at ${esUrl}.`
);

sinon.assert.calledTwice(ping);
sinon.assert.calledTwice(cluster.callWithInternalUser.withArgs('nodes.info', sinon.match.any));
sinon.assert.calledOnce(cluster.callWithInternalUser.withArgs('cluster.health', sinon.match.any));
sinon.assert.calledOnce(plugin.status.green);
expect(plugin.status.green.args[0][0]).to.be('Kibana index ready');
});
});

it('should set the cluster red if the health check status is red, then to green', function () {
cluster.callWithInternalUser.withArgs('ping').returns(Promise.resolve());

const clusterHealth = cluster.callWithInternalUser.withArgs('cluster.health', sinon.match.any);
clusterHealth.onCall(0).returns(Promise.resolve({ timed_out: false, status: 'red' }));
clusterHealth.onCall(1).returns(Promise.resolve({ timed_out: false, status: 'green' }));

return health.run()
.then(function () {
sinon.assert.calledOnce(plugin.status.yellow);
expect(plugin.status.yellow.args[0][0]).to.be('Waiting for Elasticsearch');
sinon.assert.calledOnce(plugin.status.red);
expect(plugin.status.red.args[0][0]).to.be(
'Elasticsearch is still initializing the kibana index.'
);
sinon.assert.calledOnce(cluster.callWithInternalUser.withArgs('ping'));
sinon.assert.calledTwice(cluster.callWithInternalUser.withArgs('nodes.info', sinon.match.any));
sinon.assert.calledTwice(cluster.callWithInternalUser.withArgs('cluster.health', sinon.match.any));
sinon.assert.calledOnce(plugin.status.green);
expect(plugin.status.green.args[0][0]).to.be('Kibana index ready');
});
});

it('should set the cluster yellow if the health check timed_out and create index', function () {
cluster.callWithInternalUser.withArgs('ping').returns(Promise.resolve());

const clusterHealth = cluster.callWithInternalUser.withArgs('cluster.health', sinon.match.any);
clusterHealth.onCall(0).returns(Promise.resolve({ timed_out: true, status: 'red' }));
clusterHealth.onCall(1).returns(Promise.resolve({ timed_out: false, status: 'green' }));

cluster.callWithInternalUser.withArgs('indices.create', sinon.match.any).returns(Promise.resolve());

return health.run()
.then(function () {
sinon.assert.calledTwice(plugin.status.yellow);
expect(plugin.status.yellow.args[0][0]).to.be('Waiting for Elasticsearch');
expect(plugin.status.yellow.args[1][0]).to.be('No existing Kibana index found');

sinon.assert.calledOnce(cluster.callWithInternalUser.withArgs('ping'));
sinon.assert.calledOnce(cluster.callWithInternalUser.withArgs('indices.create', sinon.match.any));
sinon.assert.calledTwice(cluster.callWithInternalUser.withArgs('nodes.info', sinon.match.any));
sinon.assert.calledTwice(clusterHealth);
sinon.assert.calledWithExactly(plugin.status.green, 'Ready');
});
});

describe('#waitUntilReady', function () {
it('polls health until index is ready, then waits for green status', function () {
const clusterHealth = cluster.callWithInternalUser.withArgs('cluster.health', sinon.match.any);
clusterHealth.onCall(0).returns(Promise.resolve({ timed_out: true }));
clusterHealth.onCall(1).returns(Promise.resolve({ status: 'red' }));
clusterHealth.onCall(2).returns(Promise.resolve({ status: 'green' }));

it('waits for green status', function () {
plugin.status.once = sinon.spy(function (event, handler) {
expect(event).to.be('green');
setImmediate(handler);
});

return health.waitUntilReady().then(function () {
sinon.assert.calledOnce(plugin.status.once);
sinon.assert.calledThrice(clusterHealth);
});
});
});
Expand Down
26 changes: 24 additions & 2 deletions src/core_plugins/elasticsearch/lib/__tests__/patch_kibana_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ function createCallCluster(index) {
return sinon.spy(async (method, params) => {
switch (method) {
case 'indices.get':
expect(params).to.have.property('index', Object.keys(index)[0]);
return cloneDeep(index);
if (!index) {
return { status: 404 };
} else {
expect(params).to.have.property('index', Object.keys(index)[0]);
return cloneDeep(index);
}
case 'indices.putMapping':
return { ok: true };
default:
Expand Down Expand Up @@ -76,6 +80,24 @@ describe('es/healthCheck/patchKibanaIndex()', () => {
});
});

describe('missing index', () => {
it('returns without doing anything', async () => {
const indexName = chance.word();
const mappings = createRandomMappings();
const callCluster = createCallCluster(null);
const log = sinon.stub();
await patchKibanaIndex({
callCluster,
indexName,
kibanaIndexMappingsDsl: mappings,
log
});

sinon.assert.calledOnce(callCluster);
sinon.assert.notCalled(log);
});
});

describe('multi-type index', () => {
it('rejects', async () => {
try {
Expand Down
25 changes: 0 additions & 25 deletions src/core_plugins/elasticsearch/lib/create_kibana_index.js

This file was deleted.

Loading