Skip to content
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

Add rule validation in AnomalyDetector constructor #1341

Merged
merged 2 commits into from
Oct 18, 2024

Conversation

kaituo
Copy link
Collaborator

@kaituo kaituo commented Oct 18, 2024

Description

This commit introduces rule validation within the AnomalyDetector constructor. Any validation errors are now propagated and displayed on the frontend to ensure immediate feedback.

Testing:

  • Verified that validation errors are properly propagated and shown on the frontend.
  • Added UTs to cover the new validation logic.

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

This commit introduces rule validation within the AnomalyDetector constructor. Any validation errors are now propagated and displayed on the frontend to ensure immediate feedback.

Testing:
* Verified that validation errors are properly propagated and shown on the frontend.
* Added UTs to cover the new validation logic.

Signed-off-by: Kaituo Li <[email protected]>
Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 94.54545% with 3 lines in your changes missing coverage. Please review.

Project coverage is 80.08%. Comparing base (2ab6dc7) to head (fa55f65).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
.../java/org/opensearch/ad/model/AnomalyDetector.java 95.91% 0 Missing and 2 partials ⚠️
...imeseries/transport/SuggestConfigParamRequest.java 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1341      +/-   ##
============================================
+ Coverage     79.68%   80.08%   +0.39%     
- Complexity     5630     5675      +45     
============================================
  Files           533      533              
  Lines         23410    23429      +19     
  Branches       2323     2335      +12     
============================================
+ Hits          18654    18762     +108     
+ Misses         3651     3563      -88     
+ Partials       1105     1104       -1     
Flag Coverage Δ
plugin 80.08% <94.54%> (+0.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...main/java/org/opensearch/ad/ml/ADModelManager.java 79.25% <ø> (+3.15%) ⬆️
...ch/timeseries/ml/MemoryAwareConcurrentHashmap.java 84.61% <ø> (+53.18%) ⬆️
...ensearch/timeseries/model/ValidationIssueType.java 100.00% <100.00%> (ø)
...imeseries/transport/SuggestConfigParamRequest.java 92.59% <75.00%> (+54.13%) ⬆️
.../java/org/opensearch/ad/model/AnomalyDetector.java 88.99% <95.91%> (+2.65%) ⬆️

... and 14 files with indirect coverage changes

* @param configId config Id
* @return a map of model id to its memory size
*/
public Map<String, Long> getModelSize(String configId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where these just never used anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, they are not used after recent refactoring.


// Null check for features
if (features == null) {
// Cannot proceed with validation if features are null but rules are not null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could add || features.isEmpty() same we do for rules above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, fixed.

// Null check for features
if (features == null) {
// Cannot proceed with validation if features are null but rules are not null
this.errorMessage = "Suppression Rule Error: Features are not defined while suppression rules are provided.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "Suppression Rule Error" can be put in a constant

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

|| thresholdType == ThresholdType.EXPECTED_OVER_ACTUAL_RATIO) {
// Check if the value is not NaN
double value = condition.getValue();
if (Double.isNaN(value)) {
Copy link
Member

@amitgalitz amitgalitz Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw I will be changing value section to be okay with Null if threshold type is ACTUAL_IS_OVER_EXPECTED or EXPECTED_IS_OVER_ACTUAL. Will make sure those aren't passed to RCF and seen as not a rule in that case later on too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks.

amitgalitz
amitgalitz previously approved these changes Oct 18, 2024
Signed-off-by: Kaituo Li <[email protected]>
@kaituo kaituo merged commit 9cdbcee into opensearch-project:main Oct 18, 2024
20 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 18, 2024
* Add rule validation in AnomalyDetector constructor

This commit introduces rule validation within the AnomalyDetector constructor. Any validation errors are now propagated and displayed on the frontend to ensure immediate feedback.

Testing:
* Verified that validation errors are properly propagated and shown on the frontend.
* Added UTs to cover the new validation logic.

Signed-off-by: Kaituo Li <[email protected]>

* address Amit's comments

Signed-off-by: Kaituo Li <[email protected]>

---------

Signed-off-by: Kaituo Li <[email protected]>
(cherry picked from commit 9cdbcee)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
kaituo pushed a commit that referenced this pull request Oct 18, 2024
* Add rule validation in AnomalyDetector constructor

This commit introduces rule validation within the AnomalyDetector constructor. Any validation errors are now propagated and displayed on the frontend to ensure immediate feedback.

Testing:
* Verified that validation errors are properly propagated and shown on the frontend.
* Added UTs to cover the new validation logic.



* address Amit's comments



---------


(cherry picked from commit 9cdbcee)

Signed-off-by: Kaituo Li <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x infra Changes to infrastructure, testing, CI/CD, pipelines, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants