Skip to content

Commit

Permalink
Add enrich policy endpoint definitions and support for registering X-…
Browse files Browse the repository at this point in the history
…Pack processors to Console (#48258)

* Add template to put enrich policy override.
* Expose addProcessorDefinition method on Console plugin API.
* Add enrichProcessorDefinition.
  • Loading branch information
jakelandis authored and cjcenizal committed Oct 16, 2019
1 parent f4cd288 commit ec38b0e
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { resolve, join, sep } from 'path';
import url from 'url';
import { has, isEmpty, head, pick } from 'lodash';

// @ts-ignore
import { addProcessorDefinition } from './server/api_server/es_6_0/ingest';
// @ts-ignore
import { resolveApi } from './server/api_server/server';
// @ts-ignore
Expand Down Expand Up @@ -119,6 +121,8 @@ export default function(kibana: any) {

async init(server: any, options: any) {
server.expose('addExtensionSpecFilePath', addExtensionSpecFilePath);
server.expose('addProcessorDefinition', addProcessorDefinition);

if (options.ssl && options.ssl.verify) {
throw new Error('sense.ssl.verify is no longer supported.');
}
Expand Down
7 changes: 5 additions & 2 deletions src/legacy/core_plugins/console/server/api_server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class Api {
this.endpoints = {};
this.name = name;
}
addGlobalAutocompleteRules = function (parentNode, rules) {

addGlobalAutocompleteRules = (parentNode, rules) => {
this.globalRules[parentNode] = rules;
}
addEndpointDescription(endpoint, description = {}) {

addEndpointDescription = (endpoint, description = {}) => {
let copiedDescription = {};
if (this.endpoints[endpoint]) {
copiedDescription = { ...this.endpoints[endpoint] };
Expand All @@ -54,6 +56,7 @@ class Api {
patterns: [endpoint],
methods: ['GET']
});

this.endpoints[endpoint] = copiedDescription;
}

Expand Down
3 changes: 2 additions & 1 deletion src/legacy/core_plugins/console/server/api_server/es_6_0.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import Api from './api';
import { getSpec } from './spec';
import { register } from './es_6_0/ingest';
const ES_6_0 = new Api('es_6_0');
const spec = getSpec();

Expand All @@ -33,7 +34,7 @@ require('./es_6_0/aggregations')(ES_6_0);
require('./es_6_0/document')(ES_6_0);
require('./es_6_0/filter')(ES_6_0);
require('./es_6_0/globals')(ES_6_0);
require('./es_6_0/ingest')(ES_6_0);
register(ES_6_0);
require('./es_6_0/mappings')(ES_6_0);
require('./es_6_0/query')(ES_6_0);
require('./es_6_0/reindex')(ES_6_0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,7 @@ const pipelineDefinition = {
version: 123,
};

export default function (api) {

export const register = api => {
// Note: this isn't an actual API endpoint. It exists so the forEach processor's "processor" field
// may recursively use the autocomplete rules for any processor.
api.addEndpointDescription('_processor', {
Expand All @@ -445,13 +444,15 @@ export default function (api) {
data_autocomplete_rules: pipelineDefinition
});



api.addEndpointDescription('ingest.simulate', {
data_autocomplete_rules: {
pipeline: pipelineDefinition,
docs: [
]
}
});
}
};

export const addProcessorDefinition = processor => {
processorDefinition.__one_of.push(processor);
};
11 changes: 9 additions & 2 deletions x-pack/legacy/plugins/console_extensions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

import { join } from 'path';
import { processors } from './spec/ingest';

export function consoleExtensions(kibana) {
return new kibana.Plugin({
id: 'console_extensions',
Expand All @@ -26,11 +28,16 @@ export function consoleExtensions(kibana) {
init: server => {
if (
server.plugins.console &&
server.plugins.console.addExtensionSpecFilePath
server.plugins.console.addExtensionSpecFilePath &&
server.plugins.console.addProcessorDefinition
) {
server.plugins.console.addExtensionSpecFilePath(
const { addExtensionSpecFilePath, addProcessorDefinition } = server.plugins.console;

addExtensionSpecFilePath(
join(__dirname, 'spec/')
);

processors.forEach(processor => addProcessorDefinition(processor));
} else {
console.warn(
'Missing server.plugins.console.addExtensionSpecFilePath extension point.',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"enrich.delete_policy": {
"methods": [
"DELETE"
],
"patterns": [
"_enrich/policy/{name}"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"enrich.execute_policy": {
"url_params": {
"wait_for_completion": "__flag__"
},
"methods": [
"PUT"
],
"patterns": [
"_enrich/policy/{name}/_execute"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"enrich.get_policy": {
"methods": [
"GET"
],
"patterns": [
"_enrich/policy/{name}",
"_enrich/policy"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"enrich.put_policy": {
"methods": [
"PUT"
],
"patterns": [
"_enrich/policy/{name}"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"enrich.stats": {
"methods": [
"GET"
],
"patterns": [
"_enrich/_stats"
]
}
}
42 changes: 42 additions & 0 deletions x-pack/legacy/plugins/console_extensions/spec/ingest/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// NOTE: This is copy-pasted from es_6_0/ingest.js in OSS Console.
const commonPipelineParams = {
on_failure: [],
ignore_failure: {
__one_of: [ false, true ]
},
if: '',
tag: ''
};

// Based on https://www.elastic.co/guide/en/elasticsearch/reference/master/enrich-processor.html
const enrichProcessorDefinition = {
enrich: {
__template: {
policy_name: '',
field: '',
target_field: '',
},
policy_name: '',
field: '',
target_field: '',
ignore_missing: {
__one_of: [ false, true ]
},
override: {
__one_of: [ true, false ]
},
max_matches: 1,
shape_relation: 'INTERSECTS',
...commonPipelineParams
}
};

export const processors = [
enrichProcessorDefinition,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"enrich.put_policy": {
"data_autocomplete_rules": {
"geo_match": {
"__template": {
"indices": "",
"match_field": "",
"enrich_fields": []
},
"indices": "",
"match_field": "",
"enrich_fields": []
},
"match": {
"__template": {
"indices": "",
"match_field": "",
"enrich_fields": []
},
"indices": "",
"match_field": "",
"enrich_fields": []
}
}
}
}

0 comments on commit ec38b0e

Please sign in to comment.