Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Monitoring] Add error state for unstructured logs #53299

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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