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

[Extensions] Moving ExtensionsRequest to use Protobuf #6960

Merged
Merged
Show file tree
Hide file tree
Changes from 11 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Enable sort optimization for all NumericTypes ([#6464](https://github.com/opensearch-project/OpenSearch/pull/6464)
- Remove 'cluster_manager' role attachment when using 'node.master' deprecated setting ([#6331](https://github.com/opensearch-project/OpenSearch/pull/6331))
- Add new cluster settings to ignore weighted round-robin routing and fallback to default behaviour. ([#6834](https://github.com/opensearch-project/OpenSearch/pull/6834))
- [Extensions] Moving Extensions APIs to protobuf serialization. ([#6960](https://github.com/opensearch-project/OpenSearch/pull/6960))
- Add experimental support for ZSTD compression. ([#3577](https://github.com/opensearch-project/OpenSearch/pull/3577))
- [Segment Replication] Add point in time and scroll query compatibility. ([#6644](https://github.com/opensearch-project/OpenSearch/pull/6644))

Expand Down Expand Up @@ -136,4 +137,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Security

[Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.x...HEAD
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.5...2.x
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.5...2.x
8 changes: 0 additions & 8 deletions modules/transport-netty4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ thirdPartyAudit {
'com.aayushatharva.brotli4j.encoder.Encoder$Parameters',
// classes are missing

// from io.netty.handler.codec.protobuf.ProtobufDecoder (netty)
'com.google.protobuf.ExtensionRegistry',
'com.google.protobuf.MessageLite$Builder',
'com.google.protobuf.MessageLite',
'com.google.protobuf.Parser',

// from io.netty.logging.CommonsLoggerFactory (netty)
'org.apache.commons.logging.Log',
'org.apache.commons.logging.LogFactory',
Expand Down Expand Up @@ -191,8 +185,6 @@ thirdPartyAudit {
'org.slf4j.spi.LocationAwareLogger',

'com.github.luben.zstd.Zstd',
'com.google.protobuf.ExtensionRegistryLite',
'com.google.protobuf.MessageLiteOrBuilder',
'com.google.protobuf.nano.CodedOutputByteBufferNano',
'com.google.protobuf.nano.MessageNano',
'com.jcraft.jzlib.Deflater',
Expand Down
13 changes: 4 additions & 9 deletions plugins/repository-gcs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ dependencies {
api 'com.google.api:api-common:1.8.1'
api 'com.google.api:gax:2.17.0'
api 'org.threeten:threetenbp:1.4.4'
api 'com.google.protobuf:protobuf-java-util:3.22.2'
api 'com.google.protobuf:protobuf-java:3.22.2'
api 'com.google.code.gson:gson:2.9.0'
api 'com.google.api.grpc:proto-google-common-protos:2.10.0'
api 'com.google.api.grpc:proto-google-iam-v1:0.12.0'
Expand Down Expand Up @@ -105,13 +103,6 @@ tasks.named("dependencyLicenses").configure {
thirdPartyAudit {
ignoreViolations(
// uses internal java api: sun.misc.Unsafe
'com.google.protobuf.UnsafeUtil',
'com.google.protobuf.UnsafeUtil$1',
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
'com.google.protobuf.UnsafeUtil$MemoryAccessor',
'com.google.protobuf.MessageSchema',
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
'com.google.common.cache.Striped64',
'com.google.common.cache.Striped64$1',
'com.google.common.cache.Striped64$Cell',
Expand Down Expand Up @@ -151,6 +142,10 @@ thirdPartyAudit {
'com.google.appengine.api.urlfetch.URLFetchService',
'com.google.appengine.api.urlfetch.URLFetchServiceFactory',
'com.oracle.svm.core.configure.ResourcesRegistry',
'com.google.protobuf.util.JsonFormat',
'com.google.protobuf.util.JsonFormat$Parser',
'com.google.protobuf.util.JsonFormat$Printer',
'com.google.protobuf.util.Timestamps',
// commons-logging optional dependencies
'org.apache.avalon.framework.logger.Logger',
'org.apache.log.Hierarchy',
Expand Down

This file was deleted.

10 changes: 1 addition & 9 deletions plugins/repository-hdfs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ dependencies {
api 'org.apache.avro:avro:1.11.1'
api 'com.google.code.gson:gson:2.10.1'
runtimeOnly "com.google.guava:guava:${versions.guava}"
api 'com.google.protobuf:protobuf-java:3.22.2'
api "commons-logging:commons-logging:${versions.commonslogging}"
api 'commons-cli:commons-cli:1.5.0'
api "commons-codec:commons-codec:${versions.commonscodec}"
Expand Down Expand Up @@ -116,14 +115,7 @@ tasks.named("dependencyLicenses").configure {

thirdPartyAudit {
ignoreViolations(
// uses internal java api: sun.misc.Unsafe
'com.google.protobuf.MessageSchema',
'com.google.protobuf.UnsafeUtil',
'com.google.protobuf.UnsafeUtil$1',
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
'com.google.protobuf.UnsafeUtil$MemoryAccessor'

)
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup we do. We are removing these violations from the plugin.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry if I wasn't clear. I meant do we need thirdPartyAudit task here anymore in this build.gradle? Can we remove the task from this build.gradle

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I missed that. It makes sense.


Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions plugins/repository-hdfs/licenses/protobuf-java-LICENSE.txt

This file was deleted.

2 changes: 0 additions & 2 deletions plugins/repository-hdfs/licenses/protobuf-java-NOTICE.txt

This file was deleted.

8 changes: 0 additions & 8 deletions plugins/transport-nio/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ thirdPartyAudit {
'com.aayushatharva.brotli4j.encoder.Encoder$Mode',
'com.aayushatharva.brotli4j.encoder.Encoder$Parameters',

// from io.netty.handler.codec.protobuf.ProtobufDecoder (netty)
'com.google.protobuf.ExtensionRegistry',
'com.google.protobuf.MessageLite$Builder',
'com.google.protobuf.MessageLite',
'com.google.protobuf.Parser',

// from io.netty.logging.CommonsLoggerFactory (netty)
'org.apache.commons.logging.Log',
'org.apache.commons.logging.LogFactory',
Expand Down Expand Up @@ -118,8 +112,6 @@ thirdPartyAudit {
'org.slf4j.spi.LocationAwareLogger',

'com.github.luben.zstd.Zstd',
'com.google.protobuf.ExtensionRegistryLite',
'com.google.protobuf.MessageLiteOrBuilder',
'com.google.protobuf.nano.CodedOutputByteBufferNano',
'com.google.protobuf.nano.MessageNano',
'com.jcraft.jzlib.Deflater',
Expand Down
Empty file added protobuf-java-NOTICE.txt
Empty file.
29 changes: 29 additions & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

import org.opensearch.gradle.info.BuildParams

plugins {
id('com.google.protobuf') version '0.8.19'
saratvemulapalli marked this conversation as resolved.
Show resolved Hide resolved
}

apply plugin: 'opensearch.build'
apply plugin: 'com.netflix.nebula.optional-base'
apply plugin: 'opensearch.publish'
Expand All @@ -45,6 +49,13 @@ publishing {

archivesBaseName = 'opensearch'

sourceSets {
main {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

java {
srcDir "${buildDir}/generated/source/proto/main/java"
}
}
}
// we want to keep the JDKs in our IDEs set to JDK 8 until minimum JDK is bumped to 11 so we do not include this source set in our IDEs
if (!isEclipse) {
sourceSets {
Expand Down Expand Up @@ -136,6 +147,9 @@ dependencies {
// jna
api "net.java.dev.jna:jna:${versions.jna}"

// protobuf
api 'com.google.protobuf:protobuf-java:3.22.2'
saratvemulapalli marked this conversation as resolved.
Show resolved Hide resolved

testImplementation(project(":test:framework")) {
// tests use the locally compiled version of server
exclude group: 'org.opensearch', module: 'server'
Expand Down Expand Up @@ -203,6 +217,12 @@ def generatePluginsList = tasks.register("generatePluginsList") {
}
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.22.2"
}
}

tasks.named("processResources").configure {
dependsOn generateModulesList, generatePluginsList
}
Expand Down Expand Up @@ -303,6 +323,15 @@ tasks.named("thirdPartyAudit").configure {
'com.google.common.geometry.S2$Metric',
'com.google.common.geometry.S2LatLng'
)
ignoreViolations(
'com.google.protobuf.MessageSchema',
'com.google.protobuf.UnsafeUtil',
'com.google.protobuf.UnsafeUtil$1',
'com.google.protobuf.UnsafeUtil$Android32MemoryAccessor',
'com.google.protobuf.UnsafeUtil$Android64MemoryAccessor',
'com.google.protobuf.UnsafeUtil$JvmMemoryAccessor',
'com.google.protobuf.UnsafeUtil$MemoryAccessor'
)
}

tasks.named("dependencyLicenses").configure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import org.opensearch.common.Nullable;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.extensions.proto.ExtensionRequestProto;
import org.opensearch.transport.TransportRequest;

import java.io.IOException;
import java.util.Objects;
import java.util.Optional;

/**
* CLusterService Request for Extensibility
Expand All @@ -26,54 +26,54 @@
*/
public class ExtensionRequest extends TransportRequest {
Copy link
Member

Choose a reason for hiding this comment

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

Can we have the generated protobuf class generate the transport request required methods while its at it? I'd love to get rid of the error prone equals/hash/tostring also

Copy link
Member Author

Choose a reason for hiding this comment

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

One step at a time :)
Definitely possible, some more framework to plumb in.

Copy link
Member Author

Choose a reason for hiding this comment

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

private static final Logger logger = LogManager.getLogger(ExtensionRequest.class);
private final ExtensionsManager.RequestType requestType;
private final Optional<String> uniqueId;
private final ExtensionRequestProto.ExtensionRequest request;
owaiskazi19 marked this conversation as resolved.
Show resolved Hide resolved

public ExtensionRequest(ExtensionsManager.RequestType requestType) {
public ExtensionRequest(ExtensionRequestProto.RequestType requestType) {
this(requestType, null);
}

public ExtensionRequest(ExtensionsManager.RequestType requestType, @Nullable String uniqueId) {
this.requestType = requestType;
this.uniqueId = uniqueId == null ? Optional.empty() : Optional.of(uniqueId);
public ExtensionRequest(ExtensionRequestProto.RequestType requestType, @Nullable String uniqueId) {
ExtensionRequestProto.ExtensionRequest.Builder builder = ExtensionRequestProto.ExtensionRequest.newBuilder();
if (uniqueId != null) {
saratvemulapalli marked this conversation as resolved.
Show resolved Hide resolved
builder.setUniqueId(uniqueId);
}
this.request = builder.setRequestType(requestType).build();
}

public ExtensionRequest(StreamInput in) throws IOException {
super(in);
this.requestType = in.readEnum(ExtensionsManager.RequestType.class);
String id = in.readOptionalString();
this.uniqueId = id == null ? Optional.empty() : Optional.of(id);
this.request = ExtensionRequestProto.ExtensionRequest.parseFrom(in.readByteArray());
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeEnum(requestType);
out.writeOptionalString(uniqueId.orElse(null));
out.writeByteArray(request.toByteArray());
}

public ExtensionsManager.RequestType getRequestType() {
return this.requestType;
public ExtensionRequestProto.RequestType getRequestType() {
return this.request.getRequestType();
}

public Optional<String> getUniqueId() {
return uniqueId;
public String getUniqueId() {
return request.getUniqueId();
}

public String toString() {
return "ExtensionRequest{" + "requestType=" + requestType + "uniqueId=" + uniqueId + '}';
return "ExtensionRequest{" + request.toString() + '}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ExtensionRequest that = (ExtensionRequest) o;
return Objects.equals(requestType, that.requestType) && Objects.equals(uniqueId, that.uniqueId);
return Objects.equals(request.getRequestType(), that.request.getRequestType())
&& Objects.equals(request.getUniqueId(), that.request.getUniqueId());
}

@Override
public int hashCode() {
return Objects.hash(requestType, uniqueId);
return Objects.hash(request.getRequestType(), request.getUniqueId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,13 @@ public class ExtensionsManager {
public static final String REQUEST_EXTENSION_REGISTER_CUSTOM_SETTINGS = "internal:discovery/registercustomsettings";
public static final String REQUEST_EXTENSION_REGISTER_REST_ACTIONS = "internal:discovery/registerrestactions";
public static final String REQUEST_EXTENSION_REGISTER_TRANSPORT_ACTIONS = "internal:discovery/registertransportactions";
public static final String REQUEST_OPENSEARCH_PARSE_NAMED_WRITEABLE = "internal:discovery/parsenamedwriteable";
saratvemulapalli marked this conversation as resolved.
Show resolved Hide resolved
public static final String REQUEST_REST_EXECUTE_ON_EXTENSION_ACTION = "internal:extensions/restexecuteonextensiontaction";
public static final String REQUEST_EXTENSION_HANDLE_TRANSPORT_ACTION = "internal:extensions/handle-transportaction";
public static final String REQUEST_EXTENSION_HANDLE_REMOTE_TRANSPORT_ACTION = "internal:extensions/handle-remote-transportaction";
public static final String TRANSPORT_ACTION_REQUEST_FROM_EXTENSION = "internal:extensions/request-transportaction-from-extension";
public static final int EXTENSION_REQUEST_WAIT_TIMEOUT = 10;

private static final Logger logger = LogManager.getLogger(ExtensionsManager.class);

/**
* Enum for Extension Requests
*
* @opensearch.internal
*/
public static enum RequestType {
REQUEST_EXTENSION_CLUSTER_STATE,
REQUEST_EXTENSION_CLUSTER_SETTINGS,
REQUEST_EXTENSION_REGISTER_REST_ACTIONS,
REQUEST_EXTENSION_REGISTER_SETTINGS,
REQUEST_EXTENSION_ENVIRONMENT_SETTINGS,
REQUEST_EXTENSION_DEPENDENCY_INFORMATION,
CREATE_COMPONENT,
ON_INDEX_MODULE,
GET_SETTINGS
};

/**
* Enum for OpenSearch Requests
*
Expand Down Expand Up @@ -430,7 +411,7 @@ public String executor() {
/**
* Handles an {@link ExtensionRequest}.
*
* @param extensionRequest The request to handle, of a type defined in the {@link RequestType} enum.
* @param extensionRequest The request to handle, of a type defined in the {@link org.opensearch.extensions.proto.ExtensionRequestProto.RequestType} enum.
* @return an Response matching the request.
* @throws Exception if the request is not handled properly.
*/
Expand All @@ -443,7 +424,7 @@ TransportResponse handleExtensionRequest(ExtensionRequest extensionRequest) thro
case REQUEST_EXTENSION_ENVIRONMENT_SETTINGS:
return new EnvironmentSettingsResponse(this.environmentSettings);
case REQUEST_EXTENSION_DEPENDENCY_INFORMATION:
String uniqueId = extensionRequest.getUniqueId().orElse(null);
String uniqueId = extensionRequest.getUniqueId();
if (uniqueId == null) {
return new ExtensionDependencyResponse(extensions);
} else {
Expand Down Expand Up @@ -686,10 +667,6 @@ public static String getRequestExtensionRegisterRestActions() {
return REQUEST_EXTENSION_REGISTER_REST_ACTIONS;
}

public static String getRequestOpensearchParseNamedWriteable() {
return REQUEST_OPENSEARCH_PARSE_NAMED_WRITEABLE;
}

public static String getRequestRestExecuteOnExtensionAction() {
return REQUEST_REST_EXECUTE_ON_EXTENSION_ACTION;
}
Expand Down
32 changes: 32 additions & 0 deletions server/src/main/proto/extensions/ExtensionRequestProto.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

syntax = "proto3";
package org.opensearch.extensions.proto;

option java_outer_classname = "ExtensionRequestProto";

enum RequestType {
REQUEST_EXTENSION_CLUSTER_STATE = 0;
REQUEST_EXTENSION_CLUSTER_SETTINGS = 1;
REQUEST_EXTENSION_REGISTER_REST_ACTIONS = 2;
REQUEST_EXTENSION_REGISTER_SETTINGS = 3;
REQUEST_EXTENSION_ENVIRONMENT_SETTINGS = 4;
REQUEST_EXTENSION_DEPENDENCY_INFORMATION = 5;
CREATE_COMPONENT = 6;
ON_INDEX_MODULE = 7;
GET_SETTINGS = 8;
}

message ExtensionRequest {
RequestType requestType = 1;
string uniqueId = 2;
}
saratvemulapalli marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public void testPrimaryBalanceWithContrainstBreaching() {

/**
* This test verifies global balance by creating indices iteratively and verify primary shards do not pile up on one
* node.
* @throws Exception generic exception
*/
public void testGlobalPrimaryBalance() throws Exception {
AllocationService strategy = createAllocationService(getSettingsBuilderForPrimaryBalance().build(), new TestGatewayAllocator());
Expand Down
Loading