-
Notifications
You must be signed in to change notification settings - Fork 8.6k
ES|QL support for partial results #223198
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bc214de
Handle cluster failures for ES|QL
nkhristinin a990db4
[Security Solution][Detection Engine] adds support of ES|QL partial r…
vitaliidm 1a4a457
Fix tests
nkhristinin 4fc2933
Merge branch 'main' into esql-partial
elasticmachine 17aa511
Update translations
nkhristinin cece2ab
Merge branch 'esql-partial' of github.com:nkhristinin/kibana into esq…
nkhristinin e3b2ba1
fix message in tests
nkhristinin 39eb84a
Merge branch 'main' into esql-partial
elasticmachine d81d8ef
Merge branch 'main' into esql-partial
nkhristinin 76ad982
fix the merge conflicts
nkhristinin 669f8bc
Add some tests assertions
nkhristinin 3b7058a
fix test title
nkhristinin e3883a8
Fix tests
nkhristinin 6245234
fix tests
nkhristinin f6890ea
Add assertion for 0 alert
nkhristinin 8d40f20
Add comment that allow_partial is deafult true
nkhristinin 80602c6
don't mutate acc
nkhristinin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...tion/server/lib/detection_engine/rule_types/utils/log_cluster_shard_failures_esql.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| import type { EsqlEsqlShardFailure } from '@elastic/elasticsearch/lib/api/types'; | ||
| import type { EsqlTable } from '../esql/esql_request'; | ||
| import type { SearchAfterAndBulkCreateReturnType } from '../types'; | ||
| import { logClusterShardFailuresEsql } from './log_cluster_shard_failures_esql'; | ||
|
|
||
| describe('logClusterShardFailuresEsql', () => { | ||
| let mockResult: SearchAfterAndBulkCreateReturnType; | ||
|
|
||
| beforeEach(() => { | ||
| mockResult = { | ||
| warningMessages: [], | ||
| bulkCreateTimes: [], | ||
| createdSignalsCount: 0, | ||
| createdSignals: [], | ||
| errors: [], | ||
| searchAfterTimes: [], | ||
| success: true, | ||
| warning: false, | ||
| enrichmentTimes: [], | ||
| }; | ||
| }); | ||
|
|
||
| it('should not add warning message when no shard failures exist', () => { | ||
| const response: EsqlTable = { | ||
| columns: [], | ||
| values: [], | ||
| _clusters: { | ||
| details: {}, | ||
| }, | ||
| }; | ||
|
|
||
| logClusterShardFailuresEsql({ response, result: mockResult }); | ||
| expect(mockResult.warningMessages).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('should add warning message when shard failures exist in a single cluster', () => { | ||
| const shardFailure: EsqlEsqlShardFailure = { | ||
| reason: { type: 'test_failure', reason: 'test failure' }, | ||
| shard: '0', | ||
| index: 'test-index', | ||
| }; | ||
|
|
||
| const response: EsqlTable = { | ||
| columns: [], | ||
| values: [], | ||
| _clusters: { | ||
| details: { | ||
| 'cluster-1': { | ||
| failures: [shardFailure], | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| logClusterShardFailuresEsql({ response, result: mockResult }); | ||
| expect(mockResult.warningMessages).toHaveLength(1); | ||
| expect(mockResult.warningMessages[0]).toBe( | ||
| `The ES|QL event query was only executed on the available shards. The query failed to run successfully on the following shards: ${JSON.stringify( | ||
| [shardFailure] | ||
| )}` | ||
| ); | ||
| }); | ||
|
|
||
| it('should add warning message when shard failures exist in multiple clusters', () => { | ||
| const shardFailure1: EsqlEsqlShardFailure = { | ||
| reason: { type: 'test_failure_1', reason: 'test failure 1' }, | ||
| shard: '0', | ||
| index: 'test-index-1', | ||
| }; | ||
|
|
||
| const shardFailure2: EsqlEsqlShardFailure = { | ||
| reason: { type: 'test_failure_2', reason: 'test failure 2' }, | ||
| shard: '1', | ||
| index: 'test-index-2', | ||
| }; | ||
|
|
||
| const response: EsqlTable = { | ||
| columns: [], | ||
| values: [], | ||
| _clusters: { | ||
| details: { | ||
| 'cluster-1': { | ||
| failures: [shardFailure1], | ||
| }, | ||
| 'cluster-2': { | ||
| failures: [shardFailure2], | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| logClusterShardFailuresEsql({ response, result: mockResult }); | ||
| expect(mockResult.warningMessages).toHaveLength(1); | ||
| expect(mockResult.warningMessages[0]).toBe( | ||
| `The ES|QL event query was only executed on the available shards. The query failed to run successfully on the following shards: ${JSON.stringify( | ||
| [shardFailure1, shardFailure2] | ||
| )}` | ||
| ); | ||
| }); | ||
|
|
||
| it('should handle undefined _clusters property', () => { | ||
| const response: EsqlTable = { | ||
| columns: [], | ||
| values: [], | ||
| }; | ||
|
|
||
| logClusterShardFailuresEsql({ response, result: mockResult }); | ||
| expect(mockResult.warningMessages).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('should handle undefined details property', () => { | ||
| const response: EsqlTable = { | ||
| columns: [], | ||
| values: [], | ||
| _clusters: {}, | ||
| }; | ||
|
|
||
| logClusterShardFailuresEsql({ response, result: mockResult }); | ||
| expect(mockResult.warningMessages).toHaveLength(0); | ||
| }); | ||
| }); |
33 changes: 33 additions & 0 deletions
33
..._solution/server/lib/detection_engine/rule_types/utils/log_cluster_shard_failures_esql.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| import type { EsqlEsqlShardFailure } from '@elastic/elasticsearch/lib/api/types'; | ||
| import type { EsqlTable } from '../esql/esql_request'; | ||
| import * as i18n from '../translations'; | ||
| import type { SearchAfterAndBulkCreateReturnType } from '../types'; | ||
|
|
||
| export const logClusterShardFailuresEsql = ({ | ||
| response, | ||
| result, | ||
| }: { | ||
| response: EsqlTable; | ||
| result: SearchAfterAndBulkCreateReturnType; | ||
| }) => { | ||
| const clusters = response?._clusters?.details ?? {}; | ||
| const shardFailures = Object.keys(clusters).reduce<EsqlEsqlShardFailure[]>((acc, cluster) => { | ||
| const failures = clusters[cluster]?.failures ?? []; | ||
|
|
||
| if (failures.length > 0) { | ||
| acc.push(...failures); | ||
| } | ||
|
|
||
| return acc; | ||
| }, []); | ||
|
|
||
| if (shardFailures.length > 0) { | ||
| result.warningMessages.push(i18n.ESQL_SHARD_FAILURE_MESSAGE(JSON.stringify(shardFailures))); | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,8 @@ import { | |
| waitForBackfillExecuted, | ||
| setAdvancedSettings, | ||
| getOpenAlerts, | ||
| setBrokenRuntimeField, | ||
| unsetBrokenRuntimeField, | ||
| } from '../../../../utils'; | ||
| import { | ||
| deleteAllRules, | ||
|
|
@@ -42,6 +44,7 @@ import { | |
| } from '../../../../../../../common/utils/security_solution'; | ||
| import { deleteAllExceptions } from '../../../../../lists_and_exception_lists/utils'; | ||
| import { FtrProviderContext } from '../../../../../../ftr_provider_context'; | ||
| import { EsArchivePathBuilder } from '../../../../../../es_archive_path_builder'; | ||
|
|
||
| export default ({ getService }: FtrProviderContext) => { | ||
| const supertest = getService('supertest'); | ||
|
|
@@ -2186,6 +2189,85 @@ export default ({ getService }: FtrProviderContext) => { | |
| }); | ||
| }); | ||
|
|
||
| describe('shard failures', () => { | ||
| const config = getService('config'); | ||
| const isServerless = config.get('serverless'); | ||
| const dataPathBuilder = new EsArchivePathBuilder(isServerless); | ||
| const packetBeatPath = dataPathBuilder.getPath('packetbeat/default'); | ||
|
|
||
| before(async () => { | ||
| await esArchiver.load(packetBeatPath); | ||
| await setBrokenRuntimeField({ es, index: 'packetbeat-*' }); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await unsetBrokenRuntimeField({ es, index: 'packetbeat-*' }); | ||
| await esArchiver.unload(packetBeatPath); | ||
| }); | ||
|
|
||
| it('should handle shard failures and include warning in logs for query that is not aggregating', async () => { | ||
| const doc1 = { agent: { name: 'test-1' } }; | ||
| await indexEnhancedDocuments({ | ||
| documents: [doc1], | ||
| id: uuidv4(), | ||
| }); | ||
|
|
||
| const rule: EsqlRuleCreateProps = { | ||
| ...getCreateEsqlRulesSchemaMock('rule-1', true), | ||
| query: `from packetbeat-*, ecs_compliant METADATA _id | limit 101`, | ||
| from: 'now-100000h', | ||
| }; | ||
|
|
||
| const { logs, previewId } = await previewRule({ | ||
| supertest, | ||
| rule, | ||
| }); | ||
|
|
||
| const previewAlerts = await getPreviewAlerts({ es, previewId }); | ||
|
|
||
| expect(logs).toEqual( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add assertion that rule still creates alerts from available shards?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| warnings: expect.arrayContaining([ | ||
| expect.stringContaining( | ||
| 'The ES|QL event query was only executed on the available shards. The query failed to run successfully on the following shards' | ||
| ), | ||
| ]), | ||
| }), | ||
| ]) | ||
| ); | ||
|
|
||
| expect(previewAlerts?.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('should handle shard failures and include errors in logs for query that is aggregating', async () => { | ||
| const rule: EsqlRuleCreateProps = { | ||
| ...getCreateEsqlRulesSchemaMock(), | ||
| query: `from packetbeat-* | stats _count=count(broken) by @timestamp`, | ||
| from: 'now-100000h', | ||
| }; | ||
|
|
||
| const { logs, previewId } = await previewRule({ | ||
| supertest, | ||
| rule, | ||
| }); | ||
|
|
||
| const previewAlerts = await getPreviewAlerts({ es, previewId }); | ||
|
|
||
| expect(logs).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| errors: expect.arrayContaining([ | ||
| expect.stringContaining('No field found for [non_existing] in mapping'), | ||
| ]), | ||
| }), | ||
| ]) | ||
| ); | ||
|
|
||
| expect(previewAlerts).toHaveLength(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('alerts on alerts', () => { | ||
| let id: string; | ||
| let ruleId: string; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment here just stating
allow_partial_resultsdefaults to true? I like to have it documented in-line.Ref: elastic/elasticsearch#122802