From c611890ad22e2889940008cbb198e33ce53cd05b Mon Sep 17 00:00:00 2001
From: Chris Roberson
Date: Mon, 18 Nov 2019 15:36:37 -0500
Subject: [PATCH] Cherry-pick f92573ab5726d7a35c09b3f06d79dd8ee439b894 (#50926)
---
.../logs/__snapshots__/reason.test.js.snap | 34 ++++++++++++++++
.../public/components/logs/reason.js | 40 +++++++++++++++----
.../public/components/logs/reason.test.js | 8 ++++
.../lib/logs/detect_reason_from_exception.js | 17 ++++++++
.../server/lib/logs/get_log_types.js | 12 +++++-
.../monitoring/server/lib/logs/get_logs.js | 13 +++++-
6 files changed, 113 insertions(+), 11 deletions(-)
create mode 100644 x-pack/legacy/plugins/monitoring/server/lib/logs/detect_reason_from_exception.js
diff --git a/x-pack/legacy/plugins/monitoring/public/components/logs/__snapshots__/reason.test.js.snap b/x-pack/legacy/plugins/monitoring/public/components/logs/__snapshots__/reason.test.js.snap
index 59de46ad950e2..d65cba5f716bb 100644
--- a/x-pack/legacy/plugins/monitoring/public/components/logs/__snapshots__/reason.test.js.snap
+++ b/x-pack/legacy/plugins/monitoring/public/components/logs/__snapshots__/reason.test.js.snap
@@ -16,6 +16,7 @@ exports[`Logs should render a default message 1`] = `
"link":
`;
+exports[`Logs should render with a bad indices reason 1`] = `
+
+
+
+ Click here for more information
+
,
+ }
+ }
+ />
+
+
+`;
+
exports[`Logs should render with a no cluster found reason 1`] = `
setup
@@ -74,6 +104,7 @@ exports[`Logs should render with a no index found reason 1`] = `
"link":
setup
@@ -101,6 +132,7 @@ exports[`Logs should render with a no index pattern found reason 1`] = `
"link":
Filebeat
@@ -128,6 +160,7 @@ exports[`Logs should render with a no node found reason 1`] = `
"link":
setup
@@ -155,6 +188,7 @@ exports[`Logs should render with a no type found reason 1`] = `
"link":
these directions
diff --git a/x-pack/legacy/plugins/monitoring/public/components/logs/reason.js b/x-pack/legacy/plugins/monitoring/public/components/logs/reason.js
index a2acbe4ac3a58..7ce6744da5712 100644
--- a/x-pack/legacy/plugins/monitoring/public/components/logs/reason.js
+++ b/x-pack/legacy/plugins/monitoring/public/components/logs/reason.js
@@ -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: (
-
+
{
defaultMessage="Set up {link}, then configure your Elasticsearch output to your monitoring cluster."
values={{
link: (
-
+
{i18n.translate('xpack.monitoring.logs.reason.noIndexPatternLink', {
defaultMessage: 'Filebeat'
})}
@@ -75,7 +75,10 @@ export const Reason = ({ reason }) => {
defaultMessage="Follow {link} to set up Elasticsearch."
values={{
link: (
-
+
{i18n.translate('xpack.monitoring.logs.reason.noTypeLink', {
defaultMessage: 'these directions'
})}
@@ -95,7 +98,7 @@ export const Reason = ({ reason }) => {
defaultMessage="Check that your {link} is correct."
values={{
link: (
-
+
{i18n.translate('xpack.monitoring.logs.reason.noClusterLink', {
defaultMessage: 'setup'
})}
@@ -115,7 +118,7 @@ export const Reason = ({ reason }) => {
defaultMessage="Check that your {link} is correct."
values={{
link: (
-
+
{i18n.translate('xpack.monitoring.logs.reason.noNodeLink', {
defaultMessage: 'setup'
})}
@@ -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: (
-
- {i18n.translate('xpack.monitoring.logs.reason.noNodeLink', {
+
+ {i18n.translate('xpack.monitoring.logs.reason.noIndexLink', {
defaultMessage: 'setup'
})}
@@ -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 = (
+
+ {i18n.translate('xpack.monitoring.logs.reason.correctIndexNameLink', {
+ defaultMessage: 'Click here for more information'
+ })}
+
+ )
+ }}
+ />
+ );
+ }
return (
{
/>);
expect(component).toMatchSnapshot();
});
+
+ it('should render with a bad indices reason', () => {
+ const component = shallow();
+ expect(component).toMatchSnapshot();
+ });
});
diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logs/detect_reason_from_exception.js b/x-pack/legacy/plugins/monitoring/server/lib/logs/detect_reason_from_exception.js
new file mode 100644
index 0000000000000..02787191b7e66
--- /dev/null
+++ b/x-pack/legacy/plugins/monitoring/server/lib/logs/detect_reason_from_exception.js
@@ -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;
+}
diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logs/get_log_types.js b/x-pack/legacy/plugins/monitoring/server/lib/logs/get_log_types.js
index 2a16b0b89b5e8..606a50a3612ee 100644
--- a/x-pack/legacy/plugins/monitoring/server/lib/logs/get_log_types.js
+++ b/x-pack/legacy/plugins/monitoring/server/lib/logs/get_log_types.js
@@ -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 = {
@@ -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;
}
diff --git a/x-pack/legacy/plugins/monitoring/server/lib/logs/get_logs.js b/x-pack/legacy/plugins/monitoring/server/lib/logs/get_logs.js
index 0d45b8c6a1c4e..e9c36dd7295c9 100644
--- a/x-pack/legacy/plugins/monitoring/server/lib/logs/get_logs.js
+++ b/x-pack/legacy/plugins/monitoring/server/lib/logs/get_logs.js
@@ -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 = {
@@ -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,