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

[Alerting]: harden APIs of built-in alert index-threshold #60702

Merged
merged 3 commits into from
Mar 20, 2020

Conversation

pmuellr
Copy link
Member

@pmuellr pmuellr commented Mar 19, 2020

resolves #59889

The index threshold APIs - used by both the index threshold UI and the
alert executor - were returning errors (500's from http endpoints) when
getting errors from ES.

These have been changed so that the error is logged as a warning, and the
relevant API returns an "empty" result.

Another 500 response was found while experimenting with this. Apparently
the date_range agg requires a date format to be passed in if the date format
in ES is not the format sent in the date range values - in this case an ISO date.
The repro on this was to select the .security alias (or it's index) within the
index threshold alert UI, and then select one of it's date fields, which are
formatted as epoch_millis, not ISO.

Checklist

Delete any items that are not applicable to this PR.

@pmuellr pmuellr added Feature:Alerting v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.7.0 Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) labels Mar 19, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-alerting-services (Team:Alerting Services)

@pmuellr pmuellr force-pushed the alerting/it-index-pattern-500 branch from 389055e to 5130327 Compare March 20, 2020 00:49
resolves elastic#59889

The index threshold APIs - used by both the index threshold UI and the
alert executor - were returning errors (500's from http endpoints) when
getting errors from ES.

These have been changed so that the error is logged as a warning, and the
relevant API returns an "empty" result.

Another 500 response was found while experimenting with this.  Apparently
the date_range agg requires a date format to be passed in if the date format
in ES is not an ISO date.  The repro on this was to select the `.security`
alias (or it's index) within the index threshold alert UI, and then select
one of it's date fields.
@pmuellr pmuellr force-pushed the alerting/it-index-pattern-500 branch from 5130327 to 8e78f89 Compare March 20, 2020 05:29
@@ -94,6 +94,7 @@ export async function timeSeriesQuery(
dateAgg: {
date_range: {
field: timeField,
format: 'strict_date_time',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to indicate the format of the dates that we pass in as the date range values. Without it, an error will occur if the dates in the index are not in this format, eg epoch_millis.

@@ -134,8 +135,8 @@ export async function timeSeriesQuery(
esResult = await callCluster('search', esQuery);
} catch (err) {
// console.log('time_series_query.ts error\n', JSON.stringify(err, null, 4));
logger.warn(`${logPrefix} error: ${JSON.stringify(err.message)}`);
throw new Error('error running search');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of throwing an error, just return an empty result. Also improve the log message (doesn't need to be stringified).


let result: TimeSeriesResult;
try {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try/catch was removed, as we now catch the only directly throwable API (above), so anything else would be a JS runtime error.

@@ -53,6 +53,7 @@ async function createEsDocument(es: any, epochMillis: number, testedValue: numbe
source: DOCUMENT_SOURCE,
reference: DOCUMENT_REFERENCE,
date: new Date(epochMillis).toISOString(),
date_epoch_millis: epochMillis,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a new date field, but in epoch millis format, to test using it as a time field

@@ -139,6 +139,12 @@ export default function fieldsEndpointTests({ getService }: FtrProviderContext)
expect(field.name).to.eql('updated_at');
expect(field.type).to.eql('date');
});

// TODO: the pattern '*a:b,c:d*' throws an exception in dev, but not ci!
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit weird. Seems like FT is running ES in some mode where bad cluster names won't result in exceptions, but running yarn es will. If you enter the pattern above when running in dev (yarn es, yarn start), you'll see the exception logged in the console, but you don't see it in in FT.

@pmuellr pmuellr marked this pull request as ready for review March 20, 2020 12:53
@pmuellr pmuellr requested a review from a team as a code owner March 20, 2020 12:53
@mikecote mikecote self-requested a review March 20, 2020 13:33
Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@YulNaumenko YulNaumenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pmuellr
Copy link
Member Author

pmuellr commented Mar 20, 2020

@elasticmachine merge upstream

@pmuellr
Copy link
Member Author

pmuellr commented Mar 20, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@pmuellr pmuellr merged commit 5efd59b into elastic:master Mar 20, 2020
pmuellr added a commit to pmuellr/kibana that referenced this pull request Mar 20, 2020
)

resolves elastic#59889

The index threshold APIs - used by both the index threshold UI and the
alert executor - were returning errors (500's from http endpoints) when
getting errors from ES.

These have been changed so that the error is logged as a warning, and the
relevant API returns an "empty" result.

Another 500 response was found while experimenting with this.  Apparently
the date_range agg requires a date format to be passed in if the date format
in ES is not an ISO date.  The repro on this was to select the `.security`
alias (or it's index) within the index threshold alert UI, and then select
one of it's date fields.
pmuellr added a commit that referenced this pull request Mar 20, 2020
…60813)

resolves #59889

The index threshold APIs - used by both the index threshold UI and the
alert executor - were returning errors (500's from http endpoints) when
getting errors from ES.

These have been changed so that the error is logged as a warning, and the
relevant API returns an "empty" result.

Another 500 response was found while experimenting with this.  Apparently
the date_range agg requires a date format to be passed in if the date format
in ES is not an ISO date.  The repro on this was to select the `.security`
alias (or it's index) within the index threshold alert UI, and then select
one of it's date fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Alerting] indexThreshold /_indices API returns 500 for CCS index pattern
5 participants