mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
better names for utilities that convert between kibana and ES API document formats
This commit is contained in:
parent
2407f5972e
commit
8f0ffd2402
7 changed files with 36 additions and 36 deletions
|
@ -1,8 +1,8 @@
|
|||
import expect from 'expect.js';
|
||||
import _ from 'lodash';
|
||||
import ingestSimulateApiToEsConverter from '../../converters/ingest_simulate_api_to_es_converter';
|
||||
import ingestSimulateApiKibanaToEsConverter from '../../converters/ingest_simulate_api_kibana_to_es_converter';
|
||||
|
||||
describe('ingestSimulateApiToEsConverter', function () {
|
||||
describe('ingestSimulateApiKibanaToEsConverter', function () {
|
||||
|
||||
it('populates the docs._source section and converts known processors', function () {
|
||||
|
||||
|
@ -34,15 +34,15 @@ describe('ingestSimulateApiToEsConverter', function () {
|
|||
let actual;
|
||||
|
||||
expected = buildExpected(undefined);
|
||||
actual = ingestSimulateApiToEsConverter(buildSamplePipeline(undefined));
|
||||
actual = ingestSimulateApiKibanaToEsConverter(buildSamplePipeline(undefined));
|
||||
expect(actual).to.eql(expected);
|
||||
|
||||
expected = buildExpected('foo');
|
||||
actual = ingestSimulateApiToEsConverter(buildSamplePipeline('foo'));
|
||||
actual = ingestSimulateApiKibanaToEsConverter(buildSamplePipeline('foo'));
|
||||
expect(actual).to.eql(expected);
|
||||
|
||||
expected = buildExpected({ foo: 'bar' });
|
||||
actual = ingestSimulateApiToEsConverter(buildSamplePipeline({ foo: 'bar' }));
|
||||
actual = ingestSimulateApiKibanaToEsConverter(buildSamplePipeline({ foo: 'bar' }));
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
||||
|
||||
|
@ -78,7 +78,7 @@ describe('ingestSimulateApiToEsConverter', function () {
|
|||
]
|
||||
};
|
||||
|
||||
const actual = ingestSimulateApiToEsConverter(pipeline);
|
||||
const actual = ingestSimulateApiKibanaToEsConverter(pipeline);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
|
@ -1,8 +1,8 @@
|
|||
const expect = require('expect.js');
|
||||
const _ = require('lodash');
|
||||
import { processResponse } from '../ingest_simulate';
|
||||
import processESIngestSimulateResponse from '../process_es_ingest_simulate_response';
|
||||
|
||||
describe('processResponse', function () {
|
||||
describe('processESIngestSimulateResponse', function () {
|
||||
|
||||
it('returns a result for each processor in the pipeline', function () {
|
||||
const pipeline = {
|
||||
|
@ -12,7 +12,7 @@ describe('processResponse', function () {
|
|||
docs: [ { processor_results: [] } ]
|
||||
};
|
||||
|
||||
const results = processResponse(pipeline, null, response);
|
||||
const results = processESIngestSimulateResponse(pipeline, response);
|
||||
expect(results.length).to.be(2);
|
||||
});
|
||||
|
||||
|
@ -33,7 +33,7 @@ describe('processResponse', function () {
|
|||
{ processorId: 'processor2', output: 'bar', error: undefined },
|
||||
{ processorId: 'processor3', output: 'baz', error: undefined }
|
||||
];
|
||||
const actual = processResponse(pipeline, null, response);
|
||||
const actual = processESIngestSimulateResponse(pipeline, response);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
||||
|
@ -58,7 +58,7 @@ describe('processResponse', function () {
|
|||
{ processorId: 'processor2', output: 'new_bar', error: undefined },
|
||||
{ processorId: 'processor3', output: 'new_baz', error: undefined }
|
||||
];
|
||||
const actual = processResponse(pipeline, null, response);
|
||||
const actual = processESIngestSimulateResponse(pipeline, response);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
||||
|
@ -89,7 +89,7 @@ describe('processResponse', function () {
|
|||
{ processorId: 'processor2', output: 'new_bar', error: undefined },
|
||||
{ processorId: 'processor3', output: undefined, error: { isNested: false, message: 'something bad happened'} }
|
||||
];
|
||||
const actual = processResponse(pipeline, null, response);
|
||||
const actual = processESIngestSimulateResponse(pipeline, response);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
||||
|
@ -118,7 +118,7 @@ describe('processResponse', function () {
|
|||
{ processorId: 'processor2', output: 'new_bar', error: undefined },
|
||||
{ processorId: 'processor3', output: undefined, error: { isNested: false, message: 'something bad happened'} }
|
||||
];
|
||||
const actual = processResponse(pipeline, null, response);
|
||||
const actual = processESIngestSimulateResponse(pipeline, response);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
||||
|
@ -153,7 +153,7 @@ describe('processResponse', function () {
|
|||
{ processorId: 'processor2', output: undefined, error: { isNested: true, message: 'Invalid Parent Processor' } },
|
||||
{ processorId: 'processor3', output: undefined, error: { isNested: true, message: 'Invalid Parent Processor' } }
|
||||
];
|
||||
const actual = processResponse(pipeline, null, response);
|
||||
const actual = processESIngestSimulateResponse(pipeline, response);
|
||||
|
||||
expect(actual).to.eql(expected);
|
||||
});
|
|
@ -0,0 +1,17 @@
|
|||
import _ from 'lodash';
|
||||
import * as ingestProcessorApiKibanaToEsConverters from './ingest_processor_api_kibana_to_es_converters';
|
||||
|
||||
export default function ingestSimulateApiKibanaToEsConverter(simulateApiDocument) {
|
||||
return {
|
||||
pipeline: {
|
||||
processors: _.map(simulateApiDocument.processors, (processor) => {
|
||||
return ingestProcessorApiKibanaToEsConverters[processor.type_id](processor);
|
||||
})
|
||||
},
|
||||
docs: [
|
||||
{
|
||||
_source: simulateApiDocument.input
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
import _ from 'lodash';
|
||||
import * as ingestProcessorApiToEsConverters from './ingest_processor_api_to_es_converters';
|
||||
|
||||
export default function ingestSimulateApiToEsConverter(simulateApiDocument) {
|
||||
return {
|
||||
pipeline: {
|
||||
processors: _.map(simulateApiDocument.processors, (processor) => {
|
||||
return ingestProcessorApiToEsConverters[processor.type_id](processor);
|
||||
})
|
||||
},
|
||||
docs: [
|
||||
{
|
||||
_source: simulateApiDocument.input
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
|
@ -6,7 +6,7 @@ function translateError(esError) {
|
|||
return _.get(rootCause, 'reason') || _.get(rootCause, 'type');
|
||||
}
|
||||
|
||||
export function processResponse(simulateApiDocument, resp) {
|
||||
export default function processESIngestSimulateResponse(simulateApiDocument, resp) {
|
||||
const results = simulateApiDocument.processors.map((processor) => {
|
||||
return {
|
||||
processorId: processor.processor_id,
|
|
@ -1,7 +1,7 @@
|
|||
import _ from 'lodash';
|
||||
import { processResponse } from '../../../lib/ingest_simulate';
|
||||
import processESIngestSimulateResponse from '../../../lib/process_es_ingest_simulate_response';
|
||||
import simulateRequestSchema from '../../../lib/schemas/simulate_request_schema';
|
||||
import ingestSimulateApiToEsConverter from '../../../lib/converters/ingest_simulate_api_to_es_converter';
|
||||
import ingestSimulateApiKibanaToEsConverter from '../../../lib/converters/ingest_simulate_api_kibana_to_es_converter';
|
||||
|
||||
module.exports = function registerSimulate(server) {
|
||||
server.route({
|
||||
|
@ -15,7 +15,7 @@ module.exports = function registerSimulate(server) {
|
|||
handler: function (request, reply) {
|
||||
const boundCallWithRequest = _.partial(server.plugins.elasticsearch.callWithRequest, request);
|
||||
const simulateApiDocument = request.payload;
|
||||
const body = ingestSimulateApiToEsConverter(simulateApiDocument);
|
||||
const body = ingestSimulateApiKibanaToEsConverter(simulateApiDocument);
|
||||
|
||||
return boundCallWithRequest('transport.request', {
|
||||
path: '_ingest/pipeline/_simulate',
|
||||
|
@ -23,7 +23,7 @@ module.exports = function registerSimulate(server) {
|
|||
method: 'POST',
|
||||
body: body
|
||||
})
|
||||
.then(_.partial(processResponse, simulateApiDocument))
|
||||
.then(_.partial(processESIngestSimulateResponse, simulateApiDocument))
|
||||
.then(reply);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue