-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] DetectionRulesClient
: move public methods out and add APM spans
#184820
[Security Solution] DetectionRulesClient
: move public methods out and add APM spans
#184820
Conversation
Pinging @elastic/security-solution (Team: SecuritySolution) |
Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management) |
DetectionRulesClient
: move public methods out and add APM spans
/ci |
...tion_engine/rule_management/logic/rule_management/delete_rule.rule_management_client.test.ts
Outdated
Show resolved
Hide resolved
/ci |
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: cc @nikitaindik |
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.
Reviewed the PR together with @nikitaindik over zoom, along with refactoring the client further. We'll open a follow-up one shortly. Thanks Nikita!
Partially addresses: #184364
Summary
This PR is second step in refactoring our newly added
detectionRulesClient
.Changes in this PR:
_createRule
,_updateRule
,_patchRule
and_upgradePrebuiltRuleWithTypeChange
private methods were removed, their code inlined into the public methodstoggleRuleEnabledOnUpdate
,validateMlAuth
andClientError
were moved toutils.ts
withSecuritySpan
to report perf stats to APM*.rules_management_client.test.ts
->*.detection_rules_client.test.ts
detectionRulesClient
in tests, not just separate methodscreateDetectionRulesClient
. Now 2 parameters are needed instead of 5,DetectionRulesClient method showing up in APM
Extracted methods
Upon reviewing the private methods in
detection_rules_client.ts
, it became apparent that extracting these methods into separate files may not be the most effective approach to improve readability. The primary reason is that these private methods do not provide clear abstractions, making them difficult to name appropriately.Take
_updateRule
as an example. This method combines an existing rule with a rule update to create an InternalRuleUpdate object, which is then passed torulesClient.update
. If we were to extract this into a separate file, we would need to import it for use in the publicupdateRule
method. This would result in anupdateRule
method that calls_updateRule
, creating confusion about what the inner_updateRule
does.Also, extracting only private methods does not significantly improve readability, as these methods do not contain a large amount of code.
So I ended up inlining the code from most of these private methods directly into the public methods.