-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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][Endpoint] Add step to the security solution plugin start
phase (non-blocking) to check endpoint policy indices
#198089
Merged
paul-tavares
merged 6 commits into
elastic:main
from
paul-tavares:task/olm-10840-create-dot-indices-on-start
Oct 30, 2024
+98
−15
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
56bd867
Add step during plugin start up (non-blocking) to check policy indices
paul-tavares 17cb490
Dedup index names in `createPolicyDataStreamsIfNecessary()`
paul-tavares 7f710ae
Unit tests
paul-tavares 736103d
Fix types in test
paul-tavares b50e495
Fix ESlint error
paul-tavares 96be4bc
Merge branch 'main' into task/olm-10840-create-dot-indices-on-start
paul-tavares 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
Loading status checks…
Unit tests
commit 7f710ae0c031a980c005ba640b11042069067324
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...s/security_solution/server/endpoint/migrations/ensure_indices_exists_for_policies.test.ts
This file contains 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,46 @@ | ||
/* | ||
* 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 { createMockEndpointAppContextService } from '../mocks'; | ||
import { ensureIndicesExistsForPolicies } from './ensure_indices_exists_for_policies'; | ||
import { createPolicyDataStreamsIfNeeded as _createPolicyDataStreamsIfNeeded } from '../../fleet_integration/handlers/create_policy_datastreams'; | ||
|
||
jest.mock('../../fleet_integration/handlers/create_policy_datastreams'); | ||
const createPolicyDataStreamsIfNeededMock = _createPolicyDataStreamsIfNeeded as jest.Mock; | ||
|
||
describe('Ensure indices exists for policies migration', () => { | ||
let endpointAppContextServicesMock: ReturnType<typeof createMockEndpointAppContextService>; | ||
|
||
beforeEach(() => { | ||
endpointAppContextServicesMock = createMockEndpointAppContextService(); | ||
|
||
endpointAppContextServicesMock | ||
.getInternalFleetServices() | ||
.packagePolicy.listIds.mockResolvedValue({ | ||
items: ['foo-1', 'foo-2', 'foo-3'], | ||
}); | ||
}); | ||
|
||
it('should query fleet looking for all endpoint integration policies', async () => { | ||
const fleetServicesMock = endpointAppContextServicesMock.getInternalFleetServices(); | ||
await ensureIndicesExistsForPolicies(endpointAppContextServicesMock); | ||
|
||
expect(fleetServicesMock.packagePolicy.listIds).toHaveBeenCalledWith(expect.anything(), { | ||
kuery: fleetServicesMock.endpointPolicyKuery, | ||
perPage: 10000, | ||
}); | ||
}); | ||
|
||
it('should call createPolicyDataStreamsIfNeeded() with list of existing policies', async () => { | ||
await ensureIndicesExistsForPolicies(endpointAppContextServicesMock); | ||
|
||
expect(createPolicyDataStreamsIfNeededMock).toHaveBeenCalledWith({ | ||
endpointServices: endpointAppContextServicesMock, | ||
endpointPolicyIds: ['foo-1', 'foo-2', 'foo-3'], | ||
}); | ||
}); | ||
}); |
This file contains 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.
What is the maximum number of items returned here? Might be a good idea to paginate if 100+.
Kibana runs on pretty low resources in some environments and might be doing other things at the same time.
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.
Thanks for 👀
The likelihood - especially for serverless - is that the returned count of items will be low. maybe a handful of policies.