Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Hide anomaly detection APM settings links when ml plugin is disabled #73638

Merged
merged 3 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions x-pack/plugins/apm/public/components/app/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ interface Props {
}

export function Home({ tab }: Props) {
const { config } = useApmPluginContext();
const { config, core } = useApmPluginContext();
const isMLEnabled = !!core.application.capabilities.ml;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ML is disabled in elasticsearch or disabled in the current space, this check will still be true.
I'd suggest looking for !!core.application.capabilities.ml?.canAccessML
canAccessML is the very minimum ML capability and is true on a basic license, so the current link to the start trial page will still work correctly.

const homeTabs = getHomeTabs(config);
const selectedTab = homeTabs.find(
(homeTab) => homeTab.name === tab
Expand All @@ -105,9 +106,11 @@ export function Home({ tab }: Props) {
</EuiButtonEmpty>
</SettingsLink>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<AnomalyDetectionSetupLink />
</EuiFlexItem>
{isMLEnabled && (
<EuiFlexItem grow={false}>
<AnomalyDetectionSetupLink />
</EuiFlexItem>
)}
<EuiFlexItem grow={false}>
<SetupInstructionsLink />
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function AddEnvironments({
return (
<EuiPanel>
<EuiEmptyPrompt
iconType="warning"
iconType="alert"
body={<>{MLErrorMessages.MISSING_WRITE_PRIVILEGES}</>}
/>
</EuiPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const DEFAULT_VALUE: AnomalyDetectionApiResponse = {

export function AnomalyDetection() {
const plugin = useApmPluginContext();
const canGetJobs = !!plugin.core.application.capabilities.ml.canGetJobs;
const canGetJobs = !!plugin.core.application.capabilities.ml?.canGetJobs;
const license = useLicense();
const hasValidLicense = license?.isActive && license?.hasAtLeast('platinum');

Expand Down Expand Up @@ -66,7 +66,7 @@ export function AnomalyDetection() {
return (
<EuiPanel>
<EuiEmptyPrompt
iconType="warning"
iconType="alert"
body={<>{MLErrorMessages.MISSING_READ_PRIVILEGES}</>}
/>
</EuiPanel>
Expand Down
33 changes: 22 additions & 11 deletions x-pack/plugins/apm/public/components/app/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import {
import { HomeLink } from '../../shared/Links/apm/HomeLink';
import { useLocation } from '../../../hooks/useLocation';
import { getAPMHref } from '../../shared/Links/apm/APMLink';
import { useApmPluginContext } from '../../../hooks/useApmPluginContext';

export function Settings(props: { children: ReactNode }) {
const plugin = useApmPluginContext();
const isMLEnabled = !!plugin.core.application.capabilities.ml;
const { search, pathname } = useLocation();
return (
<>
Expand Down Expand Up @@ -48,17 +51,25 @@ export function Settings(props: { children: ReactNode }) {
'/settings/agent-configuration'
),
},
{
name: i18n.translate(
'xpack.apm.settings.anomalyDetection',
{
defaultMessage: 'Anomaly detection',
}
),
id: '4',
href: getAPMHref('/settings/anomaly-detection', search),
isSelected: pathname === '/settings/anomaly-detection',
},
...(isMLEnabled
? [
{
name: i18n.translate(
'xpack.apm.settings.anomalyDetection',
{
defaultMessage: 'Anomaly detection',
}
),
id: '4',
href: getAPMHref(
'/settings/anomaly-detection',
search
),
isSelected:
pathname === '/settings/anomaly-detection',
},
]
: []),
{
name: i18n.translate('xpack.apm.settings.customizeApp', {
defaultMessage: 'Customize app',
Expand Down