From ab5aebd5c8a61e1ea52a19230460a293b3222da7 Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Tue, 8 Mar 2016 17:48:31 -0500 Subject: [PATCH 1/2] Added some tests for pipelines in the ingest POST endpoint --- .../schemas/resources/ingest_config_schema.js | 2 +- .../server/routes/api/ingest/register_post.js | 7 +++++- test/unit/api/ingest/_post.js | 24 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/plugins/kibana/server/lib/schemas/resources/ingest_config_schema.js b/src/plugins/kibana/server/lib/schemas/resources/ingest_config_schema.js index 023f6c2f66be0..1cccff7ee95fd 100644 --- a/src/plugins/kibana/server/lib/schemas/resources/ingest_config_schema.js +++ b/src/plugins/kibana/server/lib/schemas/resources/ingest_config_schema.js @@ -4,5 +4,5 @@ const pipelineSchema = require('./pipeline_schema'); module.exports = Joi.object({ index_pattern: indexPatternSchema.required(), - pipeline: pipelineSchema.required() + pipeline: pipelineSchema }); diff --git a/src/plugins/kibana/server/routes/api/ingest/register_post.js b/src/plugins/kibana/server/routes/api/ingest/register_post.js index 9ff7281db5417..4d9b22fb74331 100644 --- a/src/plugins/kibana/server/routes/api/ingest/register_post.js +++ b/src/plugins/kibana/server/routes/api/ingest/register_post.js @@ -67,6 +67,7 @@ module.exports = function registerPost(server) { const indexPattern = keysToCamelCaseShallow(requestDocument.index_pattern); const indexPatternId = indexPattern.id; const ingestConfigName = patternToIngest(indexPatternId); + const shouldCreatePipeline = !_.isEmpty(requestDocument.pipeline); delete indexPattern.id; const mappings = createMappingsFromPatternFields(indexPattern.fields); @@ -132,7 +133,11 @@ module.exports = function registerPost(server) { return boundCallWithRequest('indices.putTemplate', templateParams) .catch((templateError) => {return patternRollback(templateError, indexPatternId, boundCallWithRequest);}); }) - .then(() => { + .then((templateResponse) => { + if (!shouldCreatePipeline) { + return templateResponse; + } + return boundCallWithRequest('transport.request', pipelineParams) .catch((pipelineError) => {return templateRollback(pipelineError, ingestConfigName, boundCallWithRequest);}) .catch((templateRollbackError) => {return patternRollback(templateRollbackError, indexPatternId, boundCallWithRequest);}); diff --git a/test/unit/api/ingest/_post.js b/test/unit/api/ingest/_post.js index 7f9b1c5c0b394..7af56e4014236 100644 --- a/test/unit/api/ingest/_post.js +++ b/test/unit/api/ingest/_post.js @@ -113,6 +113,30 @@ define(function (require) { }); }); + bdd.it('should create a pipeline if one is included in the request', function () { + return request.post('/kibana/ingest') + .send(createTestData()) + .expect(204) + .then(function () { + return scenarioManager.client.transport.request({ + path: '_ingest/pipeline/kibana-logstash-*', + method: 'GET' + }) + .then(function (body) { + expect(body.pipelines[0].id).to.be('kibana-logstash-*'); + }); + }); + }); + + bdd.it('pipeline should be optional', function optionalPipeline() { + const payload = createTestData(); + delete payload.pipeline; + + return request.post('/kibana/ingest') + .send(payload) + .expect(204); + }); + bdd.it('should return 409 conflict when a pattern with the given ID already exists', function patternConflict() { return request.post('/kibana/ingest') .send(createTestData()) From 8f5777ed225a8f4a5f550dda39498100ddbf8cde Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Tue, 8 Mar 2016 17:54:23 -0500 Subject: [PATCH 2/2] Add pipeline to api tests for ingest DELETE endpoint --- test/unit/api/ingest/_del.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/api/ingest/_del.js b/test/unit/api/ingest/_del.js index f834d39fe9948..3d174c45feeec 100644 --- a/test/unit/api/ingest/_del.js +++ b/test/unit/api/ingest/_del.js @@ -41,6 +41,15 @@ define(function (require) { .catch(function (error) { expect(error.status).to.be(404); }); + }) + .then(function () { + return scenarioManager.client.transport.request({ + path: '_ingest/pipeline/kibana-logstash-*', + method: 'GET' + }) + .catch(function (error) { + expect(error.status).to.be(404); + }); }); });