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

[rule based autotagging] Add Create Rule API Logic #17335

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ruai0511
Copy link
Contributor

@ruai0511 ruai0511 commented Feb 12, 2025

Description

This PR introduces the create Rule API Logic.

An exampe API request is:

curl -XPUT "localhost:9200/_wlm/rule" -H 'Content-Type: application/json' -d '    
{
     "index_pattern": ["log*", "event*"],
     "query_group": "dev_query_group_id_2"
}'

And the return would be

{
    "_id":"zLKS95QBqTh9lO4Pl_FO",
    "index_pattern":["log*","event*"],
    "query_group":"dev_query_group_id_2",
    "updated_at":"2025-02-12T00:32:46.586Z"
}

Rule Schema PR:
#17238
RFC:
#16797

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

Copy link
Contributor

❌ Gradle check result for bab1e6e: 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?

@ruai0511 ruai0511 added the backport 2.x Backport to 2.x branch label Feb 12, 2025
Copy link
Contributor

❌ Gradle check result for 3c4c098: 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?

@ruai0511 ruai0511 changed the title Add Create Rule API Logic [rule based autotagging] Add Create Rule API Logic Feb 12, 2025
Signed-off-by: Ruirui Zhang <[email protected]>
Copy link
Contributor

❌ Gradle check result for 27567d7: 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?

@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add dynamic setting allowing size > 0 requests to be cached in the request cache ([#16483](https://github.com/opensearch-project/OpenSearch/pull/16483))
- Support installing plugin SNAPSHOTs with SNASPHOT distribution ([#16581](https://github.com/opensearch-project/OpenSearch/pull/16581))
- Make IndexStoreListener a pluggable interface ([#16583](https://github.com/opensearch-project/OpenSearch/pull/16583))
- Add create rule api logic for rule-based auto tagging ([#17335](https://github.com/opensearch-project/OpenSearch/pull/17335))
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add the project name in the beginning since it will help the viewer to set the context faster without reading the full line, e,g;
[Rule based auto-tagging] Add create rule API

Comment on lines +29 to +31
/**
* Default constructor
*/
Copy link
Contributor

@kaushalmahi12 kaushalmahi12 Feb 13, 2025

Choose a reason for hiding this comment

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

We should try to put meaningful comments if there is absolute need. In this case This is not a default constructor but to ensure that the created instances are created in the class scope only.

* @opensearch.experimental
*/
public class CreateRuleResponse extends ActionResponse implements ToXContent, ToXContentObject {
private final String _id;
Copy link
Contributor

Choose a reason for hiding this comment

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

If the Rule object is already carrying the id then this is redundant information.

import org.opensearch.action.ActionType;

/**
* Transport action to create Rule
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the comment is misleading here because the class is not a TransportAction class but it defines the type for the action which is used to define the mappings at co-ordinator and/or shard level request handling.

import java.util.Map;

/**
* This class defines the functions for Rule persistence
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the following javadoc is more effective description of the class
This class encapsulates the logic to manage the lifecycle of rules at index level

Comment on lines +127 to +139
/**
* client getter
*/
public Client getClient() {
return client;
}

/**
* clusterService getter
*/
public ClusterService getClusterService() {
return clusterService;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the use case for exposing these members ? I think it should not be required because the responsibility of the class is to deal with persistance of the Rules

Comment on lines +59 to +60
public void onResponse(Boolean indexCreated) {
persistRule(rule, listener);
Copy link
Contributor

Choose a reason for hiding this comment

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

We are not using the method param here. I think either we should remove this or make use of it to justify it in the method signature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants