Skip to content

Commit

Permalink
[Monitoring] Gracefully handle issue with filebeat indices (#48929) (#…
Browse files Browse the repository at this point in the history
…50924)

* Gracefully handle issue with filebeat indices

* Update translation keys

* Update link

* Add in default, per PR comment
  • Loading branch information
chrisronline authored Nov 18, 2019
1 parent 0a27e53 commit 3a476ec
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 11 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 33 additions & 7 deletions x-pack/legacy/plugins/monitoring/public/components/logs/reason.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Reason = ({ reason }) => {
defaultMessage="We did not find any log data and we are unable to diagnose why. {link}"
values={{
link: (
<EuiLink href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}>
<EuiLink target="_blank" href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}>
<FormattedMessage
id="xpack.monitoring.logs.reason.defaultMessageLink"
defaultMessage="Please verify your setup is correct."
Expand All @@ -44,7 +44,7 @@ export const Reason = ({ reason }) => {
defaultMessage="Set up {link}, then configure your Elasticsearch output to your monitoring cluster."
values={{
link: (
<EuiLink href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}>
<EuiLink target="_blank" href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}>
{i18n.translate('xpack.monitoring.logs.reason.noIndexPatternLink', {
defaultMessage: 'Filebeat'
})}
Expand Down Expand Up @@ -75,7 +75,10 @@ export const Reason = ({ reason }) => {
defaultMessage="Follow {link} to set up Elasticsearch."
values={{
link: (
<EuiLink href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-module-elasticsearch.html`}>
<EuiLink
target="_blank"
href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-module-elasticsearch.html`}
>
{i18n.translate('xpack.monitoring.logs.reason.noTypeLink', {
defaultMessage: 'these directions'
})}
Expand All @@ -95,7 +98,7 @@ export const Reason = ({ reason }) => {
defaultMessage="Check that your {link} is correct."
values={{
link: (
<EuiLink href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}>
<EuiLink target="_blank" href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}>
{i18n.translate('xpack.monitoring.logs.reason.noClusterLink', {
defaultMessage: 'setup'
})}
Expand All @@ -115,7 +118,7 @@ export const Reason = ({ reason }) => {
defaultMessage="Check that your {link} is correct."
values={{
link: (
<EuiLink href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}>
<EuiLink target="_blank" href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}>
{i18n.translate('xpack.monitoring.logs.reason.noNodeLink', {
defaultMessage: 'setup'
})}
Expand All @@ -135,8 +138,8 @@ export const Reason = ({ reason }) => {
defaultMessage="We found logs, but none for this index. If this problem continues, check that your {link} is correct."
values={{
link: (
<EuiLink href="https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-installation.html">
{i18n.translate('xpack.monitoring.logs.reason.noNodeLink', {
<EuiLink target="_blank" href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}>
{i18n.translate('xpack.monitoring.logs.reason.noIndexLink', {
defaultMessage: 'setup'
})}
</EuiLink>
Expand All @@ -145,6 +148,29 @@ export const Reason = ({ reason }) => {
/>
);
}
else if (false === reason.correctIndexName) {
title = i18n.translate('xpack.monitoring.logs.reason.correctIndexNameTitle', {
defaultMessage: 'Corrupted filebeat index'
});
message = (
<FormattedMessage
id="xpack.monitoring.logs.reason.correctIndexNameMessage"
defaultMessage="There is an issue reading from your filebeat indices. {link}."
values={{
link: (
<EuiLink
target="_blank"
href={`${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/monitor-troubleshooting.html`}
>
{i18n.translate('xpack.monitoring.logs.reason.correctIndexNameLink', {
defaultMessage: 'Click here for more information'
})}
</EuiLink>
)
}}
/>
);
}

return (
<EuiCallOut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,12 @@ describe('Logs', () => {
/>);
expect(component).toMatchSnapshot();
});

it('should render with a bad indices reason', () => {
const component = shallow(<Reason reason={{
correctIndexName: false
}}
/>);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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.
*/

export function detectReasonFromException(exception) {
const reason = { correctIndexName: true };

if (exception) {
if (exception.status === 400 && exception.message.indexOf('Fielddata is disabled on text fields by default') > -1) {
reason.correctIndexName = false;
}
}

return reason;
}
12 changes: 10 additions & 2 deletions x-pack/legacy/plugins/monitoring/server/lib/logs/get_log_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { get } from 'lodash';
import { checkParam } from '../error_missing_required';
import { createTimeFilter } from '../create_query';
import { detectReason } from './detect_reason';
import { detectReasonFromException } from './detect_reason_from_exception';

async function handleResponse(response, req, filebeatIndexPattern, opts) {
const result = {
Expand Down Expand Up @@ -88,6 +89,13 @@ export async function getLogTypes(req, filebeatIndexPattern, { clusterUuid, node
};

const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring');
const response = await callWithRequest(req, 'search', params);
return await handleResponse(response, req, filebeatIndexPattern, { clusterUuid, nodeUuid, indexUuid, start, end });
let result = {};
try {
const response = await callWithRequest(req, 'search', params);
result = await handleResponse(response, req, filebeatIndexPattern, { clusterUuid, nodeUuid, indexUuid, start, end });
}
catch (err) {
result.reason = detectReasonFromException(err);
}
return result;
}
13 changes: 11 additions & 2 deletions x-pack/legacy/plugins/monitoring/server/lib/logs/get_logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { createTimeFilter } from '../create_query';
import { detectReason } from './detect_reason';
import { formatUTCTimestampForTimezone } from '../format_timezone';
import { getTimezone } from '../get_timezone';
import { detectReasonFromException } from './detect_reason_from_exception';

async function handleResponse(response, req, filebeatIndexPattern, opts) {
const result = {
Expand Down Expand Up @@ -87,8 +88,16 @@ export async function getLogs(config, req, filebeatIndexPattern, { clusterUuid,
};

const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring');
const response = await callWithRequest(req, 'search', params);
const result = await handleResponse(response, req, filebeatIndexPattern, { clusterUuid, nodeUuid, indexUuid, start, end });

let result = {};
try {
const response = await callWithRequest(req, 'search', params);
result = await handleResponse(response, req, filebeatIndexPattern, { clusterUuid, nodeUuid, indexUuid, start, end });
}
catch (err) {
result.reason = detectReasonFromException(err);
}

return {
...result,
limit: params.size,
Expand Down

0 comments on commit 3a476ec

Please sign in to comment.