This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ingest] Creates the simulate api route
- Loading branch information
Showing
8 changed files
with
557 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,22 @@ | ||
const _ = require('lodash'); | ||
|
||
export default [ | ||
{ // set | ||
typeId: 'set', | ||
title: 'Set', | ||
targetField: '', | ||
getDefinition: function (processor) { | ||
return { | ||
'set' : { | ||
'tag': processor.processorId, | ||
'field' : processor.targetField ? processor.targetField : '', | ||
'value': processor.value ? processor.value : '' | ||
} | ||
}; | ||
}, | ||
getDescription: function (processor) { | ||
const target = (processor.targetField) ? processor.targetField : '?'; | ||
return `[${target}]`; | ||
} | ||
} | ||
]; |
This file contains 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,87 @@ | ||
var expect = require('expect.js'); | ||
var sinon = require('sinon'); | ||
|
||
var keysDeep = require('../keys_deep'); | ||
|
||
describe('keys deep', function () { | ||
|
||
it('should list first level properties', function () { | ||
let object = { | ||
property1: 'value1', | ||
property2: 'value2' | ||
}; | ||
let expected = [ | ||
'property1', | ||
'property2' | ||
]; | ||
|
||
const keys = keysDeep(object); | ||
|
||
expect(keys).to.eql(expected); | ||
}); | ||
|
||
it('should list nested properties', function () { | ||
let object = { | ||
property1: 'value1', | ||
property2: 'value2', | ||
property3: { | ||
subProperty1: 'value1.1' | ||
} | ||
}; | ||
let expected = [ | ||
'property1', | ||
'property2', | ||
'property3.subProperty1', | ||
'property3' | ||
]; | ||
|
||
const keys = keysDeep(object); | ||
|
||
expect(keys).to.eql(expected); | ||
}); | ||
|
||
it('should recursivly list nested properties', function () { | ||
let object = { | ||
property1: 'value1', | ||
property2: 'value2', | ||
property3: { | ||
subProperty1: 'value1.1', | ||
subProperty2: { | ||
prop1: 'value1.2.1', | ||
prop2: 'value2.2.2' | ||
}, | ||
subProperty3: 'value1.3' | ||
} | ||
}; | ||
let expected = [ | ||
'property1', | ||
'property2', | ||
'property3.subProperty1', | ||
'property3.subProperty2.prop1', | ||
'property3.subProperty2.prop2', | ||
'property3.subProperty2', | ||
'property3.subProperty3', | ||
'property3' | ||
]; | ||
|
||
const keys = keysDeep(object); | ||
|
||
expect(keys).to.eql(expected); | ||
}); | ||
|
||
it('should list array properties, but not contents', function () { | ||
let object = { | ||
property1: 'value1', | ||
property2: [ 'item1', 'item2' ] | ||
}; | ||
let expected = [ | ||
'property1', | ||
'property2' | ||
]; | ||
|
||
const keys = keysDeep(object); | ||
|
||
expect(keys).to.eql(expected); | ||
}); | ||
|
||
}); |
This file contains 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,21 @@ | ||
const _ = require('lodash'); | ||
|
||
export default function keysDeep(object, base) { | ||
let result = []; | ||
let delimitedBase = base ? base + '.' : ''; | ||
|
||
_.forEach(object, (value, key) => { | ||
var fullKey = delimitedBase + key; | ||
if (_.isPlainObject(value)) { | ||
result = result.concat(keysDeep(value, fullKey)); | ||
} else { | ||
result.push(fullKey); | ||
} | ||
}); | ||
|
||
if (base) { | ||
result.push(base); | ||
} | ||
|
||
return result; | ||
}; |
158 changes: 158 additions & 0 deletions
158
src/plugins/kibana/server/lib/__tests__/ingest_simulate_build_request.js
This file contains 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,158 @@ | ||
const expect = require('expect.js'); | ||
const _ = require('lodash'); | ||
import { buildRequest } from '../ingest_simulate'; | ||
|
||
describe('buildRequest', function () { | ||
|
||
const processorTypes = [ | ||
{ | ||
typeId: 'simple1', | ||
getDefinition: function (processor) { | ||
return { | ||
'modified_value': `modified_${processor.value}` | ||
}; | ||
} | ||
}, | ||
{ | ||
typeId: 'simple2', | ||
getDefinition: function (processor) { | ||
return { | ||
'value1': processor.value, | ||
'value2': `${processor.typeId}-${processor.value}` | ||
}; | ||
} | ||
} | ||
]; | ||
|
||
it('should throw an error if no processorTypes argument is passed or the argument is not a plain object', function () { | ||
expect(buildRequest).to.throwException(/requires a processorTypes object array argument/); | ||
expect(buildRequest).withArgs('').to.throwException(/requires a processorTypes object array argument/); | ||
expect(buildRequest).withArgs({}).to.throwException(/requires a processorTypes object array argument/); | ||
expect(buildRequest).withArgs([]).to.throwException(/requires a processorTypes object array argument/); | ||
}); | ||
|
||
it('should throw an error if no pipeline argument is passed or the argument is not a plain object', function () { | ||
expect(buildRequest).withArgs([{}], []).to.throwException(/requires a pipeline object argument/); | ||
}); | ||
|
||
it('should throw an error if pipeline contains no processors', function () { | ||
expect(buildRequest).withArgs([{}], {}).to.throwException(/pipeline contains no processors/); | ||
expect(buildRequest).withArgs([{}], { processors: 'foo' }).to.throwException(/pipeline contains no processors/); | ||
expect(buildRequest).withArgs([{}], { processors: {} }).to.throwException(/pipeline contains no processors/); | ||
expect(buildRequest).withArgs([{}], { processors: [] }).to.throwException(/pipeline contains no processors/); | ||
}); | ||
|
||
it('populates the docs._source section', function () { | ||
|
||
function buildSamplePipeline(input) { | ||
return { | ||
processors: [ { typeId: 'simple1', value: 'foo' } ], | ||
input: input | ||
}; | ||
} | ||
|
||
function buildExpected(input) { | ||
return { | ||
'pipeline' : { | ||
'processors': [ { modified_value: 'modified_foo' } ] | ||
}, | ||
'docs' : [ | ||
{ '_source': input } | ||
] | ||
}; | ||
} | ||
|
||
let expected; | ||
let actual; | ||
|
||
expected = buildExpected(undefined); | ||
actual = buildRequest(processorTypes, buildSamplePipeline(undefined)); | ||
expect(actual).to.eql(expected); | ||
|
||
expected = buildExpected('foo'); | ||
actual = buildRequest(processorTypes, buildSamplePipeline('foo')); | ||
expect(actual).to.eql(expected); | ||
|
||
expected = buildExpected({ foo: 'bar' }); | ||
actual = buildRequest(processorTypes, buildSamplePipeline({ foo: 'bar' })); | ||
expect(actual).to.eql(expected); | ||
}); | ||
|
||
describe('populates the pipeline.processors section with type.getDefinition()', function () { | ||
|
||
it(' - single processor type', function () { | ||
const pipeline = { | ||
processors: [ { typeId: 'simple1', value: 'foo' } ], | ||
input: {} | ||
}; | ||
const expected = { | ||
'pipeline' : { | ||
'processors': [ { modified_value: 'modified_foo' } ] | ||
}, | ||
'docs' : [ | ||
{ '_source': {} } | ||
] | ||
}; | ||
|
||
const actual = buildRequest(processorTypes, pipeline); | ||
|
||
expect(actual).to.eql(expected); | ||
}); | ||
|
||
it(' - multiple of same type of processor type', function () { | ||
const pipeline = { | ||
processors: [ | ||
{ typeId: 'simple1', value: 'foo' }, | ||
{ typeId: 'simple1', value: 'bar' }, | ||
{ typeId: 'simple1', value: 'baz' } | ||
], | ||
input: {} | ||
}; | ||
const expected = { | ||
'pipeline' : { | ||
'processors': [ | ||
{ modified_value: 'modified_foo' }, | ||
{ modified_value: 'modified_bar' }, | ||
{ modified_value: 'modified_baz' } | ||
] | ||
}, | ||
'docs' : [ | ||
{ '_source': {} } | ||
] | ||
}; | ||
|
||
const actual = buildRequest(processorTypes, pipeline); | ||
|
||
expect(actual).to.eql(expected); | ||
}); | ||
|
||
it(' - multiple processor types', function () { | ||
const pipeline = { | ||
processors: [ | ||
{ typeId: 'simple1', value: 'foo' }, | ||
{ typeId: 'simple2', value: 'bar' }, | ||
{ typeId: 'simple1', value: 'baz' } | ||
], | ||
input: {} | ||
}; | ||
const expected = { | ||
'pipeline' : { | ||
'processors': [ | ||
{ modified_value: 'modified_foo' }, | ||
{ value1: 'bar', value2: 'simple2-bar' }, | ||
{ modified_value: 'modified_baz' } | ||
] | ||
}, | ||
'docs' : [ | ||
{ '_source': {} } | ||
] | ||
}; | ||
|
||
const actual = buildRequest(processorTypes, pipeline); | ||
|
||
expect(actual).to.eql(expected); | ||
}); | ||
|
||
}); | ||
|
||
}); |
Oops, something went wrong.