From ec38b0ed5f3a61f9c40ded3b8e4b604ad534016c Mon Sep 17 00:00:00 2001 From: Jake Landis Date: Tue, 15 Oct 2019 21:26:59 -0500 Subject: [PATCH] Add enrich policy endpoint definitions and support for registering X-Pack processors to Console (#48258) * Add template to put enrich policy override. * Expose addProcessorDefinition method on Console plugin API. * Add enrichProcessorDefinition. --- src/legacy/core_plugins/console/index.ts | 4 ++ .../console/server/api_server/api.js | 7 +++- .../console/server/api_server/es_6_0.js | 3 +- .../server/api_server/es_6_0/ingest.js | 11 ++--- .../plugins/console_extensions/index.js | 11 ++++- .../spec/generated/enrich.delete_policy.json | 10 +++++ .../spec/generated/enrich.execute_policy.json | 13 ++++++ .../spec/generated/enrich.get_policy.json | 11 +++++ .../spec/generated/enrich.put_policy.json | 10 +++++ .../spec/generated/enrich.stats.json | 10 +++++ .../console_extensions/spec/ingest/index.js | 42 +++++++++++++++++++ .../spec/overrides/enrich.put_policy.json | 26 ++++++++++++ 12 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 x-pack/legacy/plugins/console_extensions/spec/generated/enrich.delete_policy.json create mode 100644 x-pack/legacy/plugins/console_extensions/spec/generated/enrich.execute_policy.json create mode 100644 x-pack/legacy/plugins/console_extensions/spec/generated/enrich.get_policy.json create mode 100644 x-pack/legacy/plugins/console_extensions/spec/generated/enrich.put_policy.json create mode 100644 x-pack/legacy/plugins/console_extensions/spec/generated/enrich.stats.json create mode 100644 x-pack/legacy/plugins/console_extensions/spec/ingest/index.js create mode 100644 x-pack/legacy/plugins/console_extensions/spec/overrides/enrich.put_policy.json diff --git a/src/legacy/core_plugins/console/index.ts b/src/legacy/core_plugins/console/index.ts index 78df2adb050df..30a85f4e7d342 100644 --- a/src/legacy/core_plugins/console/index.ts +++ b/src/legacy/core_plugins/console/index.ts @@ -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 @@ -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.'); } diff --git a/src/legacy/core_plugins/console/server/api_server/api.js b/src/legacy/core_plugins/console/server/api_server/api.js index 4b955d015649d..7a24cf8ea8219 100644 --- a/src/legacy/core_plugins/console/server/api_server/api.js +++ b/src/legacy/core_plugins/console/server/api_server/api.js @@ -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] }; @@ -54,6 +56,7 @@ class Api { patterns: [endpoint], methods: ['GET'] }); + this.endpoints[endpoint] = copiedDescription; } diff --git a/src/legacy/core_plugins/console/server/api_server/es_6_0.js b/src/legacy/core_plugins/console/server/api_server/es_6_0.js index 62bf0a9a38361..171d232407956 100644 --- a/src/legacy/core_plugins/console/server/api_server/es_6_0.js +++ b/src/legacy/core_plugins/console/server/api_server/es_6_0.js @@ -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(); @@ -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); diff --git a/src/legacy/core_plugins/console/server/api_server/es_6_0/ingest.js b/src/legacy/core_plugins/console/server/api_server/es_6_0/ingest.js index 04f2f12e003ed..0c072d6bbfeb0 100644 --- a/src/legacy/core_plugins/console/server/api_server/es_6_0/ingest.js +++ b/src/legacy/core_plugins/console/server/api_server/es_6_0/ingest.js @@ -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', { @@ -445,8 +444,6 @@ export default function (api) { data_autocomplete_rules: pipelineDefinition }); - - api.addEndpointDescription('ingest.simulate', { data_autocomplete_rules: { pipeline: pipelineDefinition, @@ -454,4 +451,8 @@ export default function (api) { ] } }); -} +}; + +export const addProcessorDefinition = processor => { + processorDefinition.__one_of.push(processor); +}; diff --git a/x-pack/legacy/plugins/console_extensions/index.js b/x-pack/legacy/plugins/console_extensions/index.js index 1a4c185733a2f..571d68e23dea5 100644 --- a/x-pack/legacy/plugins/console_extensions/index.js +++ b/x-pack/legacy/plugins/console_extensions/index.js @@ -5,6 +5,8 @@ */ import { join } from 'path'; +import { processors } from './spec/ingest'; + export function consoleExtensions(kibana) { return new kibana.Plugin({ id: 'console_extensions', @@ -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.', diff --git a/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.delete_policy.json b/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.delete_policy.json new file mode 100644 index 0000000000000..3d3c40fa093a4 --- /dev/null +++ b/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.delete_policy.json @@ -0,0 +1,10 @@ +{ + "enrich.delete_policy": { + "methods": [ + "DELETE" + ], + "patterns": [ + "_enrich/policy/{name}" + ] + } +} diff --git a/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.execute_policy.json b/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.execute_policy.json new file mode 100644 index 0000000000000..542b709c08ec6 --- /dev/null +++ b/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.execute_policy.json @@ -0,0 +1,13 @@ +{ + "enrich.execute_policy": { + "url_params": { + "wait_for_completion": "__flag__" + }, + "methods": [ + "PUT" + ], + "patterns": [ + "_enrich/policy/{name}/_execute" + ] + } +} diff --git a/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.get_policy.json b/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.get_policy.json new file mode 100644 index 0000000000000..b59bf72670b6d --- /dev/null +++ b/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.get_policy.json @@ -0,0 +1,11 @@ +{ + "enrich.get_policy": { + "methods": [ + "GET" + ], + "patterns": [ + "_enrich/policy/{name}", + "_enrich/policy" + ] + } +} diff --git a/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.put_policy.json b/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.put_policy.json new file mode 100644 index 0000000000000..96d854f04dcfc --- /dev/null +++ b/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.put_policy.json @@ -0,0 +1,10 @@ +{ + "enrich.put_policy": { + "methods": [ + "PUT" + ], + "patterns": [ + "_enrich/policy/{name}" + ] + } +} diff --git a/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.stats.json b/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.stats.json new file mode 100644 index 0000000000000..e6d1b04d63e45 --- /dev/null +++ b/x-pack/legacy/plugins/console_extensions/spec/generated/enrich.stats.json @@ -0,0 +1,10 @@ +{ + "enrich.stats": { + "methods": [ + "GET" + ], + "patterns": [ + "_enrich/_stats" + ] + } +} diff --git a/x-pack/legacy/plugins/console_extensions/spec/ingest/index.js b/x-pack/legacy/plugins/console_extensions/spec/ingest/index.js new file mode 100644 index 0000000000000..c4dad8d6af224 --- /dev/null +++ b/x-pack/legacy/plugins/console_extensions/spec/ingest/index.js @@ -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, +]; diff --git a/x-pack/legacy/plugins/console_extensions/spec/overrides/enrich.put_policy.json b/x-pack/legacy/plugins/console_extensions/spec/overrides/enrich.put_policy.json new file mode 100644 index 0000000000000..36bdeba521f7f --- /dev/null +++ b/x-pack/legacy/plugins/console_extensions/spec/overrides/enrich.put_policy.json @@ -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": [] + } + } + } +}