mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[add data] adds convert processor
This commit is contained in:
parent
889c9c1a73
commit
930a44dfa9
8 changed files with 171 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
|||
import './processor_ui_container';
|
||||
import './processor_ui_convert';
|
||||
import './processor_ui_gsub';
|
||||
import './processor_ui_set';
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import uiModules from 'ui/modules';
|
||||
import template from '../views/processor_ui_convert.html';
|
||||
import _ from 'lodash';
|
||||
import keysDeep from '../lib/keys_deep';
|
||||
|
||||
const app = uiModules.get('kibana');
|
||||
|
||||
//scope.processor, scope.pipeline are attached by the process_container.
|
||||
app.directive('processorUiConvert', function () {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: template,
|
||||
controller : function ($scope) {
|
||||
const processor = $scope.processor;
|
||||
const pipeline = $scope.pipeline;
|
||||
|
||||
function consumeNewInputObject() {
|
||||
$scope.fields = keysDeep(processor.inputObject);
|
||||
refreshFieldData();
|
||||
}
|
||||
|
||||
function refreshFieldData() {
|
||||
$scope.fieldData = _.get(processor.inputObject, processor.sourceField);
|
||||
}
|
||||
|
||||
function processorUiChanged() {
|
||||
pipeline.setDirty();
|
||||
}
|
||||
|
||||
$scope.types = ['integer', 'float', 'string', 'boolean'];
|
||||
|
||||
$scope.$watch('processor.inputObject', consumeNewInputObject);
|
||||
|
||||
$scope.$watch('processor.sourceField', () => {
|
||||
refreshFieldData();
|
||||
processorUiChanged();
|
||||
});
|
||||
|
||||
$scope.$watch('processor.type', processorUiChanged);
|
||||
}
|
||||
};
|
||||
});
|
|
@ -22,6 +22,29 @@ class Processor {
|
|||
}
|
||||
}
|
||||
|
||||
export class Convert extends Processor {
|
||||
constructor(processorId) {
|
||||
super(processorId, 'convert', 'Convert');
|
||||
this.sourceField = '';
|
||||
this.type = 'string';
|
||||
}
|
||||
|
||||
get description() {
|
||||
const source = this.sourceField || '?';
|
||||
const type = this.type || '?';
|
||||
return `[${source}] to ${type}`;
|
||||
}
|
||||
|
||||
get model() {
|
||||
return {
|
||||
processorId: this.processorId,
|
||||
typeId: this.typeId,
|
||||
sourceField: this.sourceField || '',
|
||||
type: this.type || 'string'
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export class Gsub extends Processor {
|
||||
constructor(processorId) {
|
||||
super(processorId, 'gsub', 'Gsub');
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<div class="form-group">
|
||||
<label>Field:</label>
|
||||
<select
|
||||
class="form-control"
|
||||
ng-options="field as field for field in fields"
|
||||
ng-model="processor.sourceField">
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Field Data:</label>
|
||||
<pre>{{ fieldData }}</pre>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Type:</label>
|
||||
<select
|
||||
class="form-control"
|
||||
ng-options="type as type for type in types"
|
||||
ng-model="processor.type">
|
||||
</select>
|
||||
</div>
|
|
@ -1,3 +1,13 @@
|
|||
export function convert(processorApiDocument) {
|
||||
return {
|
||||
convert: {
|
||||
tag: processorApiDocument.processor_id,
|
||||
field: processorApiDocument.source_field,
|
||||
type: processorApiDocument.type
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function gsub(processorApiDocument) {
|
||||
return {
|
||||
gsub: {
|
||||
|
|
|
@ -4,6 +4,12 @@ const base = Joi.object({
|
|||
processor_id: Joi.string().required()
|
||||
});
|
||||
|
||||
export const convert = base.keys({
|
||||
type_id: Joi.string().only('convert').required(),
|
||||
source_field: Joi.string().allow(''),
|
||||
type: Joi.string()
|
||||
});
|
||||
|
||||
export const gsub = base.keys({
|
||||
type_id: Joi.string().only('gsub').required(),
|
||||
source_field: Joi.string().allow(''),
|
||||
|
|
67
test/unit/api/ingest/processors/_convert.js
Normal file
67
test/unit/api/ingest/processors/_convert.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: 'convert',
|
||||
source_field: 'foo',
|
||||
type: 'integer'
|
||||
}],
|
||||
input: { foo: '1234' }
|
||||
};
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
bdd.describe('simulate - convert processor', () => {
|
||||
|
||||
bdd.it('should return 400 for an invalid payload', () => {
|
||||
return Promise.all([
|
||||
// Convert processor requires targetField property
|
||||
request.post('/kibana/ingest/simulate')
|
||||
.send({
|
||||
input: {},
|
||||
processors: [{
|
||||
processor_id: 'processor1',
|
||||
type_id: 'convert',
|
||||
value: 'integer',
|
||||
source_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', function () {
|
||||
return request.post('/kibana/ingest/simulate')
|
||||
.send(testPipeline)
|
||||
.expect(200)
|
||||
.then(function (response) {
|
||||
expect(response.body[0].output.foo).to.be(1234);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should enforce snake case', () => {
|
||||
return request.post('/kibana/ingest/simulate')
|
||||
.send({
|
||||
processors: [{
|
||||
processorId: 'processor1',
|
||||
typeId: 'convert',
|
||||
sourceField: 'foo',
|
||||
type: 'string'
|
||||
}],
|
||||
input: {}
|
||||
})
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
});
|
|
@ -1,8 +1,10 @@
|
|||
define(function (require) {
|
||||
var convert = require('./_convert');
|
||||
var set = require('./_set');
|
||||
var gsub = require('./_gsub');
|
||||
|
||||
return function processors(bdd, scenarioManager, request) {
|
||||
convert(bdd, scenarioManager, request);
|
||||
set(bdd, scenarioManager, request);
|
||||
gsub(bdd, scenarioManager, request);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue