From 8d33f1fe58815ee75653ac4b32b944c2b98922e3 Mon Sep 17 00:00:00 2001
From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com>
Date: Wed, 13 Nov 2024 16:18:52 +0000
Subject: [PATCH 1/3] Fix SM logs links
---
x-pack/plugins/monitoring/kibana.jsonc | 6 +++--
.../monitoring/public/components/logs/logs.js | 25 +++++++++++++------
x-pack/plugins/monitoring/public/types.ts | 2 ++
x-pack/plugins/monitoring/tsconfig.json | 1 +
4 files changed, 25 insertions(+), 9 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/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/**/*",
From 03b18b4dca1c2dcdebe9e87f125537233e817d75 Mon Sep 17 00:00:00 2001
From: mohamedhamed-ahmed
Date: Thu, 14 Nov 2024 11:53:05 +0100
Subject: [PATCH 2/3] fix dependency references
---
x-pack/plugins/monitoring/public/plugin.ts | 2 ++
1 file changed, 2 insertions(+)
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);
From 5e6a62c4e26acd34e2828c6c2cb985f18728bba3 Mon Sep 17 00:00:00 2001
From: mohamedhamed-ahmed
Date: Thu, 14 Nov 2024 16:32:18 +0100
Subject: [PATCH 3/3] fix snapshot tests
---
.../public/components/logs/logs.test.js | 33 +++++++++++++++----
1 file changed, 26 insertions(+), 7 deletions(-)
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();
});
});