Skip to content

Commit

Permalink
[Stack Monitoring] Switch Logs Explorer locator for Discover locator …
Browse files Browse the repository at this point in the history
…in Stack Monitoring (elastic#200546)

## Summary

Closes elastic#200256 and
elastic#200218.

## Overview of changes

- The call to `logsShared.logViews.defineInternalLogView()` is removed
as Log Views will be deprecated.
- The logs indices that were previously defined via
`defineInternalLogView()` are now exposed via
`externalConfig.logsIndices`
- As part of this change `ui.logs` from `config` is now exposed to
browser. Given this is just an index pattern I don't believe there are
any security concerns here.
- `getIndexPatterns()` has been moved to common (this makes it look like
there's a lot of file changes here).
- The Logs Explorer locator is swapped for the Discover locator using an
ad-hoc data view.
   - This is hidden if Discover isn't available.

The behaviour here should match exactly what we had before, as the same
indices are constructed from `getIndexPatterns()` and we apply the same
`query`.

Stack Monitoring reviewer: The path changes from moving
`getIndexPatterns()` were automated so there shouldn't be any issues,
but given it's used extensively please check everything works as
expected.

## Screenshots

![Screenshot 2024-11-18 at 11 59
45](https://github.com/user-attachments/assets/59b61421-c6f9-4df0-87c5-c67ca732c89f)

![Screenshot 2024-11-18 at 12 00
15](https://github.com/user-attachments/assets/5a934883-1c35-4551-a045-705b28dfcbb7)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 3e538d6)
  • Loading branch information
Kerry350 committed Nov 28, 2024
1 parent 50ea993 commit f1ffb9e
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 @@ -20,7 +20,6 @@
],
"optionalPlugins": [
"infra",
"logsShared",
"usageCollection",
"home",
"cloud",
Expand All @@ -35,7 +34,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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { ElasticsearchClient } from '@kbn/core/server';
import { get } from 'lodash';
import { AlertCluster } 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';
import { CCS_REMOTE_PATTERN } from '../../../common/constants';
Expand Down
Loading

0 comments on commit f1ffb9e

Please sign in to comment.