Skip to content

Commit

Permalink
[Stack Monitoring / Logs] Fix Stack Monitoring logs links (elastic#20…
Browse files Browse the repository at this point in the history
…0043)

## Summary

Fixes
elastic#199902 (comment).

This was missed in elastic#190835 due to
Stack Monitoring's lack of type checking in certain files. `infra` no
longer exposes `logsLocators`.

This uses `getLogsLocatorsFromUrlService`, technically we could go to
Discover now knowing that Logs Explorer will be deprecated in the
future. But it will make more sense to convert
`getLogsLocatorsFromUrlService` over to using the Discover locators in
one when that happens. This puts us on the same page as
elastic#190835.

This link should now work, and have the correct filters applied.

![Screenshot 2024-11-13 at 16 09
15](https://github.com/user-attachments/assets/e1f8fd18-ac73-4179-af4c-1727a2afeeec)

---------

Co-authored-by: mohamedhamed-ahmed <[email protected]>
  • Loading branch information
2 people authored and CAWilson94 committed Nov 18, 2024
1 parent b151c2d commit 1aa21cb
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
6 changes: 4 additions & 2 deletions x-pack/plugins/monitoring/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"observability",
"observabilityShared",
"dataViews",
"unifiedSearch"
"unifiedSearch",
"share"
],
"optionalPlugins": [
"infra",
Expand All @@ -39,7 +40,8 @@
"requiredBundles": [
"kibanaUtils",
"alerting",
"kibanaReact"
"kibanaReact",
"logsShared"
]
}
}
25 changes: 18 additions & 7 deletions x-pack/plugins/monitoring/public/components/logs/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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}`);
Expand All @@ -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 <LogsContent sharePlugin={share} {...props} />;
};
export class LogsContent extends PureComponent {
renderLogs() {
const {
logs: { enabled, logs },
Expand Down Expand Up @@ -165,7 +174,9 @@ export class Logs extends PureComponent {
nodeId,
clusterUuid,
indexUuid,
sharePlugin,
} = this.props;

if (!enabled || !show) {
return null;
}
Expand All @@ -184,7 +195,7 @@ export class Logs extends PureComponent {
defaultMessage="Visit {link} to dive deeper."
values={{
link: (
<EuiLink href={getLogsUiLink(clusterUuid, nodeId, indexUuid)}>
<EuiLink href={getLogsUiLink(clusterUuid, nodeId, indexUuid, sharePlugin)}>
{i18n.translate('xpack.monitoring.logs.listing.calloutLinkText', {
defaultMessage: 'Logs',
})}
Expand Down
33 changes: 26 additions & 7 deletions x-pack/plugins/monitoring/public/components/logs/logs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -123,32 +134,40 @@ const logs = {

describe('Logs', () => {
it('should render normally', () => {
const component = shallow(<Logs logs={logs} />);
const component = shallow(<LogsContent sharePlugin={sharePlugin} logs={logs} />);
expect(component).toMatchSnapshot();
});

it('should render fewer columns for node or index view', () => {
const component = shallow(<Logs logs={logs} nodeId="12345" />);
const component = shallow(<LogsContent sharePlugin={sharePlugin} logs={logs} nodeId="12345" />);
expect(component.find('EuiBasicTable').prop('columns')).toMatchSnapshot();
});

it('should render a link to filter by cluster uuid', () => {
const component = shallow(<Logs logs={logs} clusterUuid="12345" />);
const component = shallow(
<LogsContent sharePlugin={sharePlugin} logs={logs} clusterUuid="12345" />
);
expect(component.find('EuiCallOut')).toMatchSnapshot();
});

it('should render a link to filter by cluster uuid and node uuid', () => {
const component = shallow(<Logs logs={logs} clusterUuid="12345" nodeId="6789" />);
const component = shallow(
<LogsContent sharePlugin={sharePlugin} logs={logs} clusterUuid="12345" nodeId="6789" />
);
expect(component.find('EuiCallOut')).toMatchSnapshot();
});

it('should render a link to filter by cluster uuid and index uuid', () => {
const component = shallow(<Logs logs={logs} clusterUuid="12345" indexUuid="6789" />);
const component = shallow(
<LogsContent sharePlugin={sharePlugin} logs={logs} clusterUuid="12345" indexUuid="6789" />
);
expect(component.find('EuiCallOut')).toMatchSnapshot();
});

it('should render a reason if the logs are disabled', () => {
const component = shallow(<Logs logs={{ enabled: false, limit: 15, reason: {} }} />);
const component = shallow(
<LogsContent sharePlugin={sharePlugin} logs={{ enabled: false, limit: 15, reason: {} }} />
);
expect(component).toMatchSnapshot();
});
});
2 changes: 2 additions & 0 deletions x-pack/plugins/monitoring/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -124,6 +125,7 @@ export class MonitoringPlugin
appMountParameters: deps.appMountParameters,
dataViews: deps.dataViews,
infra: deps.infra,
share: deps.share,
});

const config = Object.fromEntries(externalConfig);
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/monitoring/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@ export interface MonitoringStartPluginDependencies {
dashboard?: DashboardStart;
fleet?: FleetStart;
infra?: InfraClientStartExports;
share: SharePluginStart;
}

interface LegacyStartDependencies {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@kbn/flot-charts",
"@kbn/ui-theme",
"@kbn/core-elasticsearch-server",
"@kbn/share-plugin",
],
"exclude": [
"target/**/*",
Expand Down

0 comments on commit 1aa21cb

Please sign in to comment.