-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Uptime] Redirect to error page when Heartbeat mappings are missing (#…
…110857) * Initial PoC of redirect on mapping error is working. * Update copy. Add comments. * Include headline element for page title. * Create mappings for failing functional tests. * Add functional test for mappings error page. * Add mapping for certs check.
- Loading branch information
1 parent
6235371
commit 26d19e7
Showing
13 changed files
with
272 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/uptime/public/hooks/use_mapping_check.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 { shouldRedirect } from './use_mapping_check'; | ||
|
||
describe('useMappingCheck', () => { | ||
describe('should redirect', () => { | ||
it('returns true for appropriate error', () => { | ||
const error = { | ||
request: {}, | ||
response: {}, | ||
body: { | ||
statusCode: 400, | ||
error: 'Bad Request', | ||
message: | ||
'[search_phase_execution_exception: [illegal_argument_exception] Reason: Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [monitor.id] in order to load field data by uninverting the inverted index. Note that this can use significant memory.]: all shards failed', | ||
}, | ||
name: 'Error', | ||
req: {}, | ||
res: {}, | ||
}; | ||
expect(shouldRedirect(error)).toBe(true); | ||
}); | ||
|
||
it('returns false for undefined', () => { | ||
expect(shouldRedirect(undefined)).toBe(false); | ||
}); | ||
|
||
it('returns false for missing body', () => { | ||
expect(shouldRedirect({})).toBe(false); | ||
}); | ||
|
||
it('returns false for incorrect error string', () => { | ||
expect(shouldRedirect({ body: { error: 'not the right type' } })).toBe(false); | ||
}); | ||
|
||
it('returns false for missing body message', () => { | ||
expect(shouldRedirect({ body: { error: 'Bad Request' } })).toBe(false); | ||
}); | ||
|
||
it('returns false for incorrect error message', () => { | ||
expect( | ||
shouldRedirect({ | ||
body: { error: 'Bad Request', message: 'Not the correct kind of error message' }, | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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 { useEffect } from 'react'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { MAPPING_ERROR_ROUTE } from '../../common/constants'; | ||
|
||
interface EsBadRequestError { | ||
body?: { | ||
error?: string; | ||
message?: string; | ||
}; | ||
} | ||
|
||
function contains(message: string, phrase: string) { | ||
return message.indexOf(phrase) !== -1; | ||
} | ||
|
||
export function shouldRedirect(error?: EsBadRequestError) { | ||
if (!error || !error.body || error.body.error !== 'Bad Request' || !error.body.message) { | ||
return false; | ||
} | ||
const { message } = error.body; | ||
return ( | ||
contains(message, 'search_phase_execution_exception') || | ||
contains(message, 'Please use a keyword field instead.') || | ||
contains(message, 'set fielddata=true') | ||
); | ||
} | ||
|
||
export function useMappingCheck(error?: EsBadRequestError) { | ||
const history = useHistory(); | ||
|
||
useEffect(() => { | ||
if (shouldRedirect(error)) { | ||
history.push(MAPPING_ERROR_ROUTE); | ||
} | ||
}, [error, history]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 { EuiCode, EuiEmptyPrompt, EuiLink, EuiTitle } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
||
import React from 'react'; | ||
|
||
import { useKibana } from '../../../../../src/plugins/kibana_react/public'; | ||
import { useBreadcrumbs } from '../hooks/use_breadcrumbs'; | ||
import { useTrackPageview } from '../../../observability/public'; | ||
|
||
export const MappingErrorPage = () => { | ||
useTrackPageview({ app: 'uptime', path: 'mapping-error' }); | ||
useTrackPageview({ app: 'uptime', path: 'mapping-error', delay: 15000 }); | ||
|
||
const docLinks = useKibana().services.docLinks; | ||
|
||
useBreadcrumbs([ | ||
{ | ||
text: i18n.translate('xpack.uptime.mappingErrorRoute.breadcrumb', { | ||
defaultMessage: 'Mapping error', | ||
}), | ||
}, | ||
]); | ||
|
||
return ( | ||
<EuiEmptyPrompt | ||
data-test-subj="xpack.uptime.mappingsErrorPage" | ||
iconColor="danger" | ||
iconType="cross" | ||
title={ | ||
<EuiTitle> | ||
<h3> | ||
<FormattedMessage | ||
id="xpack.uptime.public.pages.mappingError.title" | ||
defaultMessage="Heartbeat mappings missing" | ||
/> | ||
</h3> | ||
</EuiTitle> | ||
} | ||
body={ | ||
<div> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.uptime.public.pages.mappingError.bodyMessage" | ||
defaultMessage="Incorrect mappings detected! Perhaps you forgot to run the heartbeat {setup} command?" | ||
values={{ setup: <EuiCode>setup</EuiCode> }} | ||
/> | ||
</p> | ||
{docLinks && ( | ||
<p> | ||
<FormattedMessage | ||
id="xpack.uptime.public.pages.mappingError.bodyDocsLink" | ||
defaultMessage="You can learn how to troubleshoot this issue in the {docsLink}." | ||
values={{ | ||
docsLink: ( | ||
<EuiLink | ||
href={`${docLinks.ELASTIC_WEBSITE_URL}guide/en/observability/${docLinks.DOC_LINK_VERSION}/troubleshoot-uptime-mapping-issues.html`} | ||
target="_blank" | ||
> | ||
docs | ||
</EuiLink> | ||
), | ||
}} | ||
/> | ||
</p> | ||
)} | ||
</div> | ||
} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../ftr_provider_context'; | ||
import { makeCheck } from '../../../api_integration/apis/uptime/rest/helper/make_checks'; | ||
|
||
export default ({ getPageObjects, getService }: FtrProviderContext) => { | ||
const { common } = getPageObjects(['common']); | ||
const uptimeService = getService('uptime'); | ||
|
||
const es = getService('es'); | ||
describe('missing mappings', function () { | ||
before(async () => { | ||
await makeCheck({ es }); | ||
await common.navigateToApp('uptime'); | ||
}); | ||
|
||
it('redirects to mappings error page', async () => { | ||
await uptimeService.common.hasMappingsError(); | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.