Skip to content

Commit

Permalink
[Upgrade Assistant] Add deprecation logging as step on overview page (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Mar 2, 2022
1 parent 7f364ea commit e43d345
Show file tree
Hide file tree
Showing 8 changed files with 425 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { act } from 'react-dom/test-utils';
import { DEPRECATION_LOGS_INDEX } from '../../../../common/constants';
import { setupEnvironment } from '../../helpers';
import { OverviewTestBed, setupOverviewPage } from '../overview.helpers';

describe('Overview - Logs Step', () => {
let testBed: OverviewTestBed;

const { server, httpRequestsMockHelpers } = setupEnvironment();

afterAll(() => {
server.restore();
});

describe('error state', () => {
beforeEach(async () => {
const error = {
statusCode: 500,
error: 'Internal server error',
message: 'Internal server error',
};

httpRequestsMockHelpers.setLoadDeprecationLogsCountResponse(undefined, error);

await act(async () => {
testBed = await setupOverviewPage();
});

testBed.component.update();
});

test('is rendered', () => {
const { exists } = testBed;
expect(exists('deprecationLogsErrorCallout')).toBe(true);
expect(exists('deprecationLogsRetryButton')).toBe(true);
});
});

describe('success state', () => {
describe('logging enabled', () => {
beforeEach(() => {
httpRequestsMockHelpers.setLoadDeprecationLoggingResponse({
isDeprecationLogIndexingEnabled: true,
isDeprecationLoggingEnabled: true,
});
});

test('renders step as complete when a user has 0 logs', async () => {
httpRequestsMockHelpers.setLoadDeprecationLogsCountResponse({
count: 0,
});

await act(async () => {
testBed = await setupOverviewPage();
});

const { component, exists } = testBed;

component.update();

expect(exists('logsStep-complete')).toBe(true);
});

test('renders step as incomplete when a user has >0 logs', async () => {
httpRequestsMockHelpers.setLoadDeprecationLogsCountResponse({
count: 10,
});

await act(async () => {
testBed = await setupOverviewPage();
});

const { component, exists } = testBed;

component.update();

expect(exists('logsStep-incomplete')).toBe(true);
});

test('renders deprecation issue count and button to view logs', async () => {
httpRequestsMockHelpers.setLoadDeprecationLogsCountResponse({
count: 10,
});

await act(async () => {
testBed = await setupOverviewPage();
});

const { component, find } = testBed;

component.update();

expect(find('logsCountDescription').text()).toContain('You have 10 deprecation issues');
expect(find('viewLogsLink').text()).toContain('View logs');
});
});

describe('logging disabled', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadDeprecationLoggingResponse({
isDeprecationLogIndexingEnabled: false,
isDeprecationLoggingEnabled: true,
});

await act(async () => {
testBed = await setupOverviewPage();
});

const { component } = testBed;

component.update();
});

test('renders button to enable logs', () => {
const { find, exists } = testBed;

expect(exists('logsCountDescription')).toBe(false);
expect(find('enableLogsLink').text()).toContain('Enable logging');
});
});
});

describe('privileges', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadDeprecationLoggingResponse({
isDeprecationLogIndexingEnabled: true,
isDeprecationLoggingEnabled: true,
});

await act(async () => {
testBed = await setupOverviewPage({
privileges: {
hasAllPrivileges: true,
missingPrivileges: {
index: [DEPRECATION_LOGS_INDEX],
},
},
});
});

const { component } = testBed;

component.update();
});

test('warns the user of missing index privileges', () => {
const { exists } = testBed;

expect(exists('missingPrivilegesCallout')).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export { FixDeprecationLogs } from './fix_deprecation_logs';
export { useDeprecationLogging } from './use_deprecation_logging';
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export { EsDeprecationLogs } from './es_deprecation_logs';
export { useDeprecationLogging } from './fix_deprecation_logs';
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

import React, { FunctionComponent, useState, useEffect } from 'react';

import { EuiText, EuiFlexItem, EuiFlexGroup, EuiSpacer, EuiLink } from '@elastic/eui';
import { EuiText, EuiFlexItem, EuiFlexGroup, EuiSpacer } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import type { EuiStepProps } from '@elastic/eui/src/components/steps/step';

import { DEPRECATION_LOGS_INDEX } from '../../../../../common/constants';
import { WithPrivileges } from '../../../../shared_imports';
import type { OverviewStepProps } from '../../types';
import { EsDeprecationIssuesPanel, KibanaDeprecationIssuesPanel } from './components';

Expand Down Expand Up @@ -51,48 +49,10 @@ const FixIssuesStep: FunctionComponent<Props> = ({ setIsComplete }) => {
);
};

interface CustomProps {
navigateToEsDeprecationLogs: () => void;
}

const AccessDeprecationLogsMessage = ({ navigateToEsDeprecationLogs }: CustomProps) => {
return (
<WithPrivileges privileges={`index.${DEPRECATION_LOGS_INDEX}`}>
{({ hasPrivileges, isLoading }) => {
if (isLoading || !hasPrivileges) {
// Don't show the message with the link to access deprecation logs
// to users who can't access the UI anyways.
return null;
}

return (
<FormattedMessage
id="xpack.upgradeAssistant.overview.accessEsDeprecationLogsLabel"
defaultMessage="If you have application code that calls Elasticsearch APIs, review the {esDeprecationLogsLink} to make sure you are not using deprecated APIs."
values={{
esDeprecationLogsLink: (
<EuiLink
onClick={navigateToEsDeprecationLogs}
data-test-subj="viewElasticsearchDeprecationLogs"
>
{i18n.translate('xpack.upgradeAssistant.overview.esDeprecationLogsLink', {
defaultMessage: 'Elasticsearch deprecation logs',
})}
</EuiLink>
),
}}
/>
);
}}
</WithPrivileges>
);
};

export const getFixIssuesStep = ({
isComplete,
setIsComplete,
navigateToEsDeprecationLogs,
}: OverviewStepProps & CustomProps): EuiStepProps => {
}: OverviewStepProps): EuiStepProps => {
const status = isComplete ? 'complete' : 'incomplete';

return {
Expand All @@ -105,14 +65,7 @@ export const getFixIssuesStep = ({
<p>
<FormattedMessage
id="xpack.upgradeAssistant.overview.fixIssuesStepDescription"
defaultMessage="You must resolve any critical Elasticsearch and Kibana configuration issues before upgrading to Elastic 8.x. Ignoring warnings might result in differences in behavior after you upgrade. {accessDeprecationLogsMessage}"
values={{
accessDeprecationLogsMessage: (
<AccessDeprecationLogsMessage
navigateToEsDeprecationLogs={navigateToEsDeprecationLogs}
/>
),
}}
defaultMessage="You must resolve any critical Elasticsearch and Kibana configuration issues before upgrading to Elastic 8.x. Ignoring warnings might result in differences in behavior after you upgrade."
/>
</p>
</EuiText>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export { getLogsStep } from './logs_step';
Loading

0 comments on commit e43d345

Please sign in to comment.