From 25802019ae794aaec56697f6bbbd457267b5c809 Mon Sep 17 00:00:00 2001 From: Chris Roberson Date: Thu, 13 Jun 2019 09:28:54 -0400 Subject: [PATCH] [Monitoring] Integrate logs source for Logs UI (#36929) * Define and use an internal log ui source configuration * Fix urls in tests * Remove unnecessary code --- x-pack/plugins/monitoring/common/constants.js | 5 +++++ x-pack/plugins/monitoring/index.js | 5 ++++- x-pack/plugins/monitoring/init.js | 5 +++++ .../logs/__snapshots__/logs.test.js.snap | 8 +++---- .../monitoring/public/components/logs/logs.js | 3 ++- .../server/lib/logs/init_infra_source.js | 21 +++++++++++++++++++ 6 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 x-pack/plugins/monitoring/server/lib/logs/init_infra_source.js diff --git a/x-pack/plugins/monitoring/common/constants.js b/x-pack/plugins/monitoring/common/constants.js index bf4f82a0bdb6..bd6dd89ee395 100644 --- a/x-pack/plugins/monitoring/common/constants.js +++ b/x-pack/plugins/monitoring/common/constants.js @@ -164,3 +164,8 @@ export const INDEX_PATTERN_FILEBEAT = 'filebeat-*'; // This is the unique token that exists in monitoring indices collected by metricbeat export const METRICBEAT_INDEX_NAME_UNIQUE_TOKEN = '-mb-'; + +/** + * The id of the infra source owned by the monitoring plugin. + */ +export const INFRA_SOURCE_ID = 'internal-stack-monitoring'; diff --git a/x-pack/plugins/monitoring/index.js b/x-pack/plugins/monitoring/index.js index 13de010a07d9..95dd0c1f3307 100644 --- a/x-pack/plugins/monitoring/index.js +++ b/x-pack/plugins/monitoring/index.js @@ -5,7 +5,7 @@ */ import { resolve } from 'path'; -import { init } from './init'; +import { init, postInit } from './init'; import { config } from './config'; import { deprecations } from './deprecations'; import { getUiExports } from './ui_exports'; @@ -24,4 +24,7 @@ export const monitoring = (kibana) => new kibana.Plugin({ config, deprecations, uiExports: getUiExports(), + postInit(server) { + postInit(server); + }, }); diff --git a/x-pack/plugins/monitoring/init.js b/x-pack/plugins/monitoring/init.js index a4f44c87d56b..5350f1f9522b 100644 --- a/x-pack/plugins/monitoring/init.js +++ b/x-pack/plugins/monitoring/init.js @@ -15,6 +15,7 @@ import { getOpsStatsCollector, getSettingsCollector, } from './server/kibana_monitoring/collectors'; +import { initInfraSource } from './server/lib/logs/init_infra_source'; /** * Initialize the Kibana Monitoring plugin by starting up asynchronous server tasks @@ -116,3 +117,7 @@ export const init = (monitoringPlugin, server) => { }; }); }; + +export const postInit = server => { + initInfraSource(server); +}; diff --git a/x-pack/plugins/monitoring/public/components/logs/__snapshots__/logs.test.js.snap b/x-pack/plugins/monitoring/public/components/logs/__snapshots__/logs.test.js.snap index de06a73e7f8c..a2d87871626b 100644 --- a/x-pack/plugins/monitoring/public/components/logs/__snapshots__/logs.test.js.snap +++ b/x-pack/plugins/monitoring/public/components/logs/__snapshots__/logs.test.js.snap @@ -15,7 +15,7 @@ exports[`Logs should render a link to filter by cluster uuid 1`] = ` Object { "link": Logs @@ -42,7 +42,7 @@ exports[`Logs should render a link to filter by cluster uuid and index uuid 1`] Object { "link": Logs @@ -69,7 +69,7 @@ exports[`Logs should render a link to filter by cluster uuid and node uuid 1`] = Object { "link": Logs @@ -297,7 +297,7 @@ exports[`Logs should render normally 1`] = ` Object { "link": Logs diff --git a/x-pack/plugins/monitoring/public/components/logs/logs.js b/x-pack/plugins/monitoring/public/components/logs/logs.js index 55cb3cbb28cc..3db300443e2d 100644 --- a/x-pack/plugins/monitoring/public/components/logs/logs.js +++ b/x-pack/plugins/monitoring/public/components/logs/logs.js @@ -14,6 +14,7 @@ import { EuiCallOut, EuiLink, } from '@elastic/eui'; +import { INFRA_SOURCE_ID } from '../../../common/constants'; import { formatDateTimeLocal } from '../../../common/formatting'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -110,7 +111,7 @@ const clusterColumns = [ ]; function getLogsUiLink(clusterUuid, nodeId, indexUuid) { - const base = `${chrome.getBasePath()}/app/infra#/link-to/logs`; + const base = `${chrome.getBasePath()}/app/infra#/link-to/${INFRA_SOURCE_ID}/logs`; const params = []; if (clusterUuid) { diff --git a/x-pack/plugins/monitoring/server/lib/logs/init_infra_source.js b/x-pack/plugins/monitoring/server/lib/logs/init_infra_source.js new file mode 100644 index 000000000000..4059679e452d --- /dev/null +++ b/x-pack/plugins/monitoring/server/lib/logs/init_infra_source.js @@ -0,0 +1,21 @@ +/* + * 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 { prefixIndexPattern } from '../ccs_utils'; +import { INDEX_PATTERN_FILEBEAT, INFRA_SOURCE_ID } from '../../../common/constants'; + +export const initInfraSource = server => { + const infraPlugin = server.plugins.infra; + + if (infraPlugin) { + const config = server.config(); + const filebeatIndexPattern = prefixIndexPattern(config, INDEX_PATTERN_FILEBEAT, '*'); + infraPlugin.defineInternalSourceConfiguration(INFRA_SOURCE_ID, { + name: 'Elastic Stack Logs', + logAlias: filebeatIndexPattern + }); + } +};