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

[Security Solution][Detection Engine] Bubbles up more error messages from ES queries to the UI #78004

Merged

Conversation

FrankHassanabad
Copy link
Contributor

@FrankHassanabad FrankHassanabad commented Sep 21, 2020

Summary

Fixes: #77254

Bubbles up error messages from ES queries that have _shards.failures in them. For example if you have errors in your exceptions list you will need to see them bubbled up.

Steps to reproduce:
Go to a detections rule and add an invalid value within the exceptions such as this one below:
Screen Shot 2020-09-21 at 7 52 59 AM

Notice that rsa.internal.level value is not a numeric but a text string. You should now see this error message where before you could not:
Screen Shot 2020-09-21 at 7 52 44 AM

Checklist

@FrankHassanabad FrankHassanabad marked this pull request as ready for review September 21, 2020 20:24
@FrankHassanabad FrankHassanabad changed the title Bubbles up error messages from ES queries to the front end [Security Solution][Detection Engine] Bubbles up error messages from ES queries to the UI Sep 21, 2020
@FrankHassanabad FrankHassanabad changed the title [Security Solution][Detection Engine] Bubbles up error messages from ES queries to the UI [Security Solution][Detection Engine] Bubbles up more error messages from ES queries to the UI Sep 21, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@FrankHassanabad FrankHassanabad added the Feature:Detection Rules Anything related to Security Solution's Detection Rules label Sep 21, 2020
Copy link
Contributor

@dhurley14 dhurley14 left a comment

Choose a reason for hiding this comment

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

LGTM! Accumulating these failures will help us out a lot going forward with users debugging issues and bringing some "self - service" to the detection engine. Also, thanks for cleaning up the code with those merge functions!

Copy link
Contributor

@rylnd rylnd left a comment

Choose a reason for hiding this comment

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

Desk tested and saw these lovely new errors! :shipit:

I had a suggestion for a minor refactor that might clean things up and obviate some of the test permutations, but feel free to take it or leave it!

success: boolean;
searchAfterTimes: string[];
bulkCreateTimes: string[];
lastLookBackDate: Date | null | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the semantic distinction between null and undefined for this value? Looking at the implementation of createSearchAfterReturnType it seems like it'll never be undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a bit weird. It sometimes can be undefined if it has never been set before. I think we used null as setting it for another type of value. But yeah, it can be either of those three states.

logger.debug(buildRuleMessage(`created ${createdCount} signals`));
toReturn.createdSignalsCount += createdCount;
toReturn = mergeSearchAfterAndBulkCreate({
prev: toReturn,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the prev and next arguments are a little odd to me, I would expect this kind of function to instead operate on a uniform array, e.g. (A[]) => A

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that's interesting. An ordered array. That's a good idea. I can try to add that and see if it makes sense and then commit it if it does.

Comment on lines 508 to 514
const searchReturn = createSearchAfterReturnType({
success: searchResult._shards.failed === 0,
lastLookBackDate:
searchResult.hits.hits.length > 0
? new Date(searchResult.hits.hits[searchResult.hits.hits.length - 1]?._source['@timestamp'])
: undefined,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const searchReturn = createSearchAfterReturnType({
success: searchResult._shards.failed === 0,
lastLookBackDate:
searchResult.hits.hits.length > 0
? new Date(searchResult.hits.hits[searchResult.hits.hits.length - 1]?._source['@timestamp'])
: undefined,
});
const searchReturn = createSearchAfterReturnTypeFromResponse(searchResult);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha! Thank you. Pure 🥇 gold here. Appreciate the eyes. Will fix.

? new Date(searchResult.hits.hits[searchResult.hits.hits.length - 1]?._source['@timestamp'])
: undefined,
});
const partialMerge = mergeSearchAfterAndBulkCreate({
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a suggestion to normalize these merging functions, but I realize it might cause a bunch of churn so feel free to ignore it. The basic idea is to decompose into the following functions:

  • function to merge two SearchAfterAndBulkCreateReturnTypes into one (e.g.(a: A, b: A) => A)
  • function to reduce n SearchAfterAndBulkCreateReturnTypes via the above function, using createSearchAfterReturnType() as the starting value

That would eliminate the need for these prev/next parameters and the partialMerge stuff. Again, just a suggestion, take it or leave it!

Comment on lines 93 to 100
toReturn = mergeSearchAfterReturnTypeFromResponse({
searchResult,
searchDuration,
}: { searchResult: SignalSearchResponse; searchDuration: string } = await singleSearchAfter(
{
searchAfterSortId: sortId,
index: inputIndexPattern,
from: tuple.from.toISOString(),
to: tuple.to.toISOString(),
services,
logger,
filter,
pageSize: tuple.maxSignals < pageSize ? Math.ceil(tuple.maxSignals) : pageSize, // maximum number of docs to receive per search result.
timestampOverride: ruleParams.timestampOverride,
}
);
toReturn.searchAfterTimes.push(searchDuration);
prev: toReturn,
next: createSearchAfterReturnType({
searchAfterTimes: [searchDuration],
errors: searchErrors,
}),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

With those suggested changes this could be:

toReturn = mergeReturns([
  toReturn,
  createSearchAfterReturnFromResponse(searchResult),
  createSearchAfterReturnType(),
]);

Copy link
Contributor Author

@FrankHassanabad FrankHassanabad Sep 22, 2020

Choose a reason for hiding this comment

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

I think with the changes where I was able to utilize an N array of items for the merge which respect the order I was able to do this:

        toReturn = mergeReturns([
          toReturn,
          createSearchAfterReturnTypeFromResponse({ searchResult }),
          createSearchAfterReturnType({
            searchAfterTimes: [searchDuration],
            errors: searchErrors,
          }),
        ]);

And then remove that specific function. So I think this is all cleaning up nicely. I will update and make sure all the unit tests work and then re-do the ad-hoc tests again and push this all up.

Really really appreciate the thoughts you give to the API's in these places. Really makes things a lot better.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

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

@FrankHassanabad FrankHassanabad merged commit d79fbb3 into elastic:master Sep 23, 2020
@FrankHassanabad FrankHassanabad deleted the bubble-up-errors-from-query branch September 23, 2020 01:19
FrankHassanabad added a commit to FrankHassanabad/kibana that referenced this pull request Sep 23, 2020
…from ES queries to the UI (elastic#78004)

## Summary

Fixes: elastic#77254

Bubbles up error messages from ES queries that have _shards.failures in them. For example if you have errors in your exceptions list you will need to see them bubbled up.

Steps to reproduce:
Go to a detections rule and add an invalid value within the exceptions such as this one below:
<img width="1523" alt="Screen Shot 2020-09-21 at 7 52 59 AM" src="https://user-images.githubusercontent.com/1151048/93817197-d1a53780-fc15-11ea-8cf2-4dd7fd5a3c13.png">

Notice that rsa.internal.level value is not a numeric but a text string. You should now see this error message where before you could not:
<img width="1503" alt="Screen Shot 2020-09-21 at 7 52 44 AM" src="https://user-images.githubusercontent.com/1151048/93817231-e1bd1700-fc15-11ea-9038-99668233191a.png">

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
gmmorris added a commit to gmmorris/kibana that referenced this pull request Sep 23, 2020
* master: (31 commits)
  skip tests for old pacakge (elastic#78194)
  [Ingest Pipelines] Add url generator for ingest pipelines app (elastic#77872)
  [Lens] Rename "telemetry" to "stats" (elastic#78125)
  [CSM] Url search (elastic#77516)
  [Drilldowns] Config to disable URL Drilldown  (elastic#77887)
  [Lens] Combined histogram/range aggregation for numbers (elastic#76121)
  Remove legacy plugins support (elastic#77599)
  'Auto' interval must be correctly calculated for natural numbers (elastic#77995)
  [CSM] fix ingest data retry order messed up (elastic#78163)
  Add response status helpers (elastic#78006)
  Bump react-beautiful-dnd (elastic#78028)
  [Security Solution][Detection Engine] Bubbles up more error messages from ES queries to the UI (elastic#78004)
  Index pattern  - refactor constructor (elastic#77791)
  Add `xpack.security.sameSiteCookies` to docker allow list (elastic#78192)
  Remove [key: string]: any; from IIndexPattern (elastic#77968)
  Remove requirement for manage_index_templates privilege for Index Management (elastic#77377)
  [Ingest Manager] Agent bulk actions UI (elastic#77690)
  [Metrics UI] Add inventory view timeline (elastic#77804)
  Reporting/Docs: Updates for setting to enable CSV Download (elastic#78101)
  Update to latest rum-react (elastic#78193)
  ...
FrankHassanabad added a commit that referenced this pull request Sep 23, 2020
…from ES queries to the UI (#78004) (#78244)

## Summary

Fixes: #77254

Bubbles up error messages from ES queries that have _shards.failures in them. For example if you have errors in your exceptions list you will need to see them bubbled up.

Steps to reproduce:
Go to a detections rule and add an invalid value within the exceptions such as this one below:
<img width="1523" alt="Screen Shot 2020-09-21 at 7 52 59 AM" src="https://user-images.githubusercontent.com/1151048/93817197-d1a53780-fc15-11ea-8cf2-4dd7fd5a3c13.png">

Notice that rsa.internal.level value is not a numeric but a text string. You should now see this error message where before you could not:
<img width="1503" alt="Screen Shot 2020-09-21 at 7 52 44 AM" src="https://user-images.githubusercontent.com/1151048/93817231-e1bd1700-fc15-11ea-9038-99668233191a.png">

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
@MindyRS MindyRS added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Sep 23, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Detection Rules Anything related to Security Solution's Detection Rules release_note:fix Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:SIEM v7.10.0 v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution][Detection Engine] Errors from rule querying are not being populated in the UI
6 participants