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

[Logs UI] ML log integration splash screen #69288

Merged
merged 19 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 13 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from './missing_results_privileges_prompt';
export * from './missing_setup_privileges_prompt';
export * from './ml_unavailable_prompt';
export * from './setup_status_unknown_prompt';
export * from './subscription_splash_content';
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import {
EuiPage,
EuiPageBody,
EuiPageContent,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
EuiTitle,
EuiText,
EuiButton,
EuiButtonEmpty,
EuiImage,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { LoadingPage } from '../../loading_page';

import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { euiStyled } from '../../../../../observability/public';
import { useTrialStatus, TrialStatusLoadState } from '../../../hooks/use_trial_state';

export const SubscriptionSplashContent: React.FC = () => {
const { services } = useKibana();
const { loadState, isTrialAvailable } = useTrialStatus();

if (loadState === TrialStatusLoadState.Loading) {
afgomez marked this conversation as resolved.
Show resolved Hide resolved
return (
<LoadingPage
message={i18n.translate('xpack.infra.logs.logAnalysis.splash.loadingMessage', {
defaultMessage: 'Checking license...',
})}
/>
);
}

const canStartTrial = isTrialAvailable && loadState === TrialStatusLoadState.Ok;

let title;
let description;
let cta;

if (canStartTrial) {
title = (
<FormattedMessage
id="xpack.infra.logs.logAnalysis.splash.startTrialTitle"
defaultMessage="Start a free 14 day Platinum subscription trial"
afgomez marked this conversation as resolved.
Show resolved Hide resolved
/>
);

description = (
<FormattedMessage
id="xpack.infra.logs.logAnalysis.splash.startTrialDescription"
defaultMessage="Run Machine Learning jobs to view detected anomalies in your logs with our anomaly detection feature—part of the Platinum Elastic Stack subscription."
afgomez marked this conversation as resolved.
Show resolved Hide resolved
/>
);

cta = (
<EuiButton
fullWidth={false}
fill
href={services.http.basePath.prepend('/app/management/stack/license_management')}
>
<FormattedMessage
id="xpack.infra.logs.logAnalysis.splash.startTrialCta"
defaultMessage="Start free trial"
afgomez marked this conversation as resolved.
Show resolved Hide resolved
/>
</EuiButton>
);
} else {
title = (
<FormattedMessage
id="xpack.infra.logs.logAnalysis.splash.updateSubscriptionTitle"
defaultMessage="Update to a Platinum subscription"
afgomez marked this conversation as resolved.
Show resolved Hide resolved
/>
);

description = (
<FormattedMessage
id="xpack.infra.logs.logAnalysis.splash.updateSubscriptionDescription"
defaultMessage="Run Machine Learning jobs to view detected anomalies in your logs with our anomaly detection feature—part of the Platinum Elastic Stack subscription."
afgomez marked this conversation as resolved.
Show resolved Hide resolved
/>
);

cta = (
<EuiButton fullWidth={false} fill href="https://www.elastic.co/subscriptions">
<FormattedMessage
id="xpack.infra.logs.logAnalysis.splash.updateSubscriptionCta"
defaultMessage="Update subscription"
afgomez marked this conversation as resolved.
Show resolved Hide resolved
/>
</EuiButton>
);
}

return (
<SubscriptionPage>
<EuiPageBody>
<SubscriptionPageContent verticalPosition="center" horizontalPosition="center">
<EuiFlexGroup>
<EuiFlexItem>
<EuiTitle size="m">
<h2>{title}</h2>
</EuiTitle>
<EuiSpacer size="xl" />
<EuiText>
<p>{description}</p>
</EuiText>
<EuiSpacer />
<div>{cta}</div>
</EuiFlexItem>
<EuiFlexItem>
<EuiImage
alt={i18n.translate('xpack.infra.logs.logAnalysis.splash.splashImageAlt', {
defaultMessage: 'Placeholder image',
})}
url={services.http.basePath.prepend(
'/plugins/infra/assets/anomaly_chart_minified.svg'
)}
size="fullWidth"
/>
</EuiFlexItem>
</EuiFlexGroup>
<SubscriptionPageFooter>
<EuiTitle size="xs">
<h3>
<FormattedMessage
id="xpack.infra.logs.logAnalysis.splash.learnMoreTitle"
defaultMessage="Want to learn more?"
/>
</h3>
</EuiTitle>
<EuiButtonEmpty
flush="left"
iconType="training"
target="_blank"
color="text"
href="https://www.elastic.co/guide/en/kibana/master/xpack-logs-analysis.html"
>
<FormattedMessage
id="xpack.infra.logs.logAnalysis.splash.learnMoreLink"
defaultMessage="Read documentation"
/>
</EuiButtonEmpty>
</SubscriptionPageFooter>
</SubscriptionPageContent>
</EuiPageBody>
</SubscriptionPage>
);
};

const SubscriptionPage = euiStyled(EuiPage)`
height: 100%
`;

const SubscriptionPageContent = euiStyled(EuiPageContent)`
max-width: 768px !important;
`;

const SubscriptionPageFooter = euiStyled.div`
background: ${(props) => props.theme.eui.euiColorLightestShade};
margin: 0 -${(props) => props.theme.eui.paddingSizes.l} -${(props) =>
props.theme.eui.paddingSizes.l};
padding: ${(props) => props.theme.eui.paddingSizes.l};
`;
45 changes: 45 additions & 0 deletions x-pack/plugins/infra/public/hooks/use_trial_state.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { useState, useEffect } from 'react';
import { useKibana } from '../../../../../src/plugins/kibana_react/public';
import { API_BASE_PATH as LICENSE_MANAGEMENT_API_BASE_PATH } from '../../../license_management/common/constants';

export enum TrialStatusLoadState {
afgomez marked this conversation as resolved.
Show resolved Hide resolved
Loading = 'loading',
Ok = 'ok',
Error = 'error',
}

interface UseTrialStatusState {
loadState: TrialStatusLoadState;
isTrialAvailable: boolean;
}

export function useTrialStatus(): UseTrialStatusState {
const { services } = useKibana();

const [loadState, setLoadState] = useState<TrialStatusLoadState>(TrialStatusLoadState.Loading);
const [isTrialAvailable, setIsTrialAvailable] = useState<boolean>(false);

useEffect(() => {
afgomez marked this conversation as resolved.
Show resolved Hide resolved
async function fetchTrial() {
try {
const response = await services.http.get(`${LICENSE_MANAGEMENT_API_BASE_PATH}/start_trial`);
afgomez marked this conversation as resolved.
Show resolved Hide resolved
setIsTrialAvailable(response);
setLoadState(TrialStatusLoadState.Ok);
} catch {
setLoadState(TrialStatusLoadState.Error);
afgomez marked this conversation as resolved.
Show resolved Hide resolved
}
}
fetchTrial();
}, [services.http]);

return {
loadState,
isTrialAvailable,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
LogAnalysisSetupStatusUnknownPrompt,
MissingResultsPrivilegesPrompt,
MissingSetupPrivilegesPrompt,
MlUnavailablePrompt,
SubscriptionSplashContent,
} from '../../../components/logging/log_analysis_setup';
import { SourceErrorPage } from '../../../components/source_error_page';
import { SourceLoadingPage } from '../../../components/source_loading_page';
Expand Down Expand Up @@ -50,7 +50,7 @@ export const LogEntryCategoriesPageContent = () => {
} else if (hasFailedLoadingSource) {
return <SourceErrorPage errorMessage={loadSourceFailureMessage ?? ''} retry={loadSource} />;
} else if (!hasLogAnalysisCapabilites) {
return <MlUnavailablePrompt />;
return <SubscriptionSplashContent />;
} else if (!hasLogAnalysisReadCapabilities) {
return <MissingResultsPrivilegesPrompt />;
} else if (setupStatus.type === 'initializing') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
LogAnalysisSetupStatusUnknownPrompt,
MissingResultsPrivilegesPrompt,
MissingSetupPrivilegesPrompt,
MlUnavailablePrompt,
SubscriptionSplashContent,
} from '../../../components/logging/log_analysis_setup';
import { SourceErrorPage } from '../../../components/source_error_page';
import { SourceLoadingPage } from '../../../components/source_loading_page';
Expand Down Expand Up @@ -50,7 +50,7 @@ export const LogEntryRatePageContent = () => {
} else if (hasFailedLoadingSource) {
return <SourceErrorPage errorMessage={loadSourceFailureMessage ?? ''} retry={loadSource} />;
} else if (!hasLogAnalysisCapabilites) {
return <MlUnavailablePrompt />;
return <SubscriptionSplashContent />;
} else if (!hasLogAnalysisReadCapabilities) {
return <MissingResultsPrivilegesPrompt />;
} else if (setupStatus.type === 'initializing') {
Expand Down
10 changes: 1 addition & 9 deletions x-pack/plugins/infra/public/pages/logs/page_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { HelpCenterContent } from '../../components/help_center_content';
import { AppNavigation } from '../../components/navigation/app_navigation';
import { RoutedTabs } from '../../components/navigation/routed_tabs';
import { ColumnarPage } from '../../components/page';
import { useLogAnalysisCapabilitiesContext } from '../../containers/logs/log_analysis';
import { useLogSourceContext } from '../../containers/logs/log_source';
import { RedirectWithQueryParams } from '../../utils/redirect_with_query_params';
import { LogEntryCategoriesPage } from './log_entry_categories';
Expand All @@ -28,7 +27,6 @@ import { AlertDropdown } from '../../components/alerting/logs/alert_dropdown';

export const LogsPageContent: React.FunctionComponent = () => {
const uiCapabilities = useKibana().services.application?.capabilities;
const logAnalysisCapabilities = useLogAnalysisCapabilitiesContext();

const { initialize } = useLogSourceContext();

Expand Down Expand Up @@ -77,13 +75,7 @@ export const LogsPageContent: React.FunctionComponent = () => {
<AppNavigation aria-label={pageTitle}>
<EuiFlexGroup gutterSize={'none'} alignItems={'center'}>
<EuiFlexItem>
<RoutedTabs
tabs={
logAnalysisCapabilities.hasLogAnalysisCapabilites
? [streamTab, logRateTab, logCategoriesTab, settingsTab]
: [streamTab, settingsTab]
}
/>
<RoutedTabs tabs={[streamTab, logRateTab, logCategoriesTab, settingsTab]} />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<AlertDropdown />
Expand Down