mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[add data] Finished adding the append processor
This commit is contained in:
parent
34dcd7f785
commit
7de50bf2bd
8 changed files with 133 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
|||
import './processor_ui_container';
|
||||
import './processor_ui_append';
|
||||
import './processor_ui_gsub';
|
||||
import './processor_ui_set';
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
import uiModules from 'ui/modules';
|
||||
import template from '../views/processor_ui_append.html';
|
||||
|
||||
const app = uiModules.get('kibana');
|
||||
|
||||
//scope.processor, scope.pipeline are attached by the process_container.
|
||||
app.directive('processorUiAppend', function () {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: template,
|
||||
controller : function ($scope) {
|
||||
const processor = $scope.processor;
|
||||
const pipeline = $scope.pipeline;
|
||||
|
||||
function processorUiChanged() {
|
||||
pipeline.setDirty();
|
||||
}
|
||||
|
||||
function splitValues(delimitedList) {
|
||||
return delimitedList.split('\n');
|
||||
}
|
||||
|
||||
function joinValues(valueArray) {
|
||||
return valueArray.join('\n');
|
||||
}
|
||||
|
||||
function updateValues() {
|
||||
processor.values = splitValues($scope.values);
|
||||
}
|
||||
|
||||
$scope.values = joinValues(processor.values);
|
||||
|
||||
$scope.$watch('values', updateValues);
|
||||
$scope.$watch('processor.targetField', processorUiChanged);
|
||||
$scope.$watchCollection('processor.values', processorUiChanged);
|
||||
}
|
||||
};
|
||||
});
|
|
@ -39,7 +39,7 @@ export class Append extends Processor {
|
|||
processorId: this.processorId,
|
||||
typeId: this.typeId,
|
||||
targetField: this.targetField || '',
|
||||
value: this.values || []
|
||||
values: this.values || []
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<div class="form-group">
|
||||
<label>Target Field:</label>
|
||||
<input type="text" class="form-control" ng-model="processor.targetField">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Values:</label><span> (line delimited)</span>
|
||||
<textarea ng-model="values" style="display:block; width:100%; height:150px;"></textarea>
|
||||
</div>
|
|
@ -1,3 +1,13 @@
|
|||
export function append(processorApiDocument) {
|
||||
return {
|
||||
append: {
|
||||
tag: processorApiDocument.processor_id,
|
||||
field: processorApiDocument.target_field,
|
||||
value: processorApiDocument.values
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function gsub(processorApiDocument) {
|
||||
return {
|
||||
gsub: {
|
||||
|
|
|
@ -4,6 +4,12 @@ const base = Joi.object({
|
|||
processor_id: Joi.string().required()
|
||||
});
|
||||
|
||||
export const append = base.keys({
|
||||
type_id: Joi.string().only('append').required(),
|
||||
target_field: Joi.string().allow(''),
|
||||
values: Joi.array().items(Joi.string().allow(''))
|
||||
});
|
||||
|
||||
export const gsub = base.keys({
|
||||
type_id: Joi.string().only('gsub').required(),
|
||||
source_field: Joi.string().allow(''),
|
||||
|
|
67
test/unit/api/ingest/processors/_append.js
Normal file
67
test/unit/api/ingest/processors/_append.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
define(function (require) {
|
||||
var Promise = require('bluebird');
|
||||
var _ = require('intern/dojo/node!lodash');
|
||||
var expect = require('intern/dojo/node!expect.js');
|
||||
|
||||
const testPipeline = {
|
||||
processors: [{
|
||||
processor_id: 'processor1',
|
||||
type_id: 'append',
|
||||
target_field: 'foo',
|
||||
values: [ 'value1', 'value2' ]
|
||||
}],
|
||||
input: {}
|
||||
};
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
bdd.describe('simulate - append processor', () => {
|
||||
|
||||
bdd.it('should return 400 for an invalid payload', () => {
|
||||
return Promise.all([
|
||||
// Append processor requires targetField property
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send({
|
||||
input: {},
|
||||
processors: [{
|
||||
processor_id: 'processor1',
|
||||
type_id: 'append',
|
||||
values: [ 'value1', 'value2' ],
|
||||
target_field: 42
|
||||
}]
|
||||
})
|
||||
.expect(400)
|
||||
]);
|
||||
});
|
||||
|
||||
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', () => {
|
||||
return request.post('/kibana/ingest/simulate')
|
||||
.send(testPipeline)
|
||||
.expect(200)
|
||||
.then(function (response) {
|
||||
expect(response.body[0].output.foo).to.be.eql([ 'value1', 'value2' ]);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should enforce snake case', () => {
|
||||
return request.post('/kibana/ingest/simulate')
|
||||
.send({
|
||||
processors: [{
|
||||
processorId: 'processor1',
|
||||
typeId: 'append',
|
||||
targetField: 'foo',
|
||||
value: [ 'value1', 'value2' ]
|
||||
}],
|
||||
input: {}
|
||||
})
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
});
|
|
@ -1,10 +1,12 @@
|
|||
define(function (require) {
|
||||
var set = require('./_set');
|
||||
var gsub = require('./_gsub');
|
||||
var append = require('./_append');
|
||||
|
||||
return function processors(bdd, scenarioManager, request) {
|
||||
set(bdd, scenarioManager, request);
|
||||
gsub(bdd, scenarioManager, request);
|
||||
append(bdd, scenarioManager, request);
|
||||
};
|
||||
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue