Skip to content

Commit

Permalink
[App Search] Add web crawler toggle to log retention settings view (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
byronhulcher authored Oct 15, 2021
1 parent fea50b3 commit 8280743
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import { AppLogic } from '../../../app_logic';
import { SETTINGS_PATH } from '../../../routes';
import { ANALYTICS_TITLE } from '../../analytics';
import { API_LOGS_TITLE } from '../../api_logs';
import { CRAWLER_TITLE } from '../../crawler';

import { LogRetentionLogic, LogRetentionOptions, renderLogRetentionDate } from '../index';

const TITLE_MAP = {
[LogRetentionOptions.Analytics]: ANALYTICS_TITLE,
[LogRetentionOptions.API]: API_LOGS_TITLE,
[LogRetentionOptions.Crawler]: CRAWLER_TITLE,
};

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ describe('LogRetentionLogic', () => {
enabled: true,
retention_policy: { is_default: true, min_age_days: 180 },
},
crawler: {
disabled_at: null,
enabled: true,
retention_policy: { is_default: true, min_age_days: 180 },
},
};

const TYPICAL_CLIENT_LOG_RETENTION = {
Expand All @@ -46,6 +51,11 @@ describe('LogRetentionLogic', () => {
enabled: true,
retentionPolicy: { isDefault: true, minAgeDays: 180 },
},
crawler: {
disabledAt: null,
enabled: true,
retentionPolicy: { isDefault: true, minAgeDays: 180 },
},
};

const DEFAULT_VALUES = {
Expand Down Expand Up @@ -146,6 +156,11 @@ describe('LogRetentionLogic', () => {
enabled: true,
retentionPolicy: null,
},
crawler: {
disabledAt: null,
enabled: true,
retentionPolicy: null,
},
});

expect(LogRetentionLogic.values).toEqual({
Expand All @@ -161,6 +176,11 @@ describe('LogRetentionLogic', () => {
enabled: true,
retentionPolicy: null,
},
crawler: {
disabledAt: null,
enabled: true,
retentionPolicy: null,
},
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ const CAPITALIZATION_MAP = {
{ defaultMessage: 'API' }
),
},
[LogRetentionOptions.Crawler]: {
capitalized: i18n.translate(
'xpack.enterpriseSearch.appSearch.logRetention.type.crawler.title.capitalized',
{ defaultMessage: 'Web crawler' }
),
lowercase: i18n.translate(
'xpack.enterpriseSearch.appSearch.logRetention.type.crawler.title.lowercase',
{ defaultMessage: 'web crawler' }
),
},
};

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
export enum LogRetentionOptions {
Analytics = 'analytics',
API = 'api',
Crawler = 'crawler',
}

export interface LogRetention {
[LogRetentionOptions.Analytics]: LogRetentionSettings;
[LogRetentionOptions.API]: LogRetentionSettings;
[LogRetentionOptions.Crawler]: LogRetentionSettings;
}

export interface LogRetentionPolicy {
Expand All @@ -29,6 +31,7 @@ export interface LogRetentionSettings {
export interface LogRetentionServer {
[LogRetentionOptions.Analytics]: LogRetentionServerSettings;
[LogRetentionOptions.API]: LogRetentionServerSettings;
[LogRetentionOptions.Crawler]: LogRetentionServerSettings;
}

export interface LogRetentionServerPolicy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ describe('convertLogRetentionFromServerToClient', () => {
enabled: true,
retention_policy: { is_default: true, min_age_days: 180 },
},
crawler: {
disabled_at: null,
enabled: true,
retention_policy: { is_default: true, min_age_days: 180 },
},
})
).toEqual({
analytics: {
Expand All @@ -33,6 +38,11 @@ describe('convertLogRetentionFromServerToClient', () => {
enabled: true,
retentionPolicy: { isDefault: true, minAgeDays: 180 },
},
crawler: {
disabledAt: null,
enabled: true,
retentionPolicy: { isDefault: true, minAgeDays: 180 },
},
});
});

Expand All @@ -49,6 +59,11 @@ describe('convertLogRetentionFromServerToClient', () => {
enabled: true,
retention_policy: { is_default: true, min_age_days: null },
},
crawler: {
disabled_at: null,
enabled: true,
retention_policy: { is_default: true, min_age_days: null },
},
})
).toEqual({
analytics: {
Expand All @@ -61,6 +76,11 @@ describe('convertLogRetentionFromServerToClient', () => {
enabled: true,
retentionPolicy: { isDefault: true, minAgeDays: null },
},
crawler: {
disabledAt: null,
enabled: true,
retentionPolicy: { isDefault: true, minAgeDays: null },
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const convertLogRetentionFromServerToClient = (
[LogRetentionOptions.API]: convertLogRetentionSettingsFromServerToClient(
logRetention[LogRetentionOptions.API]
),
[LogRetentionOptions.Crawler]: convertLogRetentionSettingsFromServerToClient(
logRetention[LogRetentionOptions.Crawler]
),
});

const convertLogRetentionSettingsFromServerToClient = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ describe('<LogRetentionConfirmationModal />', () => {
minAgeDays: 7,
},
},
crawler: {
enabled: true,
retentionPolicy: {
isDefault: true,
minAgeDays: 7,
},
},
},
};

Expand Down Expand Up @@ -128,4 +135,42 @@ describe('<LogRetentionConfirmationModal />', () => {
expect(actions.closeModals).toHaveBeenCalled();
});
});

describe('crawler', () => {
it('renders the Crawler panel when openedModal is set to Crawler', () => {
setMockValues({
...values,
openedModal: LogRetentionOptions.Crawler,
});

const logRetentionPanel = shallow(<LogRetentionConfirmationModal />);
expect(
logRetentionPanel.find('[data-test-subj="CrawlerLogRetentionConfirmationModal"]').length
).toBe(1);
});

it('calls saveLogRetention on save when showing crawler', () => {
setMockValues({
...values,
openedModal: LogRetentionOptions.Crawler,
});

const logRetentionPanel = shallow(<LogRetentionConfirmationModal />);
const genericConfirmationModal = logRetentionPanel.find(GenericConfirmationModal);
genericConfirmationModal.prop('onSave')();
expect(actions.saveLogRetention).toHaveBeenCalledWith(LogRetentionOptions.Crawler, false);
});

it('calls closeModals on close', () => {
setMockValues({
...values,
openedModal: LogRetentionOptions.Crawler,
});

const logRetentionPanel = shallow(<LogRetentionConfirmationModal />);
const genericConfirmationModal = logRetentionPanel.find(GenericConfirmationModal);
genericConfirmationModal.prop('onClose')();
expect(actions.closeModals).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,54 @@ export const LogRetentionConfirmationModal: React.FC = () => {
onSave={() => saveLogRetention(LogRetentionOptions.API, false)}
/>
)}

{openedModal === LogRetentionOptions.Crawler && (
<GenericConfirmationModal
data-test-subj="CrawlerLogRetentionConfirmationModal"
title={i18n.translate(
'xpack.enterpriseSearch.appSearch.settings.logRetention.modal.crawler.title',
{
defaultMessage: 'Disable Web Crawler writes',
}
)}
subheading={
logRetention &&
logRetention?.[LogRetentionOptions.Crawler].retentionPolicy?.minAgeDays &&
i18n.translate(
'xpack.enterpriseSearch.appSearch.settings.logRetention.modal.crawler.subheading',
{
defaultMessage:
'Your Web Crawler Logs are currently being stored for {minAgeDays} days.',
values: {
minAgeDays:
logRetention?.[LogRetentionOptions.Crawler].retentionPolicy?.minAgeDays,
},
}
)
}
description={
<>
<p>
{i18n.translate(
'xpack.enterpriseSearch.appSearch.settings.logRetention.modal.crawler.description',
{
defaultMessage:
'When you disable writing, engines stop logging Web Crawler events. Your existing data is deleted according to the storage time frame.',
}
)}
</p>
<p>
<strong>
<EuiTextColor color="danger">{CANNOT_BE_RECOVERED_TEXT}</EuiTextColor>
</strong>
</p>
</>
}
target={DISABLE_TEXT}
onClose={closeModals}
onSave={() => saveLogRetention(LogRetentionOptions.Crawler, false)}
/>
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('<LogRetentionPanel />', () => {
).toEqual(true);
});

it('enables both switches when isLogRetentionUpdating is false', () => {
it('enables all switches when isLogRetentionUpdating is false', () => {
setMockValues({
isLogRetentionUpdating: false,
logRetention: mockLogRetention({}),
Expand All @@ -113,9 +113,12 @@ describe('<LogRetentionPanel />', () => {
expect(
logRetentionPanel.find('[data-test-subj="LogRetentionPanelAPISwitch"]').prop('disabled')
).toEqual(false);
expect(
logRetentionPanel.find('[data-test-subj="LogRetentionPanelCrawlerSwitch"]').prop('disabled')
).toEqual(false);
});

it('disables both switches when isLogRetentionUpdating is true', () => {
it('disables all switches when isLogRetentionUpdating is true', () => {
setMockValues({
isLogRetentionUpdating: true,
logRetention: mockLogRetention({}),
Expand All @@ -128,6 +131,9 @@ describe('<LogRetentionPanel />', () => {
expect(
logRetentionPanel.find('[data-test-subj="LogRetentionPanelAPISwitch"]').prop('disabled')
).toEqual(true);
expect(
logRetentionPanel.find('[data-test-subj="LogRetentionPanelCrawlerSwitch"]').prop('disabled')
).toEqual(true);
});

it('calls toggleLogRetention when analytics log retention option is changed', () => {
Expand All @@ -150,7 +156,7 @@ describe('<LogRetentionPanel />', () => {
setMockValues({
isLogRetentionUpdating: false,
logRetention: mockLogRetention({
analytics: {
api: {
enabled: false,
},
}),
Expand All @@ -159,6 +165,20 @@ describe('<LogRetentionPanel />', () => {
logRetentionPanel.find('[data-test-subj="LogRetentionPanelAPISwitch"]').simulate('change');
expect(actions.toggleLogRetention).toHaveBeenCalledWith('api');
});

it('calls toggleLogRetention when crawler log retention option is changed', () => {
setMockValues({
isLogRetentionUpdating: false,
logRetention: mockLogRetention({
crawler: {
enabled: false,
},
}),
});
const logRetentionPanel = shallow(<LogRetentionPanel />);
logRetentionPanel.find('[data-test-subj="LogRetentionPanelCrawlerSwitch"]').simulate('change');
expect(actions.toggleLogRetention).toHaveBeenCalledWith('crawler');
});
});

const mockLogRetention = (logRetention: Partial<LogRetention>) => {
Expand All @@ -173,6 +193,11 @@ const mockLogRetention = (logRetention: Partial<LogRetention>) => {
enabled: true,
retentionPolicy: { isDefault: true, minAgeDays: 180 },
},
crawler: {
disabledAt: null,
enabled: true,
retentionPolicy: { isDefault: true, minAgeDays: 180 },
},
};

return {
Expand All @@ -184,5 +209,9 @@ const mockLogRetention = (logRetention: Partial<LogRetention>) => {
...baseLogRetention.api,
...logRetention.api,
},
crawler: {
...baseLogRetention.crawler,
...logRetention.crawler,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const LogRetentionPanel: React.FC = () => {
const hasILM = logRetention !== null;
const analyticsLogRetentionSettings = logRetention?.[LogRetentionOptions.Analytics];
const apiLogRetentionSettings = logRetention?.[LogRetentionOptions.API];
const crawlerLogRetentionSettings = logRetention?.[LogRetentionOptions.Crawler];

useEffect(() => {
fetchLogRetention();
Expand Down Expand Up @@ -100,6 +101,33 @@ export const LogRetentionPanel: React.FC = () => {
data-test-subj="LogRetentionPanelAPISwitch"
/>
</EuiText>
<EuiSpacer size="m" />
<EuiText>
<EuiSwitch
label={
<>
<strong>
{i18n.translate(
'xpack.enterpriseSearch.appSearch.settings.logRetention.crawler.label',
{
defaultMessage: 'Web Crawler Logs',
}
)}
</strong>
{': '}
{hasILM && (
<EuiTextColor color="subdued">
<LogRetentionMessage type={LogRetentionOptions.Crawler} />
</EuiTextColor>
)}
</>
}
checked={!!crawlerLogRetentionSettings?.enabled}
onChange={() => toggleLogRetention(LogRetentionOptions.Crawler)}
disabled={isLogRetentionUpdating}
data-test-subj="LogRetentionPanelCrawlerSwitch"
/>
</EuiText>
<EuiSpacer size="l" />
<EuiText size="xs" color="subdued">
<p>
Expand Down
Loading

0 comments on commit 8280743

Please sign in to comment.