diff --git a/libs/common/src/main/java/org/opensearch/common/annotation/processor/ApiAnnotationProcessor.java b/libs/common/src/main/java/org/opensearch/common/annotation/processor/ApiAnnotationProcessor.java index 0d4e342bd9dc6..6264d00f01887 100644 --- a/libs/common/src/main/java/org/opensearch/common/annotation/processor/ApiAnnotationProcessor.java +++ b/libs/common/src/main/java/org/opensearch/common/annotation/processor/ApiAnnotationProcessor.java @@ -179,11 +179,6 @@ private void process(ExecutableElement executable, ReferenceType ref) { return; } - // Skip protobuf generated classes used in public apis - if (ref.toString().contains("Proto")) { - return; - } - if (ref instanceof DeclaredType) { final DeclaredType declaredType = (DeclaredType) ref; @@ -243,7 +238,15 @@ private boolean inspectable(ExecutableElement executable) { */ private boolean inspectable(Element element) { final PackageElement pckg = processingEnv.getElementUtils().getPackageOf(element); - return pckg.getQualifiedName().toString().startsWith(OPENSEARCH_PACKAGE); + return pckg.getQualifiedName().toString().startsWith(OPENSEARCH_PACKAGE) + && !element.getEnclosingElement() + .getAnnotationMirrors() + .stream() + .anyMatch( + m -> m.getAnnotationType() + .toString() /* ClassSymbol.toString() returns class name */ + .equalsIgnoreCase("javax.annotation.Generated") + ); } /** diff --git a/server/src/main/java/org/opensearch/common/util/FeatureFlags.java b/server/src/main/java/org/opensearch/common/util/FeatureFlags.java index e43dfd3b3b063..f9da0968699b5 100644 --- a/server/src/main/java/org/opensearch/common/util/FeatureFlags.java +++ b/server/src/main/java/org/opensearch/common/util/FeatureFlags.java @@ -103,6 +103,8 @@ public class FeatureFlags { public static final Setting PLUGGABLE_CACHE_SETTING = Setting.boolSetting(PLUGGABLE_CACHE, false, Property.NodeScope); + public static final Setting PROTOBUF_SETTING = Setting.boolSetting(PROTOBUF, false, Property.NodeScope, Property.Dynamic); + private static final List> ALL_FEATURE_FLAG_SETTINGS = List.of( REMOTE_STORE_MIGRATION_EXPERIMENTAL_SETTING, EXTENSIONS_SETTING, @@ -110,7 +112,8 @@ public class FeatureFlags { TELEMETRY_SETTING, DATETIME_FORMATTER_CACHING_SETTING, WRITEABLE_REMOTE_INDEX_SETTING, - PLUGGABLE_CACHE_SETTING + PLUGGABLE_CACHE_SETTING, + PROTOBUF_SETTING ); /** * Should store the settings from opensearch.yml. @@ -166,5 +169,4 @@ public static boolean isEnabled(Setting featureFlag) { } } - public static final Setting PROTOBUF_SETTING = Setting.boolSetting(PROTOBUF, false, Property.NodeScope, Property.Dynamic); } diff --git a/server/src/main/java/org/opensearch/search/SearchHit.java b/server/src/main/java/org/opensearch/search/SearchHit.java index 3cd85488bd0c6..6391353cfe5b1 100644 --- a/server/src/main/java/org/opensearch/search/SearchHit.java +++ b/server/src/main/java/org/opensearch/search/SearchHit.java @@ -39,7 +39,6 @@ import org.opensearch.common.Nullable; import org.opensearch.common.annotation.PublicApi; import org.opensearch.common.document.DocumentField; -import org.opensearch.common.util.FeatureFlags; import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.core.ParseField; import org.opensearch.core.common.ParsingException; @@ -68,8 +67,6 @@ import org.opensearch.rest.action.search.RestSearchAction; import org.opensearch.search.fetch.subphase.highlight.HighlightField; import org.opensearch.search.lookup.SourceLookup; -import org.opensearch.search.serializer.SearchHitProtobufSerializer; -import org.opensearch.server.proto.FetchSearchResultProto; import org.opensearch.transport.RemoteClusterAware; import java.io.IOException; @@ -142,8 +139,6 @@ public final class SearchHit implements Writeable, ToXContentObject, Iterable innerHits; - private FetchSearchResultProto.SearchHit searchHitProto; - // used only in tests public SearchHit(int docId) { this(docId, null, null, null); @@ -169,9 +164,6 @@ public SearchHit( this.nestedIdentity = nestedIdentity; this.documentFields = documentFields == null ? emptyMap() : documentFields; this.metaFields = metaFields == null ? emptyMap() : metaFields; - if (FeatureFlags.isEnabled(FeatureFlags.PROTOBUF)) { - this.searchHitProto = SearchHitProtobufSerializer.convertHitToProto(this); - } } public SearchHit(StreamInput in) throws IOException { @@ -456,9 +448,6 @@ public void setDocumentField(String fieldName, DocumentField field) { if (fieldName == null || field == null) return; if (documentFields.isEmpty()) this.documentFields = new HashMap<>(); this.documentFields.put(fieldName, field); - if (FeatureFlags.isEnabled(FeatureFlags.PROTOBUF)) { - this.searchHitProto = SearchHitProtobufSerializer.convertHitToProto(this); - } } public DocumentField removeDocumentField(String fieldName) { diff --git a/server/src/main/java/org/opensearch/search/SearchHits.java b/server/src/main/java/org/opensearch/search/SearchHits.java index cd5854898fccd..0b4ee3851bd61 100644 --- a/server/src/main/java/org/opensearch/search/SearchHits.java +++ b/server/src/main/java/org/opensearch/search/SearchHits.java @@ -38,7 +38,6 @@ import org.opensearch.common.Nullable; import org.opensearch.common.annotation.PublicApi; import org.opensearch.common.lucene.Lucene; -import org.opensearch.common.util.FeatureFlags; import org.opensearch.core.common.io.stream.StreamInput; import org.opensearch.core.common.io.stream.StreamOutput; import org.opensearch.core.common.io.stream.Writeable; @@ -46,7 +45,6 @@ import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.rest.action.search.RestSearchAction; -import org.opensearch.search.serializer.SearchHitsProtobufSerializer; import java.io.IOException; import java.util.ArrayList; @@ -84,8 +82,6 @@ public static SearchHits empty(boolean withTotalHits) { @Nullable private final Object[] collapseValues; - private org.opensearch.server.proto.FetchSearchResultProto.SearchHits searchHitsProto; - public SearchHits(SearchHit[] hits, @Nullable TotalHits totalHits, float maxScore) { this(hits, totalHits, maxScore, null, null, null); } @@ -104,9 +100,6 @@ public SearchHits( this.sortFields = sortFields; this.collapseField = collapseField; this.collapseValues = collapseValues; - if (FeatureFlags.isEnabled(FeatureFlags.PROTOBUF_SETTING)) { - this.searchHitsProto = SearchHitsProtobufSerializer.convertHitsToProto(this); - } } public SearchHits(StreamInput in) throws IOException {