mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[add data] Attempts to deal with unhandled errors in the ingest API
This commit is contained in:
parent
4fb1118266
commit
c63a5a2c76
7 changed files with 62 additions and 29 deletions
|
@ -13,7 +13,7 @@ describe('processESIngestSimulateError', function () {
|
|||
];
|
||||
const actual = processESIngestSimulateError(dirtyProcessorId, error);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
expect(_.isEqual(actual, expected)).to.be.ok();
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
const _ = require('lodash');
|
||||
|
||||
function buildError(error) {
|
||||
const errorMessage = _.get(error, 'body.error.reason');
|
||||
const errorMessage = _.get(error, 'body.error.root_cause[0].reason');
|
||||
if (!errorMessage) throw error;
|
||||
|
||||
return {
|
||||
compile: true,
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
const _ = require('lodash');
|
||||
|
||||
function translateError(esError) {
|
||||
const rootCause = _.get(esError, 'root_cause[0]');
|
||||
|
||||
return _.get(rootCause, 'reason') || _.get(rootCause, 'type');
|
||||
}
|
||||
|
||||
function buildError(error) {
|
||||
const errorMessage = translateError(error);
|
||||
const errorMessage = _.get(error, 'root_cause[0].reason') || _.get(error, 'root_cause[0].type');
|
||||
if (!errorMessage) return;
|
||||
|
||||
return {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import _ from 'lodash';
|
||||
import handleESError from '../../../lib/handle_es_error';
|
||||
import handleResponse from '../../../lib/process_es_ingest_simulate_response';
|
||||
import processESIngestSimulateError from '../../../lib/process_es_ingest_simulate_error';
|
||||
import simulateRequestSchema from '../../../lib/schemas/simulate_request_schema';
|
||||
|
@ -29,7 +30,10 @@ export function registerSimulate(server) {
|
|||
})
|
||||
.then(handleResponse, handleError)
|
||||
.then((processors) => _.map(processors, keysToSnakeCaseShallow))
|
||||
.then(reply);
|
||||
.then(reply)
|
||||
.catch((error) => {
|
||||
reply(handleESError(error));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -34,6 +34,14 @@ define(function (require) {
|
|||
// All processors must have a processorId property and a typeId property
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send({input: {}, processors: [{}]})
|
||||
.expect(400),
|
||||
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send({input: {}, processors: ['foo']})
|
||||
.expect(400),
|
||||
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send({input: {}, processors: 'foo'})
|
||||
.expect(400)
|
||||
]);
|
||||
});
|
||||
|
|
|
@ -7,57 +7,81 @@ define(function (require) {
|
|||
processors: [{
|
||||
processor_id: 'processor1',
|
||||
type_id: 'gsub',
|
||||
target_field: 'foo',
|
||||
value: 'bar'
|
||||
source_field: 'foo',
|
||||
pattern: 'bar',
|
||||
replacement: 'baz'
|
||||
}],
|
||||
input: {}
|
||||
input: { foo: 'bar' }
|
||||
};
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
bdd.describe('simulate - set processor', function simulatePipeline() {
|
||||
bdd.describe('simulate - gsub processor', () => {
|
||||
|
||||
bdd.it('should return 400 for an invalid payload', function invalidPayload() {
|
||||
bdd.it('should return 400 for an invalid payload', () => {
|
||||
return Promise.all([
|
||||
// Set processor requires targetField property
|
||||
// GSub processor requires targetField property
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send({
|
||||
input: {},
|
||||
input: { foo: 'bar' },
|
||||
processors: [{
|
||||
processor_id: 'processor1',
|
||||
type_id: 'set',
|
||||
value: 'bar',
|
||||
target_field: 42
|
||||
type_id: 'gsub',
|
||||
source_field: 42,
|
||||
pattern: 'bar',
|
||||
replacement: 'baz'
|
||||
}]
|
||||
})
|
||||
.expect(400)
|
||||
]);
|
||||
});
|
||||
|
||||
bdd.it('should return 200 for a valid simulate request', function validSetSimulate() {
|
||||
bdd.it('should return a compile error object for a processor with an invalid regex', () => {
|
||||
return Promise.all([
|
||||
// non-escaped square bracket is an invalid regex
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send({
|
||||
input: { foo: 'bar' },
|
||||
processors: [{
|
||||
processor_id: 'processor1',
|
||||
type_id: 'gsub',
|
||||
source_field: 'foo',
|
||||
pattern: '[',
|
||||
replacement: 'baz'
|
||||
}]
|
||||
})
|
||||
.expect(200)
|
||||
.then((response) => {
|
||||
expect(response.body[0].error.compile).to.be(true);
|
||||
})
|
||||
]);
|
||||
});
|
||||
|
||||
bdd.it('should return 200 for a valid simulate request', () => {
|
||||
return request.post('/kibana/ingest/simulate')
|
||||
.send(testPipeline)
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
bdd.it('should return a simulated output with the correct result for the given processor', function () {
|
||||
bdd.it('should return a simulated output with the correct result for the given processor', () => {
|
||||
return request.post('/kibana/ingest/simulate')
|
||||
.send(testPipeline)
|
||||
.expect(200)
|
||||
.then(function (response) {
|
||||
expect(response.body[0].output.foo).to.be.equal('bar');
|
||||
.then((response) => {
|
||||
expect(response.body[0].output.foo).to.be.equal('baz');
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should enforce snake case', function setSimulateSnakeCase() {
|
||||
bdd.it('should enforce snake case', () => {
|
||||
return request.post('/kibana/ingest/simulate')
|
||||
.send({
|
||||
processors: [{
|
||||
processorId: 'processor1',
|
||||
typeId: 'set',
|
||||
targetField: 'foo',
|
||||
value: 'bar'
|
||||
typeId: 'gsub',
|
||||
sourceField: 'foo',
|
||||
pattern: 'bar',
|
||||
replacement: 'baz'
|
||||
}],
|
||||
input: {}
|
||||
input: { foo: 'bar' }
|
||||
})
|
||||
.expect(400);
|
||||
});
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
define(function (require) {
|
||||
var set = require('./_set');
|
||||
var gsub = require('./_gsub');
|
||||
|
||||
return function processors(bdd, scenarioManager, request) {
|
||||
set(bdd, scenarioManager, request);
|
||||
gsub(bdd, scenarioManager, request);
|
||||
};
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue