Skip to content

Commit 01aa6e3

Browse files
authored
Merge branch 'main' into result-consumer-harden
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
2 parents f21f79d + 99f3189 commit 01aa6e3

File tree

75 files changed

+1119
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1119
-200
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1717
- Add a dynamic setting to change skip_cache_factor and min_frequency for querycache ([#18351](https://github.com/opensearch-project/OpenSearch/issues/18351))
1818
- Add overload constructor for Translog to accept Channel Factory as a parameter ([#18918](https://github.com/opensearch-project/OpenSearch/pull/18918))
1919
- Add subdirectory-aware store module with recovery support ([#19132](https://github.com/opensearch-project/OpenSearch/pull/19132))
20+
- [Rule-based Auto-tagging] Modify get rule api to suit nested attributes ([#19429](https://github.com/opensearch-project/OpenSearch/pull/19429))
21+
- [Rule-based Auto-tagging] Add autotagging label resolving logic for multiple attributes ([#19486](https://github.com/opensearch-project/OpenSearch/pull/19486))
2022
- Field collapsing supports search_after ([#19261](https://github.com/opensearch-project/OpenSearch/pull/19261))
2123
- Add a dynamic cluster setting to control the enablement of the merged segment warmer ([#18929](https://github.com/opensearch-project/OpenSearch/pull/18929))
2224
- Publish transport-grpc-spi exposing QueryBuilderProtoConverter and QueryBuilderProtoConverterRegistry ([#18949](https://github.com/opensearch-project/OpenSearch/pull/18949))
@@ -43,7 +45,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4345
- Implement GRPC GeoBoundingBox, GeoDistance queries ([#19451](https://github.com/opensearch-project/OpenSearch/pull/19451))
4446
- Implement GRPC Ids, Range, and Terms Set queries ([#19448](https://github.com/opensearch-project/OpenSearch/pull/19448))
4547
- Implement GRPC Nested query ([#19453](https://github.com/opensearch-project/OpenSearch/pull/19453))
48+
- Add sub aggregation support for histogram aggregation using skiplist ([19438](https://github.com/opensearch-project/OpenSearch/pull/19438))
4649
- Optimization in String Terms Aggregation query for Large Bucket Counts([#18732](https://github.com/opensearch-project/OpenSearch/pull/18732))
50+
- New cluster setting search.query.max_query_string_length ([#19491](https://github.com/opensearch-project/OpenSearch/pull/19491))
4751
- Harden the circuit breaker and failure handle logic in query result consumer ([#19396](https://github.com/opensearch-project/OpenSearch/pull/19396))
4852

4953
### Changed
@@ -97,6 +101,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
97101
- Cache serialised cluster state based on cluster state version and node version.([#19307](https://github.com/opensearch-project/OpenSearch/pull/19307))
98102
- Fix stats API in store-subdirectory module's SubdirectoryAwareStore ([#19470](https://github.com/opensearch-project/OpenSearch/pull/19470))
99103
- Handle negative search request nodes stats ([#19340](https://github.com/opensearch-project/OpenSearch/pull/19340))
104+
- Remove unnecessary iteration per-shard in request cache cleanup ([#19263](https://github.com/opensearch-project/OpenSearch/pull/19263))
100105

101106
### Dependencies
102107
- Bump `com.gradleup.shadow:shadow-gradle-plugin` from 8.3.5 to 8.3.9 ([#19400](https://github.com/opensearch-project/OpenSearch/pull/19400))
@@ -108,7 +113,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
108113
- Bump `com.azure:azure-storage-common` from 12.29.1 to 12.30.2 ([#19016](https://github.com/opensearch-project/OpenSearch/pull/19016), [#19145](https://github.com/opensearch-project/OpenSearch/pull/19145))
109114
- Update OpenTelemetry to 1.53.0 and OpenTelemetry SemConv to 1.34.0 ([#19068](https://github.com/opensearch-project/OpenSearch/pull/19068))
110115
- Bump `1password/load-secrets-action` from 2 to 3 ([#19100](https://github.com/opensearch-project/OpenSearch/pull/19100))
111-
- Bump `com.nimbusds:nimbus-jose-jwt` from 10.3 to 10.5 ([#19099](https://github.com/opensearch-project/OpenSearch/pull/19099), [#19101](https://github.com/opensearch-project/OpenSearch/pull/19101), [#19254](https://github.com/opensearch-project/OpenSearch/pull/19254))
116+
- Bump `com.nimbusds:nimbus-jose-jwt` from 10.3 to 10.5 ([#19099](https://github.com/opensearch-project/OpenSearch/pull/19099), [#19101](https://github.com/opensearch-project/OpenSearch/pull/19101), [#19254](https://github.com/opensearch-project/OpenSearch/pull/19254), [#19362](https://github.com/opensearch-project/OpenSearch/pull/19362))
112117
- Bump netty from 4.1.121.Final to 4.1.125.Final ([#19103](https://github.com/opensearch-project/OpenSearch/pull/19103)) ([#19269](https://github.com/opensearch-project/OpenSearch/pull/19269)
113118
- Bump Google Cloud Storage SDK from 1.113.1 to 2.55.0 ([#18922](https://github.com/opensearch-project/OpenSearch/pull/18922))
114119
- Bump `com.google.auth:google-auth-library-oauth2-http` from 1.37.1 to 1.38.0 ([#19144](https://github.com/opensearch-project/OpenSearch/pull/19144))
@@ -140,6 +145,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
140145
- Bump `com.azure:azure-identity` from 1.14.2 to 1.18.0 ([#19361](https://github.com/opensearch-project/OpenSearch/pull/19361))
141146
- Bump `net.bytebuddy:byte-buddy` from 1.17.5 to 1.17.7 ([#19371](https://github.com/opensearch-project/OpenSearch/pull/19371))
142147
- Bump `lycheeverse/lychee-action` from 2.4.1 to 2.6.1 ([#19463](https://github.com/opensearch-project/OpenSearch/pull/19463))
148+
- Bump `io.grpc` deps from 1.68.2 to 1.75.0 ([#19495](https://github.com/opensearch-project/OpenSearch/pull/19495))
143149

144150
### Deprecated
145151

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ google_http_client = "1.44.1"
2929
google_auth = "1.29.0"
3030
tdigest = "3.3"
3131
hdrhistogram = "2.2.2"
32-
grpc = "1.68.2"
32+
grpc = "1.75.0"
3333
json_smart = "2.5.2"
3434

3535
# when updating the JNA version, also update the version in buildSrc/build.gradle
@@ -54,6 +54,7 @@ commonscodec = "1.18.0"
5454
commonslang = "3.18.0"
5555
commonscompress = "1.28.0"
5656
commonsio = "2.16.0"
57+
commonscollections4 = "4.5.0"
5758
# plugin dependencies
5859
aws = "2.32.29"
5960
awscrt = "0.35.0"

modules/autotagging-commons/common/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ apply plugin: 'opensearch.publish'
1212
description = 'OpenSearch Rule framework common constructs which spi and module shares'
1313

1414
dependencies {
15-
api 'org.apache.commons:commons-collections4:4.4'
15+
api "org.apache.commons:commons-collections4:${versions.commonscollections4}"
1616
implementation project(":libs:opensearch-common")
1717
compileOnly project(":server")
1818

modules/autotagging-commons/common/licenses/commons-collections4-4.4.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e5cf89f0c6e132fc970bd9a465fdcb8dbe94f75a
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.rule;
10+
11+
/**
12+
* Represents a feature value along with a matching score.
13+
*/
14+
public class MatchLabel<V> {
15+
private final V featureValue;
16+
private final float matchScore;
17+
18+
/**
19+
* Constructs a FeatureValueMatch with the given feature value and score.
20+
* @param featureValue the feature value
21+
* @param matchScore the matching score
22+
*/
23+
public MatchLabel(V featureValue, float matchScore) {
24+
this.featureValue = featureValue;
25+
this.matchScore = matchScore;
26+
}
27+
28+
/**
29+
* Returns the feature value.
30+
*/
31+
public V getFeatureValue() {
32+
return featureValue;
33+
}
34+
35+
/**
36+
* Returns the match score.
37+
*/
38+
public float getMatchScore() {
39+
return matchScore;
40+
}
41+
}

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/RuleUtils.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.nio.charset.StandardCharsets;
1818
import java.time.Instant;
1919
import java.util.Collections;
20+
import java.util.HashMap;
21+
import java.util.HashSet;
2022
import java.util.List;
2123
import java.util.Map;
2224
import java.util.Optional;
@@ -29,6 +31,8 @@
2931
*/
3032
@ExperimentalApi
3133
public class RuleUtils {
34+
private static final String PIPE_DELIMITER = "\\|";
35+
private static final String DOT_DELIMITER = ".";
3236

3337
/**
3438
* constructor for RuleUtils
@@ -112,4 +116,36 @@ public static Rule composeUpdatedRule(Rule originalRule, UpdateRuleRequest reque
112116
Instant.now().toString()
113117
);
114118
}
119+
120+
/**
121+
* Builds a flattened map of attribute filters from a {@link Rule}.
122+
* This method reformats nested or prioritized subfields (e.g., values containing "|" for sub-attributes)
123+
* into top-level attribute keys. For example, an attribute "principal" with value "username|admin" will
124+
* become "principal.username" -> "admin" in the resulting map. Attributes without prioritized subfields
125+
* remain unchanged.
126+
* The resulting map is structured to make querying rules from the index easier.
127+
* @param rule the rule whose attributes are to be flattened
128+
*/
129+
public static Map<String, Set<String>> buildAttributeFilters(Rule rule) {
130+
Map<String, Set<String>> attributeFilters = new HashMap<>();
131+
132+
for (Map.Entry<Attribute, Set<String>> entry : rule.getAttributeMap().entrySet()) {
133+
Attribute attribute = entry.getKey();
134+
Set<String> values = entry.getValue();
135+
if (hasSubfields(attribute)) {
136+
for (String value : values) {
137+
String[] parts = value.split(PIPE_DELIMITER);
138+
String topLevelAttribute = attribute.getName() + DOT_DELIMITER + parts[0];
139+
attributeFilters.computeIfAbsent(topLevelAttribute, k -> new HashSet<>()).add(parts[1]);
140+
}
141+
} else {
142+
attributeFilters.put(attribute.getName(), values);
143+
}
144+
}
145+
return attributeFilters;
146+
}
147+
148+
private static boolean hasSubfields(Attribute attribute) {
149+
return !attribute.getWeightedSubfields().isEmpty();
150+
}
115151
}

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/action/GetRuleRequest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.opensearch.common.annotation.ExperimentalApi;
1414
import org.opensearch.core.common.io.stream.StreamInput;
1515
import org.opensearch.core.common.io.stream.StreamOutput;
16-
import org.opensearch.rule.autotagging.Attribute;
1716
import org.opensearch.rule.autotagging.FeatureType;
1817
import org.opensearch.rule.autotagging.Rule;
1918
import org.opensearch.rule.autotagging.RuleValidator;
@@ -34,7 +33,7 @@
3433
@ExperimentalApi
3534
public class GetRuleRequest extends ActionRequest {
3635
private final String id;
37-
private final Map<Attribute, Set<String>> attributeFilters;
36+
private final Map<String, Set<String>> attributeFilters;
3837
private final String searchAfter;
3938
private final FeatureType featureType;
4039

@@ -45,7 +44,7 @@ public class GetRuleRequest extends ActionRequest {
4544
* @param searchAfter - The sort value used for pagination.
4645
* @param featureType - The feature type related to rule.
4746
*/
48-
public GetRuleRequest(String id, Map<Attribute, Set<String>> attributeFilters, String searchAfter, FeatureType featureType) {
47+
public GetRuleRequest(String id, Map<String, Set<String>> attributeFilters, String searchAfter, FeatureType featureType) {
4948
this.id = id;
5049
this.attributeFilters = attributeFilters;
5150
this.searchAfter = searchAfter;
@@ -60,7 +59,7 @@ public GetRuleRequest(StreamInput in) throws IOException {
6059
super(in);
6160
id = in.readOptionalString();
6261
featureType = FeatureType.from(in);
63-
attributeFilters = in.readMap(i -> Attribute.from(i, featureType), i -> new HashSet<>(i.readStringList()));
62+
attributeFilters = in.readMap(StreamInput::readString, i -> new HashSet<>(i.readStringList()));
6463
searchAfter = in.readOptionalString();
6564
}
6665

@@ -80,7 +79,7 @@ public void writeTo(StreamOutput out) throws IOException {
8079
super.writeTo(out);
8180
out.writeOptionalString(id);
8281
featureType.writeTo(out);
83-
out.writeMap(attributeFilters, (output, attribute) -> attribute.writeTo(output), StreamOutput::writeStringCollection);
82+
out.writeMap(attributeFilters, StreamOutput::writeString, StreamOutput::writeStringCollection);
8483
out.writeOptionalString(searchAfter);
8584
}
8685

@@ -94,7 +93,7 @@ public String getId() {
9493
/**
9594
* attributeFilters getter
9695
*/
97-
public Map<Attribute, Set<String>> getAttributeFilters() {
96+
public Map<String, Set<String>> getAttributeFilters() {
9897
return attributeFilters;
9998
}
10099

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/attribute_extractor/AttributeExtractor.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@
1515
* @param <V>
1616
*/
1717
public interface AttributeExtractor<V> {
18+
19+
/**
20+
* Defines the combination style used when a request contains multiple values
21+
* for an attribute.
22+
*/
23+
enum LogicalOperator {
24+
/**
25+
* Logical AND
26+
*/
27+
AND,
28+
/**
29+
* Logical OR
30+
*/
31+
OR
32+
}
33+
1834
/**
1935
* This method returns the Attribute which it is responsible for extracting
2036
* @return attribute
@@ -26,4 +42,13 @@ public interface AttributeExtractor<V> {
2642
* @return attribute value
2743
*/
2844
Iterable<V> extract();
45+
46+
/**
47+
* Returns the logical operator used when a request contains multiple values
48+
* for an attribute.
49+
* For example, if the request targets both index A and B, then a rule must
50+
* have both index A and B as attributes, requiring an AND operator.
51+
* @return the logical operator (e.g., AND, OR)
52+
*/
53+
LogicalOperator getLogicalOperator();
2954
}

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/autotagging/Attribute.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
import org.opensearch.core.xcontent.XContentBuilder;
1515
import org.opensearch.core.xcontent.XContentParseException;
1616
import org.opensearch.core.xcontent.XContentParser;
17+
import org.opensearch.rule.MatchLabel;
18+
import org.opensearch.rule.attribute_extractor.AttributeExtractor;
19+
import org.opensearch.rule.storage.AttributeValueStore;
1720

1821
import java.io.IOException;
22+
import java.util.HashMap;
1923
import java.util.HashSet;
24+
import java.util.List;
25+
import java.util.Map;
2026
import java.util.Set;
21-
import java.util.TreeMap;
27+
import java.util.stream.Collectors;
2228

2329
/**
2430
* Represents an attribute within the auto-tagging feature. Attributes define characteristics that can
@@ -36,10 +42,10 @@ public interface Attribute extends Writeable {
3642
String getName();
3743

3844
/**
39-
* Returns a map of subfields ordered by priority, where 1 represents the highest priority.
45+
* Returns a map of subfields with its weight, which is used to calculate the match score for the attribute.
4046
*/
41-
default TreeMap<Integer, String> getPrioritizedSubfields() {
42-
return new TreeMap<>();
47+
default Map<String, Float> getWeightedSubfields() {
48+
return new HashMap<>();
4349
}
4450

4551
/**
@@ -106,4 +112,28 @@ static Attribute from(StreamInput in, FeatureType featureType) throws IOExceptio
106112
}
107113
return attribute;
108114
}
115+
116+
/**
117+
* Evaluates the matching labels for the attribute
118+
* @param attributeExtractor the extractor to get the attribute
119+
* @param attributeValueStore in-memory value store for the attribute
120+
*/
121+
default List<MatchLabel<String>> findAttributeMatches(
122+
AttributeExtractor<String> attributeExtractor,
123+
AttributeValueStore<String, String> attributeValueStore
124+
) {
125+
Map<String, Float> scoreMap = new HashMap<>();
126+
127+
for (String value : attributeExtractor.extract()) {
128+
List<MatchLabel<String>> matches = attributeValueStore.getMatches(value);
129+
for (MatchLabel<String> entry : matches) {
130+
scoreMap.merge(entry.getFeatureValue(), entry.getMatchScore(), Float::sum);
131+
}
132+
}
133+
return scoreMap.entrySet()
134+
.stream()
135+
.map(e -> new MatchLabel<>(e.getKey(), e.getValue()))
136+
.sorted((a, b) -> Float.compare(b.getMatchScore(), a.getMatchScore()))
137+
.collect(Collectors.toList());
138+
}
109139
}

0 commit comments

Comments
 (0)