Skip to content

Commit

Permalink
[8.x] [Stack Monitoring] Switch Logs Explorer locator for Discover lo…
Browse files Browse the repository at this point in the history
…cator in Stack Monitoring (#200546) (#202137)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Stack Monitoring] Switch Logs Explorer locator for Discover locator
in Stack Monitoring
(#200546)](#200546)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kerry
Gallagher","email":"kerry.gallagher@elastic.co"},"sourceCommit":{"committedDate":"2024-11-28T10:52:38Z","message":"[Stack
Monitoring] Switch Logs Explorer locator for Discover locator in Stack
Monitoring (#200546)\n\n## Summary\r\n\r\nCloses
#200256
and\r\nhttps://github.com//issues/200218.\r\n\r\n##
Overview of changes\r\n\r\n- The call to
`logsShared.logViews.defineInternalLogView()` is removed\r\nas Log Views
will be deprecated.\r\n- The logs indices that were previously defined
via\r\n`defineInternalLogView()` are now exposed
via\r\n`externalConfig.logsIndices`\r\n- As part of this change
`ui.logs` from `config` is now exposed to\r\nbrowser. Given this is just
an index pattern I don't believe there are\r\nany security concerns
here.\r\n- `getIndexPatterns()` has been moved to common (this makes it
look like\r\nthere's a lot of file changes here).\r\n- The Logs Explorer
locator is swapped for the Discover locator using an\r\nad-hoc data
view.\r\n - This is hidden if Discover isn't available.\r\n\r\nThe
behaviour here should match exactly what we had before, as the
same\r\nindices are constructed from `getIndexPatterns()` and we apply
the same\r\n`query`.\r\n\r\nStack Monitoring reviewer: The path changes
from moving\r\n`getIndexPatterns()` were automated so there shouldn't be
any issues,\r\nbut given it's used extensively please check everything
works as\r\nexpected.\r\n\r\n## Screenshots\r\n\r\n![Screenshot
2024-11-18 at 11
59\r\n45](https://github.com/user-attachments/assets/59b61421-c6f9-4df0-87c5-c67ca732c89f)\r\n\r\n![Screenshot
2024-11-18 at 12
00\r\n15](https://github.com/user-attachments/assets/5a934883-1c35-4551-a045-705b28dfcbb7)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"3e538d67c1378dc438d9f81cb603a7965026ac0c","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:obs-ux-logs","backport:version","v8.18.0","v8.16.2"],"title":"[Stack
Monitoring] Switch Logs Explorer locator for Discover locator in Stack
Monitoring","number":200546,"url":"https://github.com/elastic/kibana/pull/200546","mergeCommit":{"message":"[Stack
Monitoring] Switch Logs Explorer locator for Discover locator in Stack
Monitoring (#200546)\n\n## Summary\r\n\r\nCloses
#200256
and\r\nhttps://github.com//issues/200218.\r\n\r\n##
Overview of changes\r\n\r\n- The call to
`logsShared.logViews.defineInternalLogView()` is removed\r\nas Log Views
will be deprecated.\r\n- The logs indices that were previously defined
via\r\n`defineInternalLogView()` are now exposed
via\r\n`externalConfig.logsIndices`\r\n- As part of this change
`ui.logs` from `config` is now exposed to\r\nbrowser. Given this is just
an index pattern I don't believe there are\r\nany security concerns
here.\r\n- `getIndexPatterns()` has been moved to common (this makes it
look like\r\nthere's a lot of file changes here).\r\n- The Logs Explorer
locator is swapped for the Discover locator using an\r\nad-hoc data
view.\r\n - This is hidden if Discover isn't available.\r\n\r\nThe
behaviour here should match exactly what we had before, as the
same\r\nindices are constructed from `getIndexPatterns()` and we apply
the same\r\n`query`.\r\n\r\nStack Monitoring reviewer: The path changes
from moving\r\n`getIndexPatterns()` were automated so there shouldn't be
any issues,\r\nbut given it's used extensively please check everything
works as\r\nexpected.\r\n\r\n## Screenshots\r\n\r\n![Screenshot
2024-11-18 at 11
59\r\n45](https://github.com/user-attachments/assets/59b61421-c6f9-4df0-87c5-c67ca732c89f)\r\n\r\n![Screenshot
2024-11-18 at 12
00\r\n15](https://github.com/user-attachments/assets/5a934883-1c35-4551-a045-705b28dfcbb7)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"3e538d67c1378dc438d9f81cb603a7965026ac0c"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200546","number":200546,"mergeCommit":{"message":"[Stack
Monitoring] Switch Logs Explorer locator for Discover locator in Stack
Monitoring (#200546)\n\n## Summary\r\n\r\nCloses
#200256
and\r\nhttps://github.com//issues/200218.\r\n\r\n##
Overview of changes\r\n\r\n- The call to
`logsShared.logViews.defineInternalLogView()` is removed\r\nas Log Views
will be deprecated.\r\n- The logs indices that were previously defined
via\r\n`defineInternalLogView()` are now exposed
via\r\n`externalConfig.logsIndices`\r\n- As part of this change
`ui.logs` from `config` is now exposed to\r\nbrowser. Given this is just
an index pattern I don't believe there are\r\nany security concerns
here.\r\n- `getIndexPatterns()` has been moved to common (this makes it
look like\r\nthere's a lot of file changes here).\r\n- The Logs Explorer
locator is swapped for the Discover locator using an\r\nad-hoc data
view.\r\n - This is hidden if Discover isn't available.\r\n\r\nThe
behaviour here should match exactly what we had before, as the
same\r\nindices are constructed from `getIndexPatterns()` and we apply
the same\r\n`query`.\r\n\r\nStack Monitoring reviewer: The path changes
from moving\r\n`getIndexPatterns()` were automated so there shouldn't be
any issues,\r\nbut given it's used extensively please check everything
works as\r\nexpected.\r\n\r\n## Screenshots\r\n\r\n![Screenshot
2024-11-18 at 11
59\r\n45](https://github.com/user-attachments/assets/59b61421-c6f9-4df0-87c5-c67ca732c89f)\r\n\r\n![Screenshot
2024-11-18 at 12
00\r\n15](https://github.com/user-attachments/assets/5a934883-1c35-4551-a045-705b28dfcbb7)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"3e538d67c1378dc438d9f81cb603a7965026ac0c"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Kerry Gallagher <kerry.gallagher@elastic.co>
  • Loading branch information
kibanamachine and Kerry350 authored Nov 28, 2024
1 parent ca3f5a2 commit dde108c
Show file tree
Hide file tree
Showing 85 changed files with 172 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'monitoring.ui.enabled (boolean?)',
'monitoring.ui.min_interval_seconds (number?)',
'monitoring.ui.show_license_expiration (boolean?)',
'monitoring.ui.logs.index (string?)',
'newsfeed.fetchInterval (duration?)',
'newsfeed.mainInterval (duration?)',
'newsfeed.service.pathTemplate (string?)',
Expand Down
5 changes: 0 additions & 5 deletions x-pack/plugins/monitoring/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@ export const METRICBEAT_INDEX_NAME_UNIQUE_TOKEN = '-mb-';
// We use this for metricbeat migration to identify specific products that we do not have constants for
export const ELASTICSEARCH_SYSTEM_ID = 'elasticsearch';

/**
* The id of the infra source owned by the monitoring plugin.
*/
export const INFRA_SOURCE_ID = 'internal-stack-monitoring';

/*
* These constants represent code paths within `getClustersFromRequest`
* that an api call wants to invoke. This is meant as an optimization to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { DS_INDEX_PATTERN_TYPES } from '../../../common/constants';
import { MonitoringConfig } from '../..';
import { DS_INDEX_PATTERN_TYPES } from './constants';
import { MonitoringConfig } from '../server';
import {
getElasticsearchDataset,
getKibanaDataset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { prefixIndexPatternWithCcs } from '../../../common/ccs_utils';
import { prefixIndexPatternWithCcs } from './ccs_utils';
import {
INDEX_PATTERN_ELASTICSEARCH,
INDEX_PATTERN_ELASTICSEARCH_ECS,
Expand All @@ -16,8 +16,8 @@ import {
DS_INDEX_PATTERN_METRICS,
INDEX_PATTERN_TYPES,
INDEX_PATTERN_ENTERPRISE_SEARCH,
} from '../../../common/constants';
import { MonitoringConfig } from '../../config';
} from './constants';
import type { MonitoringConfig } from '../server/config';

interface CommonIndexPatternArgs {
config: MonitoringConfig;
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/monitoring/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
],
"optionalPlugins": [
"infra",
"logsShared",
"usageCollection",
"home",
"cloud",
Expand All @@ -41,7 +40,6 @@
"kibanaUtils",
"alerting",
"kibanaReact",
"logsShared"
]
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 22 additions & 10 deletions x-pack/plugins/monitoring/public/components/logs/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { PureComponent } from 'react';
import React, { PureComponent, useContext } from 'react';
import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';
import { upperFirst } from 'lodash';
import { Legacy } from '../../legacy_shims';
Expand All @@ -15,7 +15,7 @@ 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';
import { ExternalConfigContext } from '../../application/contexts/external_config_context';

const getFormattedDateTimeLocal = (timestamp) => {
const timezone = Legacy.shims.uiSettings?.get('dateFormat:tz');
Expand Down Expand Up @@ -111,7 +111,7 @@ const clusterColumns = [
},
];

function getLogsUiLink(clusterUuid, nodeId, indexUuid, sharePlugin) {
function getLogsUiLink(clusterUuid, nodeId, indexUuid, sharePlugin, logsIndices) {
const params = [];
if (clusterUuid) {
params.push(`elasticsearch.cluster.uuid:${clusterUuid}`);
Expand All @@ -124,10 +124,17 @@ function getLogsUiLink(clusterUuid, nodeId, indexUuid, sharePlugin) {
}

const filter = params.join(' and ');
const { logsLocator } = getLogsLocatorsFromUrlService(sharePlugin.url);
const discoverLocator = sharePlugin.url.locators.get('DISCOVER_APP_LOCATOR');

const base = logsLocator.getRedirectUrl({
filter,
const base = discoverLocator.getRedirectUrl({
dataViewSpec: {
id: logsIndices,
title: logsIndices,
},
query: {
language: 'kuery',
query: filter,
},
});

return base;
Expand All @@ -137,7 +144,8 @@ export const Logs = (props) => {
const {
services: { share },
} = useKibana();
return <LogsContent sharePlugin={share} {...props} />;
const externalConfig = useContext(ExternalConfigContext);
return <LogsContent sharePlugin={share} logsIndices={externalConfig.logsIndices} {...props} />;
};
export class LogsContent extends PureComponent {
renderLogs() {
Expand Down Expand Up @@ -168,13 +176,15 @@ export class LogsContent extends PureComponent {

renderCallout() {
const { capabilities: uiCapabilities, infra, kibanaServices } = Legacy.shims;
const show = uiCapabilities.logs && uiCapabilities.logs.show;
const show = uiCapabilities.discover && uiCapabilities.discover.show;

const {
logs: { enabled },
nodeId,
clusterUuid,
indexUuid,
sharePlugin,
logsIndices,
} = this.props;

if (!enabled || !show) {
Expand All @@ -195,9 +205,11 @@ export class LogsContent extends PureComponent {
defaultMessage="Visit {link} to dive deeper."
values={{
link: (
<EuiLink href={getLogsUiLink(clusterUuid, nodeId, indexUuid, sharePlugin)}>
<EuiLink
href={getLogsUiLink(clusterUuid, nodeId, indexUuid, sharePlugin, logsIndices)}
>
{i18n.translate('xpack.monitoring.logs.listing.calloutLinkText', {
defaultMessage: 'Logs',
defaultMessage: 'Discover',
})}
</EuiLink>
),
Expand Down
72 changes: 48 additions & 24 deletions x-pack/plugins/monitoring/public/components/logs/logs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,26 @@ import { shallow } from 'enzyme';
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: {
shims: {
getBasePath: () => '',
capabilities: { logs: { show: true } },
infra: {
locators: {
logsLocator: {
getRedirectUrl: () => '',
},
},
},
capabilities: { discover: { show: true } },
infra: {},
},
},
}));

const sharePlugin = {
url: {
locators: {
get: () => {
return sharePluginMock.createLocator();
},
},
},
};

const logs = {
enabled: true,
limit: 10,
Expand Down Expand Up @@ -134,39 +128,69 @@ const logs = {

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

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

it('should render a link to filter by cluster uuid', () => {
const component = shallow(
<LogsContent sharePlugin={sharePlugin} logs={logs} clusterUuid="12345" />
<LogsContent
sharePlugin={sharePlugin}
logsIndices={'logs-*,*:logs-*'}
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(
<LogsContent sharePlugin={sharePlugin} logs={logs} clusterUuid="12345" nodeId="6789" />
<LogsContent
sharePlugin={sharePlugin}
logsIndices={'logs-*,*:logs-*'}
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(
<LogsContent sharePlugin={sharePlugin} logs={logs} clusterUuid="12345" indexUuid="6789" />
<LogsContent
sharePlugin={sharePlugin}
logsIndices={'logs-*,*:logs-*'}
logs={logs}
clusterUuid="12345"
indexUuid="6789"
/>
);
expect(component.find('EuiCallOut')).toMatchSnapshot();
});

it('should render a reason if the logs are disabled', () => {
const component = shallow(
<LogsContent sharePlugin={sharePlugin} logs={{ enabled: false, limit: 15, reason: {} }} />
<LogsContent
sharePlugin={sharePlugin}
logsIndices={'logs-*,*:logs-*'}
logs={{ enabled: false, limit: 15, reason: {} }}
/>
);
expect(component).toMatchSnapshot();
});
Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugins/monitoring/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { HomePublicPluginSetup } from '@kbn/home-plugin/public';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import { TriggersAndActionsUIPublicPluginSetup } from '@kbn/triggers-actions-ui-plugin/public';
import {
CCS_REMOTE_PATTERN,
RULE_DETAILS,
RULE_THREAD_POOL_SEARCH_REJECTIONS,
RULE_THREAD_POOL_WRITE_REJECTIONS,
Expand All @@ -38,6 +39,7 @@ import {
MonitoringStartPluginDependencies,
LegacyMonitoringStartPluginDependencies,
} from './types';
import { getIndexPatterns } from '../common/get_index_patterns';

interface MonitoringSetupPluginDependencies {
home?: HomePublicPluginSetup;
Expand Down Expand Up @@ -154,6 +156,7 @@ export class MonitoringPlugin
monitoring.ui.kibana.reporting.stale_status_threshold_seconds,
],
['isCcsEnabled', monitoring.ui.ccs.enabled],
['logsIndices', getLogsIndices(monitoring)],
];
}

Expand Down Expand Up @@ -188,3 +191,11 @@ export class MonitoringPlugin
}
}
}

const getLogsIndices = (config: MonitoringConfig) => {
return getIndexPatterns({
config,
type: 'logs',
ccs: CCS_REMOTE_PATTERN,
});
};
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const config: PluginConfigDescriptor<TypeOf<typeof configSchema>> = {
stale_status_threshold_seconds: true,
},
},
logs: true,
},
kibana: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { get } from 'lodash';
import { isCCSRemoteIndexName } from '@kbn/es-query';
import { CCS_REMOTE_PATTERN } from '../../../common/constants';
import { CCRReadExceptionsStats } from '../../../common/types/alerts';
import { getIndexPatterns, getElasticsearchDataset } from '../cluster/get_index_patterns';
import { getIndexPatterns, getElasticsearchDataset } from '../../../common/get_index_patterns';
import { createDatasetFilter } from './create_dataset_query_filter';
import { Globals } from '../../static_globals';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AlertCluster, AlertClusterHealth } from '../../../common/types/alerts';
import { ElasticsearchSource } from '../../../common/types/es';
import { createDatasetFilter } from './create_dataset_query_filter';
import { Globals } from '../../static_globals';
import { getIndexPatterns, getElasticsearchDataset } from '../cluster/get_index_patterns';
import { getIndexPatterns, getElasticsearchDataset } from '../../../common/get_index_patterns';
import { CCS_REMOTE_PATTERN } from '../../../common/constants';

export async function fetchClusterHealth(
Expand Down
Loading

0 comments on commit dde108c

Please sign in to comment.