diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index 2a28e349ace99..ae8d61769b14c 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -16,7 +16,7 @@ "xpack.features": "plugins/features", "xpack.fileUpload": "plugins/file_upload", "xpack.graph": ["legacy/plugins/graph", "plugins/graph"], - "xpack.grokDebugger": "legacy/plugins/grokdebugger", + "xpack.grokDebugger": "plugins/grokdebugger", "xpack.idxMgmt": "plugins/index_management", "xpack.indexLifecycleMgmt": "legacy/plugins/index_lifecycle_management", "xpack.infra": "plugins/infra", diff --git a/x-pack/index.js b/x-pack/index.js index fb14b3dc10a4d..6fab13d726fa6 100644 --- a/x-pack/index.js +++ b/x-pack/index.js @@ -10,7 +10,6 @@ import { monitoring } from './legacy/plugins/monitoring'; import { reporting } from './legacy/plugins/reporting'; import { security } from './legacy/plugins/security'; import { tilemap } from './legacy/plugins/tilemap'; -import { grokdebugger } from './legacy/plugins/grokdebugger'; import { dashboardMode } from './legacy/plugins/dashboard_mode'; import { logstash } from './legacy/plugins/logstash'; import { beats } from './legacy/plugins/beats_management'; @@ -44,7 +43,6 @@ module.exports = function(kibana) { spaces(kibana), security(kibana), tilemap(kibana), - grokdebugger(kibana), dashboardMode(kibana), logstash(kibana), beats(kibana), diff --git a/x-pack/legacy/plugins/grokdebugger/index.js b/x-pack/legacy/plugins/grokdebugger/index.js deleted file mode 100644 index 7803aed739b99..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/index.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -import { resolve } from 'path'; -import { PLUGIN } from './common/constants'; -import { registerGrokdebuggerRoutes } from './server/routes/api/grokdebugger'; -import { registerLicenseChecker } from './server/lib/register_license_checker'; - -export const grokdebugger = kibana => - new kibana.Plugin({ - id: PLUGIN.ID, - publicDir: resolve(__dirname, 'public'), - require: ['kibana', 'elasticsearch', 'xpack_main'], - configPrefix: 'xpack.grokdebugger', - config(Joi) { - return Joi.object({ - enabled: Joi.boolean().default(true), - }).default(); - }, - uiExports: { - devTools: ['plugins/grokdebugger/register'], - home: ['plugins/grokdebugger/register_feature'], - }, - init: server => { - registerLicenseChecker(server); - registerGrokdebuggerRoutes(server); - }, - }); diff --git a/x-pack/legacy/plugins/grokdebugger/public/register.js b/x-pack/legacy/plugins/grokdebugger/public/register.js deleted file mode 100644 index 74679d65e52d2..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/public/register.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -import { i18n } from '@kbn/i18n'; -import { xpackInfo } from 'plugins/xpack_main/services/xpack_info'; -import { npSetup, npStart } from 'ui/new_platform'; - -npSetup.plugins.devTools.register({ - order: 6, - title: i18n.translate('xpack.grokDebugger.displayName', { - defaultMessage: 'Grok Debugger', - }), - id: 'grokdebugger', - enableRouting: false, - disabled: !xpackInfo.get('features.grokdebugger.enableLink', false), - tooltipContent: xpackInfo.get('features.grokdebugger.message'), - async mount(context, { element }) { - const licenseCheck = { - showPage: xpackInfo.get('features.grokdebugger.enableLink'), - message: xpackInfo.get('features.grokdebugger.message'), - }; - if (!licenseCheck.showPage) { - npStart.core.notifications.toasts.addDanger(licenseCheck.message); - window.location.hash = '/dev_tools'; - return () => {}; - } - const { renderApp } = await import('./render_app'); - return renderApp(element, npStart); - }, -}); diff --git a/x-pack/legacy/plugins/grokdebugger/public/register_feature.ts b/x-pack/legacy/plugins/grokdebugger/public/register_feature.ts deleted file mode 100644 index 97d2e53ce7836..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/public/register_feature.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - */ - -import { i18n } from '@kbn/i18n'; -import { npSetup } from 'ui/new_platform'; -import { FeatureCatalogueCategory } from '../../../../../src/plugins/home/public'; - -const { - plugins: { home }, -} = npSetup; - -home.featureCatalogue.register({ - id: 'grokdebugger', - title: i18n.translate('xpack.grokDebugger.registryProviderTitle', { - defaultMessage: '{grokLogParsingTool} Debugger', - values: { - grokLogParsingTool: 'Grok', - }, - }), - description: i18n.translate('xpack.grokDebugger.registryProviderDescription', { - defaultMessage: - 'Simulate and debug {grokLogParsingTool} patterns for data transformation on ingestion.', - values: { - grokLogParsingTool: 'grok', - }, - }), - icon: 'grokApp', - path: '/app/kibana#/dev_tools/grokdebugger', - showOnHomePage: false, - category: FeatureCatalogueCategory.ADMIN, -}); diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/call_with_request_factory/call_with_request_factory.js b/x-pack/legacy/plugins/grokdebugger/server/lib/call_with_request_factory/call_with_request_factory.js deleted file mode 100644 index 7359a831994f9..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/call_with_request_factory/call_with_request_factory.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -import { once } from 'lodash'; - -const callWithRequest = once(server => { - const cluster = server.plugins.elasticsearch.getCluster('data'); - return cluster.callWithRequest; -}); - -export const callWithRequestFactory = (server, request) => { - return (...args) => { - return callWithRequest(server)(request, ...args); - }; -}; diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/call_with_request_factory/index.js b/x-pack/legacy/plugins/grokdebugger/server/lib/call_with_request_factory/index.js deleted file mode 100644 index 787814d87dff9..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/call_with_request_factory/index.js +++ /dev/null @@ -1,7 +0,0 @@ -/* - * 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. - */ - -export { callWithRequestFactory } from './call_with_request_factory'; diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/check_license/__tests__/check_license.js b/x-pack/legacy/plugins/grokdebugger/server/lib/check_license/__tests__/check_license.js deleted file mode 100644 index 7e32d68a67ece..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/check_license/__tests__/check_license.js +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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. - */ - -import expect from '@kbn/expect'; -import { set } from 'lodash'; -import { checkLicense } from '../check_license'; - -describe('check_license', function() { - let mockLicenseInfo; - beforeEach(() => (mockLicenseInfo = {})); - - describe('license information is undefined', () => { - beforeEach(() => (mockLicenseInfo = undefined)); - - it('should set enableLink to false', () => { - expect(checkLicense(mockLicenseInfo).enableLink).to.be(false); - }); - - it('should set enableAPIRoute to false', () => { - expect(checkLicense(mockLicenseInfo).enableAPIRoute).to.be(false); - }); - - it('should set a message', () => { - expect(checkLicense(mockLicenseInfo).message).to.not.be(undefined); - }); - }); - - describe('license information is not available', () => { - beforeEach(() => (mockLicenseInfo.isAvailable = () => false)); - - it('should set enableLink to false', () => { - expect(checkLicense(mockLicenseInfo).enableLink).to.be(false); - }); - - it('should set enableAPIRoute to false', () => { - expect(checkLicense(mockLicenseInfo).enableAPIRoute).to.be(false); - }); - - it('should set a message', () => { - expect(checkLicense(mockLicenseInfo).message).to.not.be(undefined); - }); - }); - - describe('license information is available', () => { - beforeEach( - () => - (mockLicenseInfo = { - isAvailable: () => true, - license: { - getType: () => 'foobar', - }, - }) - ); - - describe('& license is active', () => { - beforeEach(() => set(mockLicenseInfo, 'license.isActive', () => true)); - - it('should set enableLink to true', () => { - expect(checkLicense(mockLicenseInfo).enableLink).to.be(true); - }); - - it('should set enableAPIRoute to true', () => { - expect(checkLicense(mockLicenseInfo).enableAPIRoute).to.be(true); - }); - - it('should NOT set a message', () => { - expect(checkLicense(mockLicenseInfo).message).to.be(undefined); - }); - }); - - describe('& license is expired', () => { - beforeEach(() => set(mockLicenseInfo, 'license.isActive', () => false)); - - it('should set enableLink to false', () => { - expect(checkLicense(mockLicenseInfo).enableLink).to.be(false); - }); - - it('should set enableAPIRoute to false', () => { - expect(checkLicense(mockLicenseInfo).enableAPIRoute).to.be(false); - }); - - it('should set a message', () => { - expect(checkLicense(mockLicenseInfo).message).to.not.be(undefined); - }); - }); - }); -}); diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/check_license/check_license.js b/x-pack/legacy/plugins/grokdebugger/server/lib/check_license/check_license.js deleted file mode 100644 index c7a8d2bbca059..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/check_license/check_license.js +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - */ - -import { i18n } from '@kbn/i18n'; - -export function checkLicense(xpackLicenseInfo) { - // If, for some reason, we cannot get the license information - // from Elasticsearch, assume worst case and disable the Watcher UI - if (!xpackLicenseInfo || !xpackLicenseInfo.isAvailable()) { - return { - enableLink: false, - enableAPIRoute: false, - message: i18n.translate('xpack.grokDebugger.unavailableLicenseInformationMessage', { - defaultMessage: - 'You cannot use the {grokLogParsingTool} Debugger because license information is not available at this time.', - values: { - grokLogParsingTool: 'Grok', - }, - }), - }; - } - - const isLicenseActive = xpackLicenseInfo.license.isActive(); - const licenseType = xpackLicenseInfo.license.getType(); - - // License is not valid - if (!isLicenseActive) { - return { - enableLink: false, - enableAPIRoute: false, - message: i18n.translate('xpack.grokDebugger.licenseHasExpiredMessage', { - defaultMessage: - 'You cannot use the {grokLogParsingTool} Debugger because your {licenseType} license has expired.', - values: { - licenseType, - grokLogParsingTool: 'Grok', - }, - }), - }; - } - - // License is valid and active - return { - enableLink: true, - enableAPIRoute: true, - }; -} diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/check_license/index.js b/x-pack/legacy/plugins/grokdebugger/server/lib/check_license/index.js deleted file mode 100644 index f2c070fd44b6e..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/check_license/index.js +++ /dev/null @@ -1,7 +0,0 @@ -/* - * 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. - */ - -export { checkLicense } from './check_license'; diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/error_wrappers/wrap_es_error.js b/x-pack/legacy/plugins/grokdebugger/server/lib/error_wrappers/wrap_es_error.js deleted file mode 100644 index dfcd4e3b1e17c..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/error_wrappers/wrap_es_error.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -import Boom from 'boom'; - -/** - * Wraps ES errors into a Boom error response and returns it - * This also handles the permissions issue gracefully - * - * @param err Object ES error - * @return Object Boom error response - */ -export function wrapEsError(err) { - return Boom.boomify(err, { statusCode: err.statusCode }); -} diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/__tests__/license_pre_routing_factory.js b/x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/__tests__/license_pre_routing_factory.js deleted file mode 100644 index 135317f050774..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/__tests__/license_pre_routing_factory.js +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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. - */ - -import expect from '@kbn/expect'; -import Boom from 'boom'; -import { licensePreRoutingFactory } from '../license_pre_routing_factory'; - -describe('license_pre_routing_factory', () => { - describe('#grokDebuggerFeaturePreRoutingFactory', () => { - let mockServer; - let mockLicenseCheckResults; - - beforeEach(() => { - mockServer = { - plugins: { - xpack_main: { - info: { - feature: () => ({ - getLicenseCheckResults: () => mockLicenseCheckResults, - }), - }, - }, - }, - }; - }); - - describe('isAvailable is false', () => { - beforeEach(() => { - mockLicenseCheckResults = { - isAvailable: false, - }; - }); - - it('replies with 403', async () => { - const licensePreRouting = licensePreRoutingFactory(mockServer); - const stubRequest = {}; - expect(() => licensePreRouting(stubRequest)).to.throwException(response => { - expect(response).to.be.an(Error); - expect(response.isBoom).to.be(true); - expect(response.output.statusCode).to.be(403); - }); - }); - }); - - describe('isAvailable is true', () => { - beforeEach(() => { - mockLicenseCheckResults = { - isAvailable: true, - }; - }); - - it('replies with forbidden', async () => { - const licensePreRouting = licensePreRoutingFactory(mockServer); - const stubRequest = {}; - expect(() => licensePreRouting(stubRequest)).to.throwException(response => { - expect(response).to.eql(Boom.forbidden()); - }); - }); - }); - }); -}); diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/license_pre_routing_factory.js b/x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/license_pre_routing_factory.js deleted file mode 100644 index 88c844de3e2ca..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/license_pre_routing_factory.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - -import Boom from 'boom'; -import { PLUGIN } from '../../../common/constants'; - -export const licensePreRoutingFactory = server => { - const xpackMainPlugin = server.plugins.xpack_main; - - // License checking and enable/disable logic - function licensePreRouting() { - const licenseCheckResults = xpackMainPlugin.info.feature(PLUGIN.ID).getLicenseCheckResults(); - if (!licenseCheckResults.enableAPIRoute) { - throw Boom.forbidden(licenseCheckResults.message); - } - - return null; - } - - return licensePreRouting; -}; diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/register_license_checker/index.js b/x-pack/legacy/plugins/grokdebugger/server/lib/register_license_checker/index.js deleted file mode 100644 index 7b0f97c38d129..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/register_license_checker/index.js +++ /dev/null @@ -1,7 +0,0 @@ -/* - * 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. - */ - -export { registerLicenseChecker } from './register_license_checker'; diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/register_license_checker/register_license_checker.js b/x-pack/legacy/plugins/grokdebugger/server/lib/register_license_checker/register_license_checker.js deleted file mode 100644 index ee9a9a3ebdece..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/register_license_checker/register_license_checker.js +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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. - */ - -import { mirrorPluginStatus } from '../../../../../server/lib/mirror_plugin_status'; -import { checkLicense } from '../check_license'; -import { PLUGIN } from '../../../common/constants'; - -export function registerLicenseChecker(server) { - const xpackMainPlugin = server.plugins.xpack_main; - const grokdebuggerPlugin = server.plugins[PLUGIN.ID]; - - mirrorPluginStatus(xpackMainPlugin, grokdebuggerPlugin); - xpackMainPlugin.status.once('green', () => { - // Register a function that is called whenever the xpack info changes, - // to re-compute the license check results for this plugin - xpackMainPlugin.info.feature(PLUGIN.ID).registerLicenseCheckResultsGenerator(checkLicense); - }); -} diff --git a/x-pack/legacy/plugins/grokdebugger/server/routes/api/grokdebugger/register_grok_simulate_route.js b/x-pack/legacy/plugins/grokdebugger/server/routes/api/grokdebugger/register_grok_simulate_route.js deleted file mode 100644 index 14ea1e7acb668..0000000000000 --- a/x-pack/legacy/plugins/grokdebugger/server/routes/api/grokdebugger/register_grok_simulate_route.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ - -import { wrapEsError } from '../../../lib/error_wrappers'; -import { callWithRequestFactory } from '../../../lib/call_with_request_factory'; -import { GrokdebuggerRequest } from '../../../models/grokdebugger_request'; -import { GrokdebuggerResponse } from '../../../models/grokdebugger_response'; -import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; - -function simulateGrok(callWithRequest, ingestJson) { - return callWithRequest('ingest.simulate', { - body: ingestJson, - }); -} - -export function registerGrokSimulateRoute(server) { - const licensePreRouting = licensePreRoutingFactory(server); - - server.route({ - path: '/api/grokdebugger/simulate', - method: 'POST', - handler: request => { - const callWithRequest = callWithRequestFactory(server, request); - const grokdebuggerRequest = GrokdebuggerRequest.fromDownstreamJSON(request.payload); - return simulateGrok(callWithRequest, grokdebuggerRequest.upstreamJSON) - .then(simulateResponseFromES => { - const grokdebuggerResponse = GrokdebuggerResponse.fromUpstreamJSON( - simulateResponseFromES - ); - return { grokdebuggerResponse }; - }) - .catch(e => wrapEsError(e)); - }, - config: { - pre: [licensePreRouting], - }, - }); -} diff --git a/x-pack/legacy/plugins/grokdebugger/README.md b/x-pack/plugins/grokdebugger/README.md similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/README.md rename to x-pack/plugins/grokdebugger/README.md diff --git a/x-pack/legacy/plugins/grokdebugger/common/constants/editor.js b/x-pack/plugins/grokdebugger/common/constants/editor.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/common/constants/editor.js rename to x-pack/plugins/grokdebugger/common/constants/editor.js diff --git a/x-pack/legacy/plugins/grokdebugger/common/constants/index.js b/x-pack/plugins/grokdebugger/common/constants/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/common/constants/index.js rename to x-pack/plugins/grokdebugger/common/constants/index.js diff --git a/x-pack/legacy/plugins/grokdebugger/common/constants/plugin.js b/x-pack/plugins/grokdebugger/common/constants/plugin.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/common/constants/plugin.js rename to x-pack/plugins/grokdebugger/common/constants/plugin.js diff --git a/x-pack/legacy/plugins/grokdebugger/common/constants/routes.js b/x-pack/plugins/grokdebugger/common/constants/routes.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/common/constants/routes.js rename to x-pack/plugins/grokdebugger/common/constants/routes.js diff --git a/x-pack/plugins/grokdebugger/kibana.json b/x-pack/plugins/grokdebugger/kibana.json new file mode 100644 index 0000000000000..4d37f9ccdb0de --- /dev/null +++ b/x-pack/plugins/grokdebugger/kibana.json @@ -0,0 +1,13 @@ +{ + "id": "grokdebugger", + "version": "8.0.0", + "kibanaVersion": "kibana", + "requiredPlugins": [ + "licensing", + "home", + "devTools" + ], + "server": true, + "ui": true, + "configPath": ["xpack", "grokdebugger"] +} diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/custom_patterns_input/custom_patterns_input.js b/x-pack/plugins/grokdebugger/public/components/custom_patterns_input/custom_patterns_input.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/components/custom_patterns_input/custom_patterns_input.js rename to x-pack/plugins/grokdebugger/public/components/custom_patterns_input/custom_patterns_input.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/custom_patterns_input/index.js b/x-pack/plugins/grokdebugger/public/components/custom_patterns_input/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/components/custom_patterns_input/index.js rename to x-pack/plugins/grokdebugger/public/components/custom_patterns_input/index.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/event_input/event_input.js b/x-pack/plugins/grokdebugger/public/components/event_input/event_input.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/components/event_input/event_input.js rename to x-pack/plugins/grokdebugger/public/components/event_input/event_input.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/event_input/index.js b/x-pack/plugins/grokdebugger/public/components/event_input/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/components/event_input/index.js rename to x-pack/plugins/grokdebugger/public/components/event_input/index.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/event_output/event_output.js b/x-pack/plugins/grokdebugger/public/components/event_output/event_output.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/components/event_output/event_output.js rename to x-pack/plugins/grokdebugger/public/components/event_output/event_output.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/event_output/index.js b/x-pack/plugins/grokdebugger/public/components/event_output/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/components/event_output/index.js rename to x-pack/plugins/grokdebugger/public/components/event_output/index.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/grok_debugger/brace_imports.ts b/x-pack/plugins/grokdebugger/public/components/grok_debugger/brace_imports.ts similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/components/grok_debugger/brace_imports.ts rename to x-pack/plugins/grokdebugger/public/components/grok_debugger/brace_imports.ts diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/grok_debugger/grok_debugger.js b/x-pack/plugins/grokdebugger/public/components/grok_debugger/grok_debugger.js similarity index 90% rename from x-pack/legacy/plugins/grokdebugger/public/components/grok_debugger/grok_debugger.js rename to x-pack/plugins/grokdebugger/public/components/grok_debugger/grok_debugger.js index dfdd524b3d3d4..c27f3314e60ae 100644 --- a/x-pack/legacy/plugins/grokdebugger/public/components/grok_debugger/grok_debugger.js +++ b/x-pack/plugins/grokdebugger/public/components/grok_debugger/grok_debugger.js @@ -22,10 +22,10 @@ import { PatternInput } from '../pattern_input'; import { CustomPatternsInput } from '../custom_patterns_input'; import { EventOutput } from '../event_output'; import { GrokdebuggerRequest } from '../../models/grokdebugger_request'; -import { toastNotifications } from 'ui/notify'; +import { withKibana } from '../../../../../../src/plugins/kibana_react/public'; import { FormattedMessage } from '@kbn/i18n/react'; -export class GrokDebugger extends React.Component { +export class GrokDebuggerComponent extends React.Component { constructor(props) { super(props); this.state = { @@ -73,6 +73,7 @@ export class GrokDebugger extends React.Component { }; simulateGrok = async () => { + const notifications = this.props.kibana.services.notifications; try { const simulateResponse = await this.props.grokdebuggerService.simulate( this.grokdebuggerRequest @@ -82,10 +83,14 @@ export class GrokDebugger extends React.Component { }); if (!isEmpty(simulateResponse.error)) { - toastNotifications.addDanger(simulateResponse.error); + notifications.toasts.addDanger({ + body: simulateResponse.error, + }); } } catch (e) { - toastNotifications.addDanger(e); + notifications.toasts.addDanger({ + body: e, + }); } }; @@ -138,3 +143,5 @@ export class GrokDebugger extends React.Component { ); } } + +export const GrokDebugger = withKibana(GrokDebuggerComponent); diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/grok_debugger/index.js b/x-pack/plugins/grokdebugger/public/components/grok_debugger/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/components/grok_debugger/index.js rename to x-pack/plugins/grokdebugger/public/components/grok_debugger/index.js diff --git a/x-pack/plugins/grokdebugger/public/components/inactive_license.js b/x-pack/plugins/grokdebugger/public/components/inactive_license.js new file mode 100644 index 0000000000000..ff0306b789190 --- /dev/null +++ b/x-pack/plugins/grokdebugger/public/components/inactive_license.js @@ -0,0 +1,91 @@ +/* + * 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. + */ + +import React from 'react'; +import { + EuiCallOut, + EuiText, + EuiLink, + EuiCode, + EuiPage, + EuiPageBody, + EuiPageContent, + EuiPageContentBody, +} from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; + +export const InactiveLicenseSlate = () => { + const registerLicenseLinkLabel = i18n.translate('xpack.grokDebugger.registerLicenseLinkLabel', { + defaultMessage: 'register a license', + }); + + const trialLicense = i18n.translate('xpack.grokDebugger.trialLicenseTitle', { + defaultMessage: 'Trial', + }); + + const basicLicense = i18n.translate('xpack.grokDebugger.basicLicenseTitle', { + defaultMessage: 'Basic', + }); + + const goldLicense = i18n.translate('xpack.grokDebugger.goldLicenseTitle', { + defaultMessage: 'Gold', + }); + + const platinumLicense = i18n.translate('xpack.grokDebugger.platinumLicenseTitle', { + defaultMessage: 'Platinum', + }); + + return ( + + + + + + +

+ + {trialLicense}, {basicLicense},{' '} + {goldLicense} + + ), + platinumLicenseType: {platinumLicense}, + }} + /> +

+

+ + {registerLicenseLinkLabel} + + ), + }} + /> +

+
+
+
+
+
+
+ ); +}; diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/pattern_input/index.js b/x-pack/plugins/grokdebugger/public/components/pattern_input/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/components/pattern_input/index.js rename to x-pack/plugins/grokdebugger/public/components/pattern_input/index.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/components/pattern_input/pattern_input.js b/x-pack/plugins/grokdebugger/public/components/pattern_input/pattern_input.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/components/pattern_input/pattern_input.js rename to x-pack/plugins/grokdebugger/public/components/pattern_input/pattern_input.js diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/error_wrappers/index.js b/x-pack/plugins/grokdebugger/public/index.js similarity index 66% rename from x-pack/legacy/plugins/grokdebugger/server/lib/error_wrappers/index.js rename to x-pack/plugins/grokdebugger/public/index.js index 3756b0c74fb10..960c9d8d58e4a 100644 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/error_wrappers/index.js +++ b/x-pack/plugins/grokdebugger/public/index.js @@ -4,4 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -export { wrapEsError } from './wrap_es_error'; +import { Plugin } from './plugin'; + +export function plugin(initializerContext) { + return new Plugin(initializerContext); +} diff --git a/x-pack/legacy/plugins/grokdebugger/public/lib/ace/grok_highlight_rules.js b/x-pack/plugins/grokdebugger/public/lib/ace/grok_highlight_rules.js similarity index 97% rename from x-pack/legacy/plugins/grokdebugger/public/lib/ace/grok_highlight_rules.js rename to x-pack/plugins/grokdebugger/public/lib/ace/grok_highlight_rules.js index 3da1afdc0fc00..1851d53ff0ee8 100644 --- a/x-pack/legacy/plugins/grokdebugger/public/lib/ace/grok_highlight_rules.js +++ b/x-pack/plugins/grokdebugger/public/lib/ace/grok_highlight_rules.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import ace from 'ace'; +import ace from 'brace'; const { TextHighlightRules } = ace.acequire('ace/mode/text_highlight_rules'); diff --git a/x-pack/legacy/plugins/grokdebugger/public/lib/ace/grok_mode.js b/x-pack/plugins/grokdebugger/public/lib/ace/grok_mode.js similarity index 95% rename from x-pack/legacy/plugins/grokdebugger/public/lib/ace/grok_mode.js rename to x-pack/plugins/grokdebugger/public/lib/ace/grok_mode.js index 84b2e482673c6..cd82a5b9917e6 100644 --- a/x-pack/legacy/plugins/grokdebugger/public/lib/ace/grok_mode.js +++ b/x-pack/plugins/grokdebugger/public/lib/ace/grok_mode.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import ace from 'ace'; +import ace from 'brace'; import { GrokHighlightRules } from './grok_highlight_rules'; const TextMode = ace.acequire('ace/mode/text').Mode; diff --git a/x-pack/legacy/plugins/grokdebugger/public/lib/ace/index.js b/x-pack/plugins/grokdebugger/public/lib/ace/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/lib/ace/index.js rename to x-pack/plugins/grokdebugger/public/lib/ace/index.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/models/grokdebugger_request/grokdebugger_request.js b/x-pack/plugins/grokdebugger/public/models/grokdebugger_request/grokdebugger_request.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/models/grokdebugger_request/grokdebugger_request.js rename to x-pack/plugins/grokdebugger/public/models/grokdebugger_request/grokdebugger_request.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/models/grokdebugger_request/index.js b/x-pack/plugins/grokdebugger/public/models/grokdebugger_request/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/models/grokdebugger_request/index.js rename to x-pack/plugins/grokdebugger/public/models/grokdebugger_request/index.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/models/grokdebugger_response/grokdebugger_response.js b/x-pack/plugins/grokdebugger/public/models/grokdebugger_response/grokdebugger_response.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/models/grokdebugger_response/grokdebugger_response.js rename to x-pack/plugins/grokdebugger/public/models/grokdebugger_response/grokdebugger_response.js diff --git a/x-pack/legacy/plugins/grokdebugger/public/models/grokdebugger_response/index.js b/x-pack/plugins/grokdebugger/public/models/grokdebugger_response/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/public/models/grokdebugger_response/index.js rename to x-pack/plugins/grokdebugger/public/models/grokdebugger_response/index.js diff --git a/x-pack/plugins/grokdebugger/public/plugin.js b/x-pack/plugins/grokdebugger/public/plugin.js new file mode 100644 index 0000000000000..9de4f9c3f8bc0 --- /dev/null +++ b/x-pack/plugins/grokdebugger/public/plugin.js @@ -0,0 +1,35 @@ +/* + * 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. + */ + +import { i18n } from '@kbn/i18n'; +import { first } from 'rxjs/operators'; +import { registerFeature } from './register_feature'; +import { PLUGIN } from '../common/constants'; + +export class Plugin { + setup(coreSetup, plugins) { + registerFeature(plugins.home); + + plugins.devTools.register({ + order: 6, + title: i18n.translate('xpack.grokDebugger.displayName', { + defaultMessage: 'Grok Debugger', + }), + id: PLUGIN.ID, + enableRouting: false, + async mount(context, { element }) { + const [coreStart] = await coreSetup.getStartServices(); + const license = await plugins.licensing.license$.pipe(first()).toPromise(); + const { renderApp } = await import('./render_app'); + return renderApp(license, element, coreStart); + }, + }); + } + + start() {} + + stop() {} +} diff --git a/x-pack/plugins/grokdebugger/public/register_feature.ts b/x-pack/plugins/grokdebugger/public/register_feature.ts new file mode 100644 index 0000000000000..f05d4c973a5fb --- /dev/null +++ b/x-pack/plugins/grokdebugger/public/register_feature.ts @@ -0,0 +1,27 @@ +/* + * 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. + */ + +import { i18n } from '@kbn/i18n'; +import { + FeatureCatalogueCategory, + HomePublicPluginSetup, +} from '../../../../src/plugins/home/public'; + +export const registerFeature = (homePlugin: HomePublicPluginSetup) => { + homePlugin.featureCatalogue.register({ + id: 'grokdebugger', + title: i18n.translate('xpack.grokDebugger.registryProviderTitle', { + defaultMessage: 'Grok Debugger', + }), + description: i18n.translate('xpack.grokDebugger.registryProviderDescription', { + defaultMessage: 'Simulate and debug grok patterns for data transformation on ingestion.', + }), + icon: 'grokApp', + path: '/app/kibana#/dev_tools/grokdebugger', + showOnHomePage: false, + category: FeatureCatalogueCategory.ADMIN, + }); +}; diff --git a/x-pack/legacy/plugins/grokdebugger/public/render_app.js b/x-pack/plugins/grokdebugger/public/render_app.js similarity index 51% rename from x-pack/legacy/plugins/grokdebugger/public/render_app.js rename to x-pack/plugins/grokdebugger/public/render_app.js index 2c4894bb70ee1..82783c7bd9795 100644 --- a/x-pack/legacy/plugins/grokdebugger/public/render_app.js +++ b/x-pack/plugins/grokdebugger/public/render_app.js @@ -10,13 +10,23 @@ import { render, unmountComponentAtNode } from 'react-dom'; import { GrokDebugger } from './components/grok_debugger'; import { GrokdebuggerService } from './services/grokdebugger/grokdebugger_service'; import { I18nProvider } from '@kbn/i18n/react'; +import { KibanaContextProvider } from '../../../../src/plugins/kibana_react/public'; +import { InactiveLicenseSlate } from './components/inactive_license'; -export function renderApp(element, npStart) { - render( +export function renderApp(license, element, coreStart) { + const content = license.isActive ? ( + + + + + + ) : ( - - , - element + + ); + + render(content, element); + return () => unmountComponentAtNode(element); } diff --git a/x-pack/legacy/plugins/grokdebugger/public/services/grokdebugger/grokdebugger_service.js b/x-pack/plugins/grokdebugger/public/services/grokdebugger/grokdebugger_service.js similarity index 78% rename from x-pack/legacy/plugins/grokdebugger/public/services/grokdebugger/grokdebugger_service.js rename to x-pack/plugins/grokdebugger/public/services/grokdebugger/grokdebugger_service.js index c6d28adcefd78..e26c9c5091e14 100644 --- a/x-pack/legacy/plugins/grokdebugger/public/services/grokdebugger/grokdebugger_service.js +++ b/x-pack/plugins/grokdebugger/public/services/grokdebugger/grokdebugger_service.js @@ -5,7 +5,7 @@ */ import { ROUTES } from '../../../common/constants'; -import { GrokdebuggerResponse } from 'plugins/grokdebugger/models/grokdebugger_response'; +import { GrokdebuggerResponse } from '../../models/grokdebugger_response'; export class GrokdebuggerService { constructor(http) { @@ -18,7 +18,7 @@ export class GrokdebuggerService { body: JSON.stringify(grokdebuggerRequest.upstreamJSON), }) .then(response => { - return GrokdebuggerResponse.fromUpstreamJSON(response.grokdebuggerResponse); + return GrokdebuggerResponse.fromUpstreamJSON(response); }) .catch(e => { throw e.body.message; diff --git a/x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/index.js b/x-pack/plugins/grokdebugger/server/index.js similarity index 66% rename from x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/index.js rename to x-pack/plugins/grokdebugger/server/index.js index 0743e443955f4..960c9d8d58e4a 100644 --- a/x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/index.js +++ b/x-pack/plugins/grokdebugger/server/index.js @@ -4,4 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -export { licensePreRoutingFactory } from './license_pre_routing_factory'; +import { Plugin } from './plugin'; + +export function plugin(initializerContext) { + return new Plugin(initializerContext); +} diff --git a/x-pack/plugins/grokdebugger/server/lib/kibana_framework.ts b/x-pack/plugins/grokdebugger/server/lib/kibana_framework.ts new file mode 100644 index 0000000000000..749f5e9ebf8f0 --- /dev/null +++ b/x-pack/plugins/grokdebugger/server/lib/kibana_framework.ts @@ -0,0 +1,105 @@ +/* + * 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. + */ + +/* eslint-disable @typescript-eslint/array-type */ + +import { i18n } from '@kbn/i18n'; + +import { + CoreSetup, + IRouter, + RequestHandlerContext, + RouteMethod, + RouteConfig, + RequestHandler, +} from 'src/core/server'; + +import { ILicense } from '../../../licensing/server'; + +type GrokDebuggerRouteConfig = { + method: RouteMethod; +} & RouteConfig; + +export class KibanaFramework { + public router: IRouter; + public license?: ILicense; + + constructor(core: CoreSetup) { + this.router = core.http.createRouter(); + } + + public setLicense(license: ILicense) { + this.license = license; + } + + private hasActiveLicense() { + if (!this.license) { + throw new Error( + "Please set license information in the plugin's setup method before trying to check the status" + ); + } + return this.license.isActive; + } + + public registerRoute( + config: GrokDebuggerRouteConfig, + handler: RequestHandler + ) { + // Automatically wrap all route registrations with license checking + const wrappedHandler: RequestHandler = async ( + requestContext, + request, + response + ) => { + if (this.hasActiveLicense()) { + return await handler(requestContext, request, response); + } else { + return response.forbidden({ + body: i18n.translate('xpack.grokDebugger.serverInactiveLicenseError', { + defaultMessage: 'The Grok Debugger tool requires an active license.', + }), + }); + } + }; + + const routeConfig = { + path: config.path, + validate: config.validate, + }; + + switch (config.method) { + case 'get': + this.router.get(routeConfig, wrappedHandler); + break; + case 'post': + this.router.post(routeConfig, wrappedHandler); + break; + case 'delete': + this.router.delete(routeConfig, wrappedHandler); + break; + case 'put': + this.router.put(routeConfig, wrappedHandler); + break; + } + } + + callWithRequest( + requestContext: RequestHandlerContext, + endpoint: 'ingest.simulate', + options?: { + body: any; + } + ): Promise; + + public async callWithRequest( + requestContext: RequestHandlerContext, + endpoint: string, + options?: any + ) { + const { elasticsearch } = requestContext.core; + return elasticsearch.dataClient.callAsCurrentUser(endpoint, options); + } +} diff --git a/x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_request/__tests__/grokdebugger_request.js b/x-pack/plugins/grokdebugger/server/models/grokdebugger_request/__tests__/grokdebugger_request.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_request/__tests__/grokdebugger_request.js rename to x-pack/plugins/grokdebugger/server/models/grokdebugger_request/__tests__/grokdebugger_request.js diff --git a/x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_request/grokdebugger_request.js b/x-pack/plugins/grokdebugger/server/models/grokdebugger_request/grokdebugger_request.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_request/grokdebugger_request.js rename to x-pack/plugins/grokdebugger/server/models/grokdebugger_request/grokdebugger_request.js diff --git a/x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_request/index.js b/x-pack/plugins/grokdebugger/server/models/grokdebugger_request/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_request/index.js rename to x-pack/plugins/grokdebugger/server/models/grokdebugger_request/index.js diff --git a/x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_response/__tests__/grokdebugger_response.js b/x-pack/plugins/grokdebugger/server/models/grokdebugger_response/__tests__/grokdebugger_response.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_response/__tests__/grokdebugger_response.js rename to x-pack/plugins/grokdebugger/server/models/grokdebugger_response/__tests__/grokdebugger_response.js diff --git a/x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_response/grokdebugger_response.js b/x-pack/plugins/grokdebugger/server/models/grokdebugger_response/grokdebugger_response.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_response/grokdebugger_response.js rename to x-pack/plugins/grokdebugger/server/models/grokdebugger_response/grokdebugger_response.js diff --git a/x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_response/index.js b/x-pack/plugins/grokdebugger/server/models/grokdebugger_response/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/server/models/grokdebugger_response/index.js rename to x-pack/plugins/grokdebugger/server/models/grokdebugger_response/index.js diff --git a/x-pack/plugins/grokdebugger/server/plugin.js b/x-pack/plugins/grokdebugger/server/plugin.js new file mode 100644 index 0000000000000..06ddd92aefac9 --- /dev/null +++ b/x-pack/plugins/grokdebugger/server/plugin.js @@ -0,0 +1,30 @@ +/* + * 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. + */ + +import { schema } from '@kbn/config-schema'; +import { KibanaFramework } from './lib/kibana_framework'; +import { registerGrokdebuggerRoutes } from './routes/api/grokdebugger'; + +export const config = { + schema: schema.object({ + enabled: schema.boolean({ defaultValue: true }), + }), +}; + +export class Plugin { + setup(coreSetup, plugins) { + const framework = new KibanaFramework(coreSetup); + + plugins.licensing.license$.subscribe(license => { + framework.setLicense(license); + }); + + registerGrokdebuggerRoutes(framework); + } + + start() {} + stop() {} +} diff --git a/x-pack/legacy/plugins/grokdebugger/server/routes/api/grokdebugger/index.js b/x-pack/plugins/grokdebugger/server/routes/api/grokdebugger/index.js similarity index 100% rename from x-pack/legacy/plugins/grokdebugger/server/routes/api/grokdebugger/index.js rename to x-pack/plugins/grokdebugger/server/routes/api/grokdebugger/index.js diff --git a/x-pack/plugins/grokdebugger/server/routes/api/grokdebugger/register_grok_simulate_route.js b/x-pack/plugins/grokdebugger/server/routes/api/grokdebugger/register_grok_simulate_route.js new file mode 100644 index 0000000000000..f953bc64c3b4f --- /dev/null +++ b/x-pack/plugins/grokdebugger/server/routes/api/grokdebugger/register_grok_simulate_route.js @@ -0,0 +1,46 @@ +/* + * 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. + */ + +import { schema } from '@kbn/config-schema'; +import { GrokdebuggerRequest } from '../../../models/grokdebugger_request'; +import { GrokdebuggerResponse } from '../../../models/grokdebugger_response'; + +const requestBodySchema = schema.object({ + pattern: schema.string(), + rawEvent: schema.string(), + // We don't know these key / values up front as they depend on user input + customPatterns: schema.object({}, { unknowns: 'allow' }), +}); + +export function registerGrokSimulateRoute(framework) { + framework.registerRoute( + { + method: 'post', + path: '/api/grokdebugger/simulate', + validate: { + body: requestBodySchema, + }, + }, + async (requestContext, request, response) => { + try { + const grokdebuggerRequest = GrokdebuggerRequest.fromDownstreamJSON(request.body); + const simulateResponseFromES = await framework.callWithRequest( + requestContext, + 'ingest.simulate', + { body: grokdebuggerRequest.upstreamJSON } + ); + const grokdebuggerResponse = GrokdebuggerResponse.fromUpstreamJSON(simulateResponseFromES); + return response.ok({ + body: grokdebuggerResponse, + }); + } catch (error) { + return response.internalError({ + body: error.message, + }); + } + } + ); +} diff --git a/x-pack/legacy/plugins/grokdebugger/server/routes/api/grokdebugger/register_grokdebugger_routes.js b/x-pack/plugins/grokdebugger/server/routes/api/grokdebugger/register_grokdebugger_routes.js similarity index 77% rename from x-pack/legacy/plugins/grokdebugger/server/routes/api/grokdebugger/register_grokdebugger_routes.js rename to x-pack/plugins/grokdebugger/server/routes/api/grokdebugger/register_grokdebugger_routes.js index 6d27ce2ca0545..d7ecd1c360d81 100644 --- a/x-pack/legacy/plugins/grokdebugger/server/routes/api/grokdebugger/register_grokdebugger_routes.js +++ b/x-pack/plugins/grokdebugger/server/routes/api/grokdebugger/register_grokdebugger_routes.js @@ -6,6 +6,6 @@ import { registerGrokSimulateRoute } from './register_grok_simulate_route'; -export function registerGrokdebuggerRoutes(server) { - registerGrokSimulateRoute(server); +export function registerGrokdebuggerRoutes(framework) { + registerGrokSimulateRoute(framework); } diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 1f7a1294fe786..a9f3c9acf216d 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -5783,14 +5783,10 @@ "xpack.grokDebugger.customPatternsButtonLabel": "カスタムパターン", "xpack.grokDebugger.displayName": "Grok デバッガー", "xpack.grokDebugger.grokPatternLabel": "Grok パターン", - "xpack.grokDebugger.licenseHasExpiredMessage": "{licenseType} ライセンスが期限切れのため {grokLogParsingTool} デバッガーを使用できません", "xpack.grokDebugger.patternsErrorMessage": "提供された {grokLogParsingTool} パターンがインプットのデータと一致していません", - "xpack.grokDebugger.registryProviderDescription": "{grokLogParsingTool} パターンを、投入時にデータ変換用にシミュレートしデバッグします。", - "xpack.grokDebugger.registryProviderTitle": "{grokLogParsingTool} デバッガー", "xpack.grokDebugger.sampleDataLabel": "サンプルデータ", "xpack.grokDebugger.simulateButtonLabel": "シミュレート", "xpack.grokDebugger.structuredDataLabel": "構造化データ", - "xpack.grokDebugger.unavailableLicenseInformationMessage": "現在ライセンス情報が利用できないため {grokLogParsingTool} デバッガーを使用できません。", "xpack.idxMgmt.appTitle": "インデックス管理", "xpack.idxMgmt.badgeAriaLabel": "{label}。これをフィルタリングするよう選択。", "xpack.idxMgmt.breadcrumb.cloneTemplateLabel": "テンプレートのクローンを作成", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index f93216662ca7c..96db297bd519e 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -5783,14 +5783,10 @@ "xpack.grokDebugger.customPatternsButtonLabel": "自定义模式", "xpack.grokDebugger.displayName": "Grok Debugger", "xpack.grokDebugger.grokPatternLabel": "Grok 模式", - "xpack.grokDebugger.licenseHasExpiredMessage": "您不能使用 {grokLogParsingTool} Debugger,因为您的 {licenseType} 许可证已过期。", "xpack.grokDebugger.patternsErrorMessage": "提供的 {grokLogParsingTool} 模式不匹配输入中的数据", - "xpack.grokDebugger.registryProviderDescription": "采集时模拟和调试用于数据转换的 {grokLogParsingTool} 模式。", - "xpack.grokDebugger.registryProviderTitle": "{grokLogParsingTool} Debugger", "xpack.grokDebugger.sampleDataLabel": "样例数据", "xpack.grokDebugger.simulateButtonLabel": "模拟", "xpack.grokDebugger.structuredDataLabel": "结构化数据", - "xpack.grokDebugger.unavailableLicenseInformationMessage": "您不能使用 {grokLogParsingTool} Debugger,因为许可证信息当前不可用。", "xpack.idxMgmt.appTitle": "索引管理", "xpack.idxMgmt.badgeAriaLabel": "{label}。选择以基于此选项进行筛选。", "xpack.idxMgmt.breadcrumb.cloneTemplateLabel": "克隆模板",