-
Notifications
You must be signed in to change notification settings - Fork 8.6k
🌊 Streams: Prevent concurrent access #222961
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
9 commits
Select commit
Hold shift + click to select a range
5bc8430
add lock manager
flash1293 b518e57
Merge remote-tracking branch 'upstream/main' into flash1293/use-lock-…
flash1293 19e7b61
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine 5f0f7d3
Merge remote-tracking branch 'upstream/main' into flash1293/use-lock-…
flash1293 5be7810
move things where they belong
flash1293 2ea161c
Merge branch 'flash1293/use-lock-manager' of github.com:flash1293/kib…
flash1293 5f94e56
Merge branch 'main' into flash1293/use-lock-manager
klacabane bc7d62b
Merge branch 'main' into flash1293/use-lock-manager
flash1293 edbce3b
comments
flash1293 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
15 changes: 15 additions & 0 deletions
15
...gins/shared/streams/server/lib/streams/state_management/errors/concurrent_access_error.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,15 @@ | ||
| /* | ||
| * 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 { StatusError } from '../../errors/status_error'; | ||
|
|
||
| export class ConcurrentAccessError extends StatusError { | ||
| constructor(message: string) { | ||
| super(message, 409); | ||
| this.name = 'ConcurrentAccessError'; | ||
| } | ||
| } |
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
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
70 changes: 70 additions & 0 deletions
70
x-pack/test/api_integration/deployment_agnostic/apis/observability/streams/conflicts.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,70 @@ | ||
| /* | ||
| * 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 expect from '@kbn/expect'; | ||
| import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; | ||
| import { disableStreams, enableStreams, forkStream } from './helpers/requests'; | ||
| import { | ||
| StreamsSupertestRepositoryClient, | ||
| createStreamsRepositoryAdminClient, | ||
| } from './helpers/repository_client'; | ||
|
|
||
| export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { | ||
| const roleScopedSupertest = getService('roleScopedSupertest'); | ||
| let apiClient: StreamsSupertestRepositoryClient; | ||
|
|
||
| describe('conflict handling', function () { | ||
| before(async () => { | ||
| apiClient = await createStreamsRepositoryAdminClient(roleScopedSupertest); | ||
| await enableStreams(apiClient); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await disableStreams(apiClient); | ||
| }); | ||
|
|
||
| it('should not allow multiple requests manipulating streams state at once', async () => { | ||
| const stream1 = { | ||
| stream: { | ||
| name: 'logs.nginx', | ||
| }, | ||
| if: { | ||
| field: 'resource.attributes.host.name', | ||
| operator: 'eq' as const, | ||
| value: 'routeme', | ||
| }, | ||
| }; | ||
| const stream2 = { | ||
| stream: { | ||
| name: 'logs.apache', | ||
| }, | ||
| if: { | ||
| field: 'resource.attributes.host.name', | ||
| operator: 'eq' as const, | ||
| value: 'routeme2', | ||
| }, | ||
| }; | ||
| const responses = await Promise.allSettled([ | ||
| forkStream(apiClient, 'logs', stream1), | ||
| forkStream(apiClient, 'logs', stream2), | ||
| ]); | ||
| // Assert than one of the requests failed with a conflict error and the other succeeded | ||
| // It needs to check either way (success or failure) because the order of execution is not guaranteed | ||
| expect(responses).to.have.length(2); | ||
| const successResponse = responses.find( | ||
| (response) => response.status === 'fulfilled' && response.value.acknowledged | ||
| ); | ||
| const conflictResponse = responses.find( | ||
| (response) => | ||
| response.status === 'rejected' && | ||
| String(response.reason).toLowerCase().includes('conflict') | ||
| ); | ||
| expect(successResponse).to.not.be(undefined); | ||
| expect(conflictResponse).to.not.be(undefined); | ||
| }); | ||
| }); | ||
| } | ||
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
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.
forkshould be slow enough that we won't get flaky results on this ? perhaps to be safe we could trigger an even longer request, like a upsert that creates 2-3 child from root