From 558dd120a18c478aacebc14647952f72f6155ec6 Mon Sep 17 00:00:00 2001 From: Kerry Gallagher Date: Tue, 31 Mar 2020 17:54:34 +0100 Subject: [PATCH] Grok debugger migration (#60658) * Migrates Grok Debugger to new platform --- x-pack/.i18nrc.json | 2 +- x-pack/index.js | 2 - x-pack/legacy/plugins/grokdebugger/index.js | 31 ------ .../plugins/grokdebugger/public/register.js | 33 ------ .../grokdebugger/public/register_feature.ts | 34 ------ .../call_with_request_factory.js | 18 --- .../lib/call_with_request_factory/index.js | 7 -- .../check_license/__tests__/check_license.js | 90 --------------- .../server/lib/check_license/check_license.js | 50 --------- .../server/lib/check_license/index.js | 7 -- .../lib/error_wrappers/wrap_es_error.js | 18 --- .../__tests__/license_pre_routing_factory.js | 64 ----------- .../license_pre_routing_factory.js | 24 ---- .../lib/register_license_checker/index.js | 7 -- .../register_license_checker.js | 21 ---- .../register_grok_simulate_route.js | 41 ------- .../plugins/grokdebugger/README.md | 0 .../grokdebugger/common/constants/editor.js | 0 .../grokdebugger/common/constants/index.js | 0 .../grokdebugger/common/constants/plugin.js | 0 .../grokdebugger/common/constants/routes.js | 0 x-pack/plugins/grokdebugger/kibana.json | 13 +++ .../custom_patterns_input.js | 0 .../components/custom_patterns_input/index.js | 0 .../components/event_input/event_input.js | 0 .../public/components/event_input/index.js | 0 .../components/event_output/event_output.js | 0 .../public/components/event_output/index.js | 0 .../components/grok_debugger/brace_imports.ts | 0 .../components/grok_debugger/grok_debugger.js | 15 ++- .../public/components/grok_debugger/index.js | 0 .../public/components/inactive_license.js | 91 +++++++++++++++ .../public/components/pattern_input/index.js | 0 .../components/pattern_input/pattern_input.js | 0 .../grokdebugger/public}/index.js | 6 +- .../public/lib/ace/grok_highlight_rules.js | 2 +- .../grokdebugger/public/lib/ace/grok_mode.js | 2 +- .../grokdebugger/public/lib/ace/index.js | 0 .../grokdebugger_request.js | 0 .../models/grokdebugger_request/index.js | 0 .../grokdebugger_response.js | 0 .../models/grokdebugger_response/index.js | 0 x-pack/plugins/grokdebugger/public/plugin.js | 35 ++++++ .../grokdebugger/public/register_feature.ts | 27 +++++ .../plugins/grokdebugger/public/render_app.js | 20 +++- .../grokdebugger/grokdebugger_service.js | 4 +- .../grokdebugger/server}/index.js | 6 +- .../server/lib/kibana_framework.ts | 105 ++++++++++++++++++ .../__tests__/grokdebugger_request.js | 0 .../grokdebugger_request.js | 0 .../models/grokdebugger_request/index.js | 0 .../__tests__/grokdebugger_response.js | 0 .../grokdebugger_response.js | 0 .../models/grokdebugger_response/index.js | 0 x-pack/plugins/grokdebugger/server/plugin.js | 30 +++++ .../server/routes/api/grokdebugger/index.js | 0 .../register_grok_simulate_route.js | 46 ++++++++ .../register_grokdebugger_routes.js | 4 +- .../translations/translations/ja-JP.json | 4 - .../translations/translations/zh-CN.json | 4 - 60 files changed, 390 insertions(+), 473 deletions(-) delete mode 100644 x-pack/legacy/plugins/grokdebugger/index.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/public/register.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/public/register_feature.ts delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/lib/call_with_request_factory/call_with_request_factory.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/lib/call_with_request_factory/index.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/lib/check_license/__tests__/check_license.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/lib/check_license/check_license.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/lib/check_license/index.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/lib/error_wrappers/wrap_es_error.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/__tests__/license_pre_routing_factory.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory/license_pre_routing_factory.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/lib/register_license_checker/index.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/lib/register_license_checker/register_license_checker.js delete mode 100644 x-pack/legacy/plugins/grokdebugger/server/routes/api/grokdebugger/register_grok_simulate_route.js rename x-pack/{legacy => }/plugins/grokdebugger/README.md (100%) rename x-pack/{legacy => }/plugins/grokdebugger/common/constants/editor.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/common/constants/index.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/common/constants/plugin.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/common/constants/routes.js (100%) create mode 100644 x-pack/plugins/grokdebugger/kibana.json rename x-pack/{legacy => }/plugins/grokdebugger/public/components/custom_patterns_input/custom_patterns_input.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/components/custom_patterns_input/index.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/components/event_input/event_input.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/components/event_input/index.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/components/event_output/event_output.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/components/event_output/index.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/components/grok_debugger/brace_imports.ts (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/components/grok_debugger/grok_debugger.js (90%) rename x-pack/{legacy => }/plugins/grokdebugger/public/components/grok_debugger/index.js (100%) create mode 100644 x-pack/plugins/grokdebugger/public/components/inactive_license.js rename x-pack/{legacy => }/plugins/grokdebugger/public/components/pattern_input/index.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/components/pattern_input/pattern_input.js (100%) rename x-pack/{legacy/plugins/grokdebugger/server/lib/error_wrappers => plugins/grokdebugger/public}/index.js (66%) rename x-pack/{legacy => }/plugins/grokdebugger/public/lib/ace/grok_highlight_rules.js (97%) rename x-pack/{legacy => }/plugins/grokdebugger/public/lib/ace/grok_mode.js (95%) rename x-pack/{legacy => }/plugins/grokdebugger/public/lib/ace/index.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/models/grokdebugger_request/grokdebugger_request.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/models/grokdebugger_request/index.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/models/grokdebugger_response/grokdebugger_response.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/public/models/grokdebugger_response/index.js (100%) create mode 100644 x-pack/plugins/grokdebugger/public/plugin.js create mode 100644 x-pack/plugins/grokdebugger/public/register_feature.ts rename x-pack/{legacy => }/plugins/grokdebugger/public/render_app.js (51%) rename x-pack/{legacy => }/plugins/grokdebugger/public/services/grokdebugger/grokdebugger_service.js (78%) rename x-pack/{legacy/plugins/grokdebugger/server/lib/license_pre_routing_factory => plugins/grokdebugger/server}/index.js (66%) create mode 100644 x-pack/plugins/grokdebugger/server/lib/kibana_framework.ts rename x-pack/{legacy => }/plugins/grokdebugger/server/models/grokdebugger_request/__tests__/grokdebugger_request.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/server/models/grokdebugger_request/grokdebugger_request.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/server/models/grokdebugger_request/index.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/server/models/grokdebugger_response/__tests__/grokdebugger_response.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/server/models/grokdebugger_response/grokdebugger_response.js (100%) rename x-pack/{legacy => }/plugins/grokdebugger/server/models/grokdebugger_response/index.js (100%) create mode 100644 x-pack/plugins/grokdebugger/server/plugin.js rename x-pack/{legacy => }/plugins/grokdebugger/server/routes/api/grokdebugger/index.js (100%) create mode 100644 x-pack/plugins/grokdebugger/server/routes/api/grokdebugger/register_grok_simulate_route.js rename x-pack/{legacy => }/plugins/grokdebugger/server/routes/api/grokdebugger/register_grokdebugger_routes.js (77%) diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index 2a28e349ace9..ae8d61769b14 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 fb14b3dc10a4..6fab13d726fa 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 7803aed739b9..000000000000 --- 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 74679d65e52d..000000000000 --- 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 97d2e53ce783..000000000000 --- 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 7359a831994f..000000000000 --- 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 787814d87dff..000000000000 --- 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 7e32d68a67ec..000000000000 --- 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 c7a8d2bbca05..000000000000 --- 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 f2c070fd44b6..000000000000 --- 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 dfcd4e3b1e17..000000000000 --- 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 135317f05077..000000000000 --- 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 88c844de3e2c..000000000000 --- 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 7b0f97c38d12..000000000000 --- 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 ee9a9a3ebdec..000000000000 --- 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 14ea1e7acb66..000000000000 --- 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 000000000000..4d37f9ccdb0d --- /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 dfdd524b3d3d..c27f3314e60a 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 000000000000..ff0306b78919 --- /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 3756b0c74fb1..960c9d8d58e4 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 3da1afdc0fc0..1851d53ff0ee 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 84b2e482673c..cd82a5b9917e 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 000000000000..9de4f9c3f8bc --- /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 000000000000..f05d4c973a5f --- /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 2c4894bb70ee..82783c7bd979 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 c6d28adcefd7..e26c9c5091e1 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 0743e443955f..960c9d8d58e4 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 000000000000..749f5e9ebf8f --- /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 000000000000..06ddd92aefac --- /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 000000000000..f953bc64c3b4 --- /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 6d27ce2ca054..d7ecd1c360d8 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 447a3b706bf9..aea6e2ab0009 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -5776,14 +5776,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 5ca4f609a6dc..dfc5ef065732 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -5776,14 +5776,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": "克隆模板",