Skip to content

[Bug fix] Rule based Auto tagging update rule api #18488

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

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Bump OpenSearch Core main branch to 3.0.0 ([#18039](https://github.com/opensearch-project/OpenSearch/pull/18039))
- [Rule based Auto-tagging] Add wlm `ActionFilter` ([#17791](https://github.com/opensearch-project/OpenSearch/pull/17791))
- [Rule based auto-tagging] Add update rule API ([#17797](https://github.com/opensearch-project/OpenSearch/pull/17797))
- [Rule based auto-tagging] Bug fix for update rule api ([#18488](https://github.com/opensearch-project/OpenSearch/pull/18488))
- Update API of Message in index to add the timestamp for lag calculation in ingestion polling ([#17977](https://github.com/opensearch-project/OpenSearch/pull/17977/))
- Add Warm Disk Threshold Allocation Decider for Warm shards ([#18082](https://github.com/opensearch-project/OpenSearch/pull/18082))
- Add composite directory factory ([#17988](https://github.com/opensearch-project/OpenSearch/pull/17988))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ public static String computeRuleHash(
public static Optional<String> getDuplicateRuleId(Rule rule, List<Rule> ruleList) {
Map<Attribute, Set<String>> targetAttributeMap = rule.getAttributeMap();
for (Rule currRule : ruleList) {
Map<Attribute, Set<String>> existingAttributeMap = currRule.getAttributeMap();
String currRuleId = currRule.getId();
if (currRuleId.equals(rule.getId())) {
continue;
}

Map<Attribute, Set<String>> existingAttributeMap = currRule.getAttributeMap();
if (rule.getFeatureType() != currRule.getFeatureType() || targetAttributeMap.size() != existingAttributeMap.size()) {
continue;
}
Expand All @@ -82,7 +86,7 @@ public static Optional<String> getDuplicateRuleId(Rule rule, List<Rule> ruleList
}
}
if (allAttributesIntersect) {
return Optional.of(currRule.getId());
return Optional.of(currRuleId);
}
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Optional;
import java.util.Set;

import static org.opensearch.rule.utils.RuleTestUtils.ATTRIBUTE_MAP;
import static org.opensearch.rule.utils.RuleTestUtils.ATTRIBUTE_VALUE_ONE;
import static org.opensearch.rule.utils.RuleTestUtils.ATTRIBUTE_VALUE_TWO;
import static org.opensearch.rule.utils.RuleTestUtils.DESCRIPTION_ONE;
Expand All @@ -28,15 +29,25 @@
import static org.opensearch.rule.utils.RuleTestUtils.MockRuleAttributes;
import static org.opensearch.rule.utils.RuleTestUtils.TIMESTAMP_ONE;
import static org.opensearch.rule.utils.RuleTestUtils._ID_ONE;
import static org.opensearch.rule.utils.RuleTestUtils._ID_TWO;
import static org.opensearch.rule.utils.RuleTestUtils.ruleOne;
import static org.opensearch.rule.utils.RuleTestUtils.ruleTwo;

public class RuleUtilsTests extends OpenSearchTestCase {

public void testDuplicateRuleFound() {
Optional<String> result = RuleUtils.getDuplicateRuleId(ruleOne, List.of(ruleOne, ruleTwo));
Rule testRule = Rule.builder()
.id(_ID_TWO)
.description(DESCRIPTION_ONE)
.featureType(RuleTestUtils.MockRuleFeatureType.INSTANCE)
.featureValue(FEATURE_VALUE_ONE)
.attributeMap(ATTRIBUTE_MAP)
.updatedAt(TIMESTAMP_ONE)
.build();

Optional<String> result = RuleUtils.getDuplicateRuleId(ruleOne, List.of(testRule));
assertTrue(result.isPresent());
assertEquals(_ID_ONE, result.get());
assertEquals(_ID_TWO, result.get());
}

public void testNoAttributeIntersection() {
Expand Down Expand Up @@ -66,7 +77,7 @@ public void testAttributeSizeMismatch() {

public void testPartialAttributeValueIntersection() {
Rule ruleWithPartialOverlap = Rule.builder()
.id(_ID_ONE)
.id(_ID_TWO)
.description(DESCRIPTION_ONE)
.featureType(RuleTestUtils.MockRuleFeatureType.INSTANCE)
.featureValue(FEATURE_VALUE_ONE)
Expand All @@ -79,6 +90,11 @@ public void testPartialAttributeValueIntersection() {
assertEquals(_ID_ONE, result.get());
}

public void testDuplicateRuleWithSameId() {
Optional<String> result = RuleUtils.getDuplicateRuleId(ruleOne, List.of(ruleOne));
assertFalse(result.isPresent());
}

public void testDifferentFeatureTypes() {
Rule differentFeatureTypeRule = Rule.builder()
.id(_ID_ONE)
Expand Down
Loading