From d0c9a2f1f52a3bbe629ee3472702e497c286d36d Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 15 Nov 2024 06:29:03 +1100 Subject: [PATCH] [8.x] [Stack Monitoring / Logs] Fix Stack Monitoring logs links (#200043) (#200227) # Backport This will backport the following commits from `main` to `8.x`: - [[Stack Monitoring / Logs] Fix Stack Monitoring logs links (#200043)](https://github.com/elastic/kibana/pull/200043) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Kerry Gallagher --- x-pack/plugins/monitoring/kibana.jsonc | 6 ++-- .../monitoring/public/components/logs/logs.js | 25 ++++++++++---- .../public/components/logs/logs.test.js | 33 +++++++++++++++---- x-pack/plugins/monitoring/public/plugin.ts | 2 ++ x-pack/plugins/monitoring/public/types.ts | 2 ++ x-pack/plugins/monitoring/tsconfig.json | 1 + 6 files changed, 53 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/monitoring/kibana.jsonc b/x-pack/plugins/monitoring/kibana.jsonc index 51272f995b012..5b9b2853357b9 100644 --- a/x-pack/plugins/monitoring/kibana.jsonc +++ b/x-pack/plugins/monitoring/kibana.jsonc @@ -21,7 +21,8 @@ "observability", "observabilityShared", "dataViews", - "unifiedSearch" + "unifiedSearch", + "share" ], "optionalPlugins": [ "infra", @@ -39,7 +40,8 @@ "requiredBundles": [ "kibanaUtils", "alerting", - "kibanaReact" + "kibanaReact", + "logsShared" ] } } \ No newline at end of file diff --git a/x-pack/plugins/monitoring/public/components/logs/logs.js b/x-pack/plugins/monitoring/public/components/logs/logs.js index 3678c4ae9e27f..3da4bc9dc13ff 100644 --- a/x-pack/plugins/monitoring/public/components/logs/logs.js +++ b/x-pack/plugins/monitoring/public/components/logs/logs.js @@ -10,11 +10,12 @@ import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app'; import { upperFirst } from 'lodash'; import { Legacy } from '../../legacy_shims'; import { EuiBasicTable, EuiTitle, EuiSpacer, EuiText, 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'; import { Reason } from './reason'; +import { useKibana } from '@kbn/kibana-react-plugin/public'; +import { getLogsLocatorsFromUrlService } from '@kbn/logs-shared-plugin/common'; const getFormattedDateTimeLocal = (timestamp) => { const timezone = Legacy.shims.uiSettings?.get('dateFormat:tz'); @@ -110,7 +111,7 @@ const clusterColumns = [ }, ]; -function getLogsUiLink(clusterUuid, nodeId, indexUuid) { +function getLogsUiLink(clusterUuid, nodeId, indexUuid, sharePlugin) { const params = []; if (clusterUuid) { params.push(`elasticsearch.cluster.uuid:${clusterUuid}`); @@ -122,15 +123,23 @@ function getLogsUiLink(clusterUuid, nodeId, indexUuid) { params.push(`elasticsearch.index.name:${indexUuid}`); } - const base = Legacy.shims.infra.locators.logsLocator.getRedirectUrl({ - logView: { logViewId: INFRA_SOURCE_ID, type: 'log-view-reference' }, - ...(params.length ? { filter: params.join(' and ') } : {}), + const filter = params.join(' and '); + const { logsLocator } = getLogsLocatorsFromUrlService(sharePlugin.url); + + const base = logsLocator.getRedirectUrl({ + filter, }); return base; } -export class Logs extends PureComponent { +export const Logs = (props) => { + const { + services: { share }, + } = useKibana(); + return ; +}; +export class LogsContent extends PureComponent { renderLogs() { const { logs: { enabled, logs }, @@ -165,7 +174,9 @@ export class Logs extends PureComponent { nodeId, clusterUuid, indexUuid, + sharePlugin, } = this.props; + if (!enabled || !show) { return null; } @@ -184,7 +195,7 @@ export class Logs extends PureComponent { defaultMessage="Visit {link} to dive deeper." values={{ link: ( - + {i18n.translate('xpack.monitoring.logs.listing.calloutLinkText', { defaultMessage: 'Logs', })} diff --git a/x-pack/plugins/monitoring/public/components/logs/logs.test.js b/x-pack/plugins/monitoring/public/components/logs/logs.test.js index 23292ff742fcd..1117a484a294c 100644 --- a/x-pack/plugins/monitoring/public/components/logs/logs.test.js +++ b/x-pack/plugins/monitoring/public/components/logs/logs.test.js @@ -7,7 +7,18 @@ import React from 'react'; import { shallow } from 'enzyme'; -import { Logs } from './logs'; +import { LogsContent } from './logs'; +import { sharePluginMock } from '@kbn/share-plugin/public/mocks'; + +const sharePlugin = sharePluginMock.createStartContract(); + +jest.mock('@kbn/logs-shared-plugin/common', () => { + return { + getLogsLocatorsFromUrlService: jest.fn().mockReturnValue({ + logsLocator: { getRedirectUrl: jest.fn(() => '') }, + }), + }; +}); jest.mock('../../legacy_shims', () => ({ Legacy: { @@ -123,32 +134,40 @@ const logs = { describe('Logs', () => { it('should render normally', () => { - const component = shallow(); + const component = shallow(); expect(component).toMatchSnapshot(); }); it('should render fewer columns for node or index view', () => { - const component = shallow(); + const component = shallow(); expect(component.find('EuiBasicTable').prop('columns')).toMatchSnapshot(); }); it('should render a link to filter by cluster uuid', () => { - const component = shallow(); + const component = shallow( + + ); expect(component.find('EuiCallOut')).toMatchSnapshot(); }); it('should render a link to filter by cluster uuid and node uuid', () => { - const component = shallow(); + const component = shallow( + + ); expect(component.find('EuiCallOut')).toMatchSnapshot(); }); it('should render a link to filter by cluster uuid and index uuid', () => { - const component = shallow(); + const component = shallow( + + ); expect(component.find('EuiCallOut')).toMatchSnapshot(); }); it('should render a reason if the logs are disabled', () => { - const component = shallow(); + const component = shallow( + + ); expect(component).toMatchSnapshot(); }); }); diff --git a/x-pack/plugins/monitoring/public/plugin.ts b/x-pack/plugins/monitoring/public/plugin.ts index c6cfbdc48094c..e29faa9ca5d86 100644 --- a/x-pack/plugins/monitoring/public/plugin.ts +++ b/x-pack/plugins/monitoring/public/plugin.ts @@ -101,6 +101,7 @@ export class MonitoringPlugin element: params.element, core: coreStart, data: pluginsStart.data, + share: pluginsStart.share, isCloud: Boolean(plugins.cloud?.isCloudEnabled), pluginInitializerContext: this.initializerContext, externalConfig, @@ -124,6 +125,7 @@ export class MonitoringPlugin appMountParameters: deps.appMountParameters, dataViews: deps.dataViews, infra: deps.infra, + share: deps.share, }); const config = Object.fromEntries(externalConfig); diff --git a/x-pack/plugins/monitoring/public/types.ts b/x-pack/plugins/monitoring/public/types.ts index 5e6590968d232..cd5314521f947 100644 --- a/x-pack/plugins/monitoring/public/types.ts +++ b/x-pack/plugins/monitoring/public/types.ts @@ -16,6 +16,7 @@ import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; import { DashboardStart } from '@kbn/dashboard-plugin/public'; import { FleetStart } from '@kbn/fleet-plugin/public'; import type { InfraClientStartExports } from '@kbn/infra-plugin/public'; +import { SharePluginStart } from '@kbn/share-plugin/public'; export interface MonitoringStartPluginDependencies { navigation: NavigationStart; @@ -26,6 +27,7 @@ export interface MonitoringStartPluginDependencies { dashboard?: DashboardStart; fleet?: FleetStart; infra?: InfraClientStartExports; + share: SharePluginStart; } interface LegacyStartDependencies { diff --git a/x-pack/plugins/monitoring/tsconfig.json b/x-pack/plugins/monitoring/tsconfig.json index 3b78104e65b8c..48b538a00c1eb 100644 --- a/x-pack/plugins/monitoring/tsconfig.json +++ b/x-pack/plugins/monitoring/tsconfig.json @@ -48,6 +48,7 @@ "@kbn/flot-charts", "@kbn/ui-theme", "@kbn/core-elasticsearch-server", + "@kbn/share-plugin", ], "exclude": [ "target/**/*",