Refactor Index Sync Logic and Improve Component Test Coverage#225783
Refactor Index Sync Logic and Improve Component Test Coverage#225783CAWilson94 wants to merge 16 commits intoelastic:mainfrom
Conversation
…rations; helper functions for testing; formatting
x-pack/test_serverless/api_integration/test_suites/security/platform_security/authorization.ts
Show resolved
Hide resolved
|
🤖 Jobs for this PR can be triggered through checkboxes. 🚧
ℹ️ To trigger the CI, please tick the checkbox below 👇
|
| * 2.0. | ||
| */ | ||
|
|
||
| describe('Privilege Monitoring API Key Manager', () => { |
💔 Build Failed
Failed CI StepsTest Failures
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History |
| source: MonitoringEntitySourceDescriptor, | ||
| index: string |
There was a problem hiding this comment.
Why does it receive two params if index is already inside source?
There was a problem hiding this comment.
May be a leftover from a previous iteration, good spot. I don't see a reason to have them separate. Will update this 🫡
There was a problem hiding this comment.
Oh no, I see why now. I was trying to reduce the checks inside the ingestUsersFromIndexSource method so it can always assume it receives a valid index. If I used source.indexPattern directly in that method, I’d have to move the source.indexPattern === undefined check into it.
I felt it was a bit cleaner and easier to follow with that validation staying in plainIndexSync, since it keeps the top-level flow clear.
My usual preference is to push validation down to the lowest-level method so that ingestUsersFromIndexSource would be more self-contained and flexible for future reuse — but in this case, keeping it in the top-level method just felt simpler.
Let me know if you’d prefer the check moved down into ingestUsersFromIndexSource — happy to refactor if that feels more consistent!
| */ | ||
|
|
||
| export type PrivMonUserSource = 'csv' | 'api' | 'index_sync'; | ||
| export type SyncIntervalConfig = EntityAnalyticsConfig['monitoring']['privileges']['syncInterval']; |
There was a problem hiding this comment.
should be monitoring -> privileges -> developer -> syncInterval
|
|
||
| const query = kuery ? toElasticsearchQuery(fromKueryExpression(kuery)) : { match_all: {} }; | ||
|
|
||
| while (true) { |
There was a problem hiding this comment.
instead of while true, needs to be more readable. Could rename this to something like 'hits' but look for where we do composite in risk scoring @hop-dev
This pull request refactors the
PrivilegeMonitoringDataClientclass to improve code clarity and modularity in line with this issue: #225551🚧 Add testing for new types and functionalities from API Key and Sync Task merging.
How To Test
For testing steps, please see the steps on the API and Sync Task PR: #225551