Skip to content

Commit

Permalink
xds: migrate udpa proto to xds directory (#8686)
Browse files Browse the repository at this point in the history
fix #8631:
1. import udpa protos form new git repo `https://github.com/cncf/xds.git` instead of  `https://github.com/cncf/udpa.git`
2. use proto from xds directory not udpa directory in `https://github.com/cncf/xds.git`, details was here cncf/xds#2 (comment)
3. support both versions of TypeStruct
4. remove v1 orca service in old directory and use the new one v3, and refer to v3 in ORCA related area
  • Loading branch information
YifeiZhuang authored Nov 11, 2021
1 parent ad0971e commit 881747a
Show file tree
Hide file tree
Showing 31 changed files with 476 additions and 90 deletions.
7 changes: 6 additions & 1 deletion xds/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sourceSets {
proto {
srcDir 'third_party/envoy/src/main/proto'
srcDir 'third_party/protoc-gen-validate/src/main/proto'
srcDir 'third_party/udpa/src/main/proto'
srcDir 'third_party/xds/src/main/proto'
srcDir 'third_party/googleapis/src/main/proto'
srcDir 'third_party/istio/src/main/proto'
}
Expand All @@ -92,6 +92,7 @@ jar {
javadoc {
// Exclusions here should generally also be relocated
exclude 'com/github/udpa/**'
exclude 'com/github/xds/**'
exclude 'com/google/security/**'
exclude 'io/envoyproxy/**'
// Need to clean up the class structure to reduce how much is exposed
Expand All @@ -115,6 +116,7 @@ shadowJar {
}
// Relocated packages commonly need exclusions in jacocoTestReport and javadoc
relocate 'com.github.udpa', "${prefixName}.shaded.com.github.udpa"
relocate 'com.github.xds', "${prefixName}.shaded.com.github.xds"
relocate 'com.google.api.expr', "${prefixName}.shaded.com.google.api.expr"
relocate 'com.google.security', "${prefixName}.shaded.com.google.security"
// TODO: missing java_package option in .proto
Expand All @@ -124,6 +126,7 @@ shadowJar {
relocate 'io.netty', 'io.grpc.netty.shaded.io.netty'
// TODO: missing java_package option in .proto
relocate 'udpa.annotations', "${prefixName}.shaded.udpa.annotations"
relocate 'xds.annotations', "${prefixName}.shaded.xds.annotations"
exclude "**/*.proto"
}

Expand Down Expand Up @@ -159,11 +162,13 @@ jacocoTestReport {
fileTree(dir: it,
exclude: [ // Exclusions here should generally also be relocated
'**/com/github/udpa/**',
'**/com/github/xds/**',
'**/com/google/api/expr/**',
'**/com/google/security/**',
'**/envoy/annotations/**',
'**/io/envoyproxy/**',
'**/udpa/annotations/**',
'**/xds/annotations/**',
])
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.udpa.udpa.service.orca.v1;
package com.github.xds.service.orca.v3;

import static io.grpc.MethodDescriptor.generateFullMethodName;

Expand All @@ -16,38 +16,38 @@
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler",
comments = "Source: udpa/service/orca/v1/orca.proto")
comments = "Source: xds/service/orca/v3/orca.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class OpenRcaServiceGrpc {

private OpenRcaServiceGrpc() {}

public static final String SERVICE_NAME = "udpa.service.orca.v1.OpenRcaService";
public static final String SERVICE_NAME = "xds.service.orca.v3.OpenRcaService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest,
com.github.udpa.udpa.data.orca.v1.OrcaLoadReport> getStreamCoreMetricsMethod;
private static volatile io.grpc.MethodDescriptor<com.github.xds.service.orca.v3.OrcaLoadReportRequest,
com.github.xds.data.orca.v3.OrcaLoadReport> getStreamCoreMetricsMethod;

@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "StreamCoreMetrics",
requestType = com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest.class,
responseType = com.github.udpa.udpa.data.orca.v1.OrcaLoadReport.class,
requestType = com.github.xds.service.orca.v3.OrcaLoadReportRequest.class,
responseType = com.github.xds.data.orca.v3.OrcaLoadReport.class,
methodType = io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
public static io.grpc.MethodDescriptor<com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest,
com.github.udpa.udpa.data.orca.v1.OrcaLoadReport> getStreamCoreMetricsMethod() {
io.grpc.MethodDescriptor<com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest, com.github.udpa.udpa.data.orca.v1.OrcaLoadReport> getStreamCoreMetricsMethod;
public static io.grpc.MethodDescriptor<com.github.xds.service.orca.v3.OrcaLoadReportRequest,
com.github.xds.data.orca.v3.OrcaLoadReport> getStreamCoreMetricsMethod() {
io.grpc.MethodDescriptor<com.github.xds.service.orca.v3.OrcaLoadReportRequest, com.github.xds.data.orca.v3.OrcaLoadReport> getStreamCoreMetricsMethod;
if ((getStreamCoreMetricsMethod = OpenRcaServiceGrpc.getStreamCoreMetricsMethod) == null) {
synchronized (OpenRcaServiceGrpc.class) {
if ((getStreamCoreMetricsMethod = OpenRcaServiceGrpc.getStreamCoreMetricsMethod) == null) {
OpenRcaServiceGrpc.getStreamCoreMetricsMethod = getStreamCoreMetricsMethod =
io.grpc.MethodDescriptor.<com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest, com.github.udpa.udpa.data.orca.v1.OrcaLoadReport>newBuilder()
io.grpc.MethodDescriptor.<com.github.xds.service.orca.v3.OrcaLoadReportRequest, com.github.xds.data.orca.v3.OrcaLoadReport>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "StreamCoreMetrics"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest.getDefaultInstance()))
com.github.xds.service.orca.v3.OrcaLoadReportRequest.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
com.github.udpa.udpa.data.orca.v1.OrcaLoadReport.getDefaultInstance()))
com.github.xds.data.orca.v3.OrcaLoadReport.getDefaultInstance()))
.setSchemaDescriptor(new OpenRcaServiceMethodDescriptorSupplier("StreamCoreMetrics"))
.build();
}
Expand Down Expand Up @@ -116,8 +116,8 @@ public static abstract class OpenRcaServiceImplBase implements io.grpc.BindableS

/**
*/
public void streamCoreMetrics(com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest request,
io.grpc.stub.StreamObserver<com.github.udpa.udpa.data.orca.v1.OrcaLoadReport> responseObserver) {
public void streamCoreMetrics(com.github.xds.service.orca.v3.OrcaLoadReportRequest request,
io.grpc.stub.StreamObserver<com.github.xds.data.orca.v3.OrcaLoadReport> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getStreamCoreMetricsMethod(), responseObserver);
}

Expand All @@ -127,8 +127,8 @@ public void streamCoreMetrics(com.github.udpa.udpa.service.orca.v1.OrcaLoadRepor
getStreamCoreMetricsMethod(),
io.grpc.stub.ServerCalls.asyncServerStreamingCall(
new MethodHandlers<
com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest,
com.github.udpa.udpa.data.orca.v1.OrcaLoadReport>(
com.github.xds.service.orca.v3.OrcaLoadReportRequest,
com.github.xds.data.orca.v3.OrcaLoadReport>(
this, METHODID_STREAM_CORE_METRICS)))
.build();
}
Expand Down Expand Up @@ -160,8 +160,8 @@ protected OpenRcaServiceStub build(

/**
*/
public void streamCoreMetrics(com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest request,
io.grpc.stub.StreamObserver<com.github.udpa.udpa.data.orca.v1.OrcaLoadReport> responseObserver) {
public void streamCoreMetrics(com.github.xds.service.orca.v3.OrcaLoadReportRequest request,
io.grpc.stub.StreamObserver<com.github.xds.data.orca.v3.OrcaLoadReport> responseObserver) {
io.grpc.stub.ClientCalls.asyncServerStreamingCall(
getChannel().newCall(getStreamCoreMetricsMethod(), getCallOptions()), request, responseObserver);
}
Expand Down Expand Up @@ -193,8 +193,8 @@ protected OpenRcaServiceBlockingStub build(

/**
*/
public java.util.Iterator<com.github.udpa.udpa.data.orca.v1.OrcaLoadReport> streamCoreMetrics(
com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest request) {
public java.util.Iterator<com.github.xds.data.orca.v3.OrcaLoadReport> streamCoreMetrics(
com.github.xds.service.orca.v3.OrcaLoadReportRequest request) {
return io.grpc.stub.ClientCalls.blockingServerStreamingCall(
getChannel(), getStreamCoreMetricsMethod(), getCallOptions(), request);
}
Expand Down Expand Up @@ -245,8 +245,8 @@ private static final class MethodHandlers<Req, Resp> implements
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
switch (methodId) {
case METHODID_STREAM_CORE_METRICS:
serviceImpl.streamCoreMetrics((com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest) request,
(io.grpc.stub.StreamObserver<com.github.udpa.udpa.data.orca.v1.OrcaLoadReport>) responseObserver);
serviceImpl.streamCoreMetrics((com.github.xds.service.orca.v3.OrcaLoadReportRequest) request,
(io.grpc.stub.StreamObserver<com.github.xds.data.orca.v3.OrcaLoadReport>) responseObserver);
break;
default:
throw new AssertionError();
Expand All @@ -270,7 +270,7 @@ private static abstract class OpenRcaServiceBaseDescriptorSupplier

@java.lang.Override
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
return com.github.udpa.udpa.service.orca.v1.OrcaProto.getDescriptor();
return com.github.xds.service.orca.v3.OrcaProto.getDescriptor();
}

@java.lang.Override
Expand Down
49 changes: 30 additions & 19 deletions xds/src/main/java/io/grpc/xds/ClientXdsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
"type.googleapis.com/envoy.config.cluster.aggregate.v2alpha.ClusterConfig";
private static final String TYPE_URL_CLUSTER_CONFIG =
"type.googleapis.com/envoy.extensions.clusters.aggregate.v3.ClusterConfig";
private static final String TYPE_URL_TYPED_STRUCT =
private static final String TYPE_URL_TYPED_STRUCT_UDPA =
"type.googleapis.com/udpa.type.v1.TypedStruct";
private static final String TYPE_URL_TYPED_STRUCT =
"type.googleapis.com/xds.type.v3.TypedStruct";
private static final String TYPE_URL_FILTER_CONFIG =
"type.googleapis.com/envoy.config.route.v3.FilterConfig";
// TODO(zdapeng): need to discuss how to handle unsupported values.
Expand Down Expand Up @@ -908,16 +910,21 @@ static StructOrError<FilterConfig> parseHttpFilter(
}
Message rawConfig = httpFilter.getTypedConfig();
String typeUrl = httpFilter.getTypedConfig().getTypeUrl();
if (typeUrl.equals(TYPE_URL_TYPED_STRUCT)) {
TypedStruct typedStruct;
try {
typedStruct = httpFilter.getTypedConfig().unpack(TypedStruct.class);
} catch (InvalidProtocolBufferException e) {
return StructOrError.fromError(
"HttpFilter [" + filterName + "] contains invalid proto: " + e);

try {
if (typeUrl.equals(TYPE_URL_TYPED_STRUCT_UDPA)) {
TypedStruct typedStruct = httpFilter.getTypedConfig().unpack(TypedStruct.class);
typeUrl = typedStruct.getTypeUrl();
rawConfig = typedStruct.getValue();
} else if (typeUrl.equals(TYPE_URL_TYPED_STRUCT)) {
com.github.xds.type.v3.TypedStruct newTypedStruct =
httpFilter.getTypedConfig().unpack(com.github.xds.type.v3.TypedStruct.class);
typeUrl = newTypedStruct.getTypeUrl();
rawConfig = newTypedStruct.getValue();
}
typeUrl = typedStruct.getTypeUrl();
rawConfig = typedStruct.getValue();
} catch (InvalidProtocolBufferException e) {
return StructOrError.fromError(
"HttpFilter [" + filterName + "] contains invalid proto: " + e);
}
Filter filter = filterRegistry.get(typeUrl);
if ((isForClient && !(filter instanceof ClientInterceptorBuilder))
Expand Down Expand Up @@ -991,16 +998,20 @@ static StructOrError<Map<String, FilterConfig>> parseOverrideFilterConfigs(
typeUrl = anyConfig.getTypeUrl();
}
Message rawConfig = anyConfig;
if (typeUrl.equals(TYPE_URL_TYPED_STRUCT)) {
TypedStruct typedStruct;
try {
typedStruct = anyConfig.unpack(TypedStruct.class);
} catch (InvalidProtocolBufferException e) {
return StructOrError.fromError(
"FilterConfig [" + name + "] contains invalid proto: " + e);
try {
if (typeUrl.equals(TYPE_URL_TYPED_STRUCT_UDPA)) {
TypedStruct typedStruct = anyConfig.unpack(TypedStruct.class);
typeUrl = typedStruct.getTypeUrl();
rawConfig = typedStruct.getValue();
} else if (typeUrl.equals(TYPE_URL_TYPED_STRUCT)) {
com.github.xds.type.v3.TypedStruct newTypedStruct =
anyConfig.unpack(com.github.xds.type.v3.TypedStruct.class);
typeUrl = newTypedStruct.getTypeUrl();
rawConfig = newTypedStruct.getValue();
}
typeUrl = typedStruct.getTypeUrl();
rawConfig = typedStruct.getValue();
} catch (InvalidProtocolBufferException e) {
return StructOrError.fromError(
"FilterConfig [" + name + "] contains invalid proto: " + e);
}
Filter filter = filterRegistry.get(typeUrl);
if (filter == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.grpc.xds;

import com.github.udpa.udpa.data.orca.v1.OrcaLoadReport;
import com.github.xds.data.orca.v3.OrcaLoadReport;
import com.google.common.annotations.VisibleForTesting;
import io.grpc.Context;
import io.grpc.Contexts;
Expand Down
6 changes: 3 additions & 3 deletions xds/src/main/java/io/grpc/xds/OrcaOobUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import static io.grpc.ConnectivityState.READY;
import static io.grpc.ConnectivityState.SHUTDOWN;

import com.github.udpa.udpa.data.orca.v1.OrcaLoadReport;
import com.github.udpa.udpa.service.orca.v1.OpenRcaServiceGrpc;
import com.github.udpa.udpa.service.orca.v1.OrcaLoadReportRequest;
import com.github.xds.data.orca.v3.OrcaLoadReport;
import com.github.xds.service.orca.v3.OpenRcaServiceGrpc;
import com.github.xds.service.orca.v3.OrcaLoadReportRequest;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
Expand Down
2 changes: 1 addition & 1 deletion xds/src/main/java/io/grpc/xds/OrcaPerRequestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.github.udpa.udpa.data.orca.v1.OrcaLoadReport;
import com.github.xds.data.orca.v3.OrcaLoadReport;
import com.google.common.annotations.VisibleForTesting;
import io.grpc.CallOptions;
import io.grpc.ClientStreamTracer;
Expand Down
Loading

0 comments on commit 881747a

Please sign in to comment.