-
Notifications
You must be signed in to change notification settings - Fork 2k
[rule based autotagging] Add Create Rule API Logic #17792
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
base: main
Are you sure you want to change the base?
Conversation
454afcf
to
90e2b4c
Compare
❌ Gradle check result for 90e2b4c: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
90e2b4c
to
85ea24e
Compare
❌ Gradle check result for 85ea24e: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
85ea24e
to
e215963
Compare
❌ Gradle check result for e215963: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
❌ Gradle check result for e0c9c06: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Signed-off-by: Ruirui Zhang <[email protected]>
Signed-off-by: Ruirui Zhang <[email protected]>
Signed-off-by: Ruirui Zhang <[email protected]>
Signed-off-by: Ruirui Zhang <[email protected]>
Signed-off-by: Ruirui Zhang <[email protected]>
Signed-off-by: Ruirui Zhang <[email protected]>
Signed-off-by: Ruirui Zhang <[email protected]>
modify based on comments Signed-off-by: Ruirui Zhang <[email protected]>
Signed-off-by: Ruirui Zhang <[email protected]>
Signed-off-by: Ruirui Zhang <[email protected]>
Signed-off-by: Ruirui Zhang <[email protected]>
e0c9c06
to
8f8ecd2
Compare
Signed-off-by: Lingxi Chen <[email protected]>
8f8ecd2
to
c6e7250
Compare
❌ Gradle check result for c6e7250: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Signed-off-by: Ruirui Zhang <[email protected]>
c6e7250
to
dbe2e18
Compare
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.
Some minor comments, LGTM! overall. We should focus on test coverage though
* { | ||
* "description": "description1", | ||
* "index_pattern": ["log*", "event*"], | ||
* "query_group": "poOiU851RwyLYvV5lbvv5w" |
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.
lets replace query_group with workload_group wherever applicable
@Override | ||
public ActionRequestValidationException validate() { | ||
try { | ||
rule.getFeatureType().getFeatureValueValidator().validate(rule.getFeatureValue()); |
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.
We are chaining a lot of method calls in this statement, this can potentially result in NPE. Have we thought of the scenarios when this can be null ?
* "_id":"wi6VApYBoX5wstmtU_8l", | ||
* "description":"description1", | ||
* "index_pattern":["log*", "uvent*"], | ||
* "query_group":"poOiU851RwyLYvV5lbvv5w", |
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.
[NIT] name change
* Interface to check for rule duplication. | ||
*/ | ||
@ExperimentalApi | ||
public interface RuleDuplicateChecker { |
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.
I think DuplicateRuleChecker
is more appropriate name.
package org.opensearch.rule.autotagging; | ||
|
||
/** | ||
* Validates a feature value for a specific feature type |
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.
Lets add more context for this class. I think this is not a simple string format and length checker but rather it validates the value against the pre-stored feature values (index, cluster state ....etc).
*/ | ||
public void createRule(CreateRuleRequest request, ActionListener<CreateRuleResponse> listener) { | ||
try (ThreadContext.StoredContext ctx = getContext()) { | ||
createIndexIfAbsent(new ActionListener<>() { |
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.
I think we can write this in a better way, Lot of action listener chaining is unnecessary
if (indexDoesNotExist) {
createIndex(listener); //this is a method listener
} else {
saveRule(listener);
}
private void createIndex(ActionListener<CreateRuleResponse> listener) {
final CreateIndexRequest request = new CreateIndexRequest(indexName).settings(indexSettings);
client.admin().indices().create(request, new ActionListener<>() {
@Override
public void onResponse(CreateIndexResponse response) {
if (!response.isAcknowledged()) {
throwError;
} else {
saveRule(listener);
}
}
@Override
public void onFailure(Exception e) {
if (e instanceof ResourceAlreadyExistsException) {
saveRule(rule, listener);
} else {
logger.error("Failed to create index {}: {}", indexName, e.getMessage());
listener.onFailure(e);
}
}
});
}
Signed-off-by: Ruirui Zhang <[email protected]>
Signed-off-by: Ruirui Zhang <[email protected]>
❌ Gradle check result for 9a706c2: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
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.
LGTM! just need to address/answer the two questions
FeatureValueValidator featureValueValidator = rule.getFeatureType().getFeatureValueValidator(); | ||
if (featureValueValidator != null) { | ||
featureValueValidator.validate(rule.getFeatureValue()); | ||
} |
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.
I believe it will be abnormal behavior when feature validator is null hence we should at least log the instance or throw exception.
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.
Right. Yesterday, I thought it made sense for featureValueValidator to be null if a feature type didn’t need any validation. But thinking about it more now, it’s better if featureValueValidator is always present. If a feature type doesn’t actually need validation, its validate() method can just do nothing or return null (although i doubt if any feature value doesn't need validation)
} | ||
@Override | ||
public void onFailure(Exception e) { | ||
if (e instanceof ResourceAlreadyExistsException) { |
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.
Will we always get only this exception if the index already exists or e
can be something different as well
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.
Based on this I believe it'll always be ResourceAlreadyExistsException
Signed-off-by: Ruirui Zhang <[email protected]>
❌ Gradle check result for d70aa32: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Description
This PR introduces the create Rule API Logic.
An exampe API request is:
And the return would be
Rule Schema PR:
#17238
RFC:
#16797
Check List