Skip to content

Commit

Permalink
[Monitoring] Add error state for unstructured logs (#53299) (#53338)
Browse files Browse the repository at this point in the history
* Add error state for unstructured logs

* Fix tests
  • Loading branch information
chrisronline authored Dec 18, 2019
1 parent 1dae172 commit 3b16d3a
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 7 deletions.

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

30 changes: 27 additions & 3 deletions x-pack/legacy/plugins/monitoring/public/components/logs/reason.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EuiCallOut, EuiLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links';
import { Monospace } from '../metricbeat_migration/instruction_steps/components/monospace/monospace';

export const Reason = ({ reason }) => {
let title = i18n.translate('xpack.monitoring.logs.reason.defaultTitle', {
Expand Down Expand Up @@ -91,6 +92,29 @@ export const Reason = ({ reason }) => {
}}
/>
);
} else if (false === reason.usingStructuredLogs) {
title = i18n.translate('xpack.monitoring.logs.reason.notUsingStructuredLogsTitle', {
defaultMessage: 'No structured logs found',
});
message = (
<FormattedMessage
id="xpack.monitoring.logs.reason.notUsingStructuredLogsMessage"
defaultMessage="Check if the {varPaths} setting {link}."
values={{
varPaths: <Monospace>var.paths</Monospace>,
link: (
<EuiLink
target="_blank"
href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-module-elasticsearch.html`}
>
{i18n.translate('xpack.monitoring.logs.reason.notUsingStructuredLogsLink', {
defaultMessage: 'points to JSON logs',
})}
</EuiLink>
),
}}
/>
);
} else if (false === reason.clusterExists) {
title = i18n.translate('xpack.monitoring.logs.reason.noClusterTitle', {
defaultMessage: 'No logs for this cluster',
Expand All @@ -103,7 +127,7 @@ export const Reason = ({ reason }) => {
link: (
<EuiLink
target="_blank"
href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}
href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-module-elasticsearch.html`}
>
{i18n.translate('xpack.monitoring.logs.reason.noClusterLink', {
defaultMessage: 'setup',
Expand All @@ -125,7 +149,7 @@ export const Reason = ({ reason }) => {
link: (
<EuiLink
target="_blank"
href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}
href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-module-elasticsearch.html`}
>
{i18n.translate('xpack.monitoring.logs.reason.noNodeLink', {
defaultMessage: 'setup',
Expand All @@ -147,7 +171,7 @@ export const Reason = ({ reason }) => {
link: (
<EuiLink
target="_blank"
href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-installation.html`}
href={`${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}/filebeat-module-elasticsearch.html`}
>
{i18n.translate('xpack.monitoring.logs.reason.noIndexLink', {
defaultMessage: 'setup',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ describe('Logs', () => {
expect(component).toMatchSnapshot();
});

it('should render with a no structured logs reason', () => {
const component = shallow(
<Reason reason={{ indexPatternExists: true, typeExists: true, usingStructuredLogs: false }} />
);
expect(component).toMatchSnapshot();
});

it('should render with a no cluster found reason', () => {
const component = shallow(
<Reason reason={{ indexPatternExists: true, typeExists: true, clusterExists: false }} />
Expand Down
13 changes: 13 additions & 0 deletions x-pack/legacy/plugins/monitoring/server/lib/logs/detect_reason.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async function doesFilebeatIndexExist(
const filter = [createTimeFilter({ start, end, metric })];

const typeFilter = { term: { 'service.type': 'elasticsearch' } };
const structuredLogsFilter = { exists: { field: 'elasticsearch.cluster' } };
const clusterFilter = { term: { 'elasticsearch.cluster.uuid': clusterUuid } };
const nodeFilter = { term: { 'elasticsearch.node.id': nodeUuid } };
const indexFilter = { term: { 'elasticsearch.index.name': indexUuid } };
Expand Down Expand Up @@ -44,6 +45,14 @@ async function doesFilebeatIndexExist(
},
};

const usingStructuredLogsQuery = {
query: {
bool: {
filter: [...filter, typeFilter, structuredLogsFilter],
},
},
};

const clusterExistsQuery = {
query: {
bool: {
Expand Down Expand Up @@ -81,6 +90,8 @@ async function doesFilebeatIndexExist(
{ ...defaultParams, ...typeExistsAtAnyTimeQuery },
{ index: filebeatIndexPattern },
{ ...defaultParams, ...typeExistsQuery },
{ index: filebeatIndexPattern },
{ ...defaultParams, ...usingStructuredLogsQuery },
];

if (clusterUuid) {
Expand All @@ -102,6 +113,7 @@ async function doesFilebeatIndexExist(
indexPatternExistsInTimeRangeResponse,
typeExistsAtAnyTimeResponse,
typeExistsResponse,
usingStructuredLogsResponse,
clusterExistsResponse,
nodeExistsResponse,
indexExistsResponse,
Expand All @@ -114,6 +126,7 @@ async function doesFilebeatIndexExist(
get(indexPatternExistsInTimeRangeResponse, 'hits.total.value', 0) > 0,
typeExistsAtAnyTime: get(typeExistsAtAnyTimeResponse, 'hits.total.value', 0) > 0,
typeExists: get(typeExistsResponse, 'hits.total.value', 0) > 0,
usingStructuredLogs: get(usingStructuredLogsResponse, 'hits.total.value', 0) > 0,
clusterExists: clusterUuid ? get(clusterExistsResponse, 'hits.total.value', 0) > 0 : null,
nodeExists: nodeUuid ? get(nodeExistsResponse, 'hits.total.value', 0) > 0 : null,
indexExists: indexUuid ? get(indexExistsResponse, 'hits.total.value', 0) > 0 : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"nodeExists": null,
"indexExists": null,
"typeExists": false,
"typeExistsAtAnyTime": false
"typeExistsAtAnyTime": false,
"usingStructuredLogs": false
},
"types": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"indexPatternExists": false,
"indexPatternInTimeRangeExists": false,
"typeExistsAtAnyTime": false,
"usingStructuredLogs": false,
"nodeExists": null,
"indexExists": false,
"typeExists": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"indexPatternExists": false,
"indexPatternInTimeRangeExists": false,
"typeExistsAtAnyTime": false,
"usingStructuredLogs": false,
"nodeExists": false,
"indexExists": null,
"typeExists": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5757,6 +5757,7 @@
"indexPatternExists": false,
"indexPatternInTimeRangeExists": false,
"typeExistsAtAnyTime": false,
"usingStructuredLogs": false,
"nodeExists": null,
"indexExists": null,
"typeExists": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"indexPatternExists": false,
"indexPatternInTimeRangeExists": false,
"typeExistsAtAnyTime": false,
"usingStructuredLogs": false,
"nodeExists": null,
"indexExists": null,
"typeExists": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"indexPatternExists": false,
"indexPatternInTimeRangeExists": false,
"typeExistsAtAnyTime": false,
"usingStructuredLogs": false,
"nodeExists": null,
"indexExists": null,
"typeExists": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"indexPatternExists": true,
"indexPatternInTimeRangeExists": true,
"typeExistsAtAnyTime": true,
"usingStructuredLogs": true,
"typeExists": true,
"clusterExists": false,
"nodeExists": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"indexPatternExists": false,
"indexPatternInTimeRangeExists": false,
"typeExistsAtAnyTime": false,
"usingStructuredLogs": false,
"nodeExists": null,
"indexExists": null,
"typeExists": false
Expand Down

0 comments on commit 3b16d3a

Please sign in to comment.