Skip to content

Commit

Permalink
split backend_protocol into backend_protocol and http_protocol
Browse files Browse the repository at this point in the history
Old way:
"backend_protocol" allows http, http1, http2, or grpc. it can be suffixed with "s" for tls.
New way:
"backend_protocol" only allows http or grpc. it can be suffixed with "s" for tls. Use "http_protocol" to specify http1 or http2.

Signed-off-by: Wayne Zhang <[email protected]>
Change-Id: I2a1aee919b39cb2d3acc68a3b91f06599cdc67f8
  • Loading branch information
qiwzhang committed Feb 6, 2020
1 parent e8cfc3f commit f4a215b
Show file tree
Hide file tree
Showing 41 changed files with 124 additions and 229 deletions.
12 changes: 6 additions & 6 deletions docker/generic/start_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ def make_argparser():
'--backend_protocol',
default=None,
help='''Backend Protocol. Overrides the protocol in --backend.
Choices: [http1|http2|grpc].
Default value: http1.''',
choices=['http1', 'http2', 'grpc'])
Choices: [http|https|grpc|grpcs].
Default value: http.''',
choices=['http', 'https', 'grpc', 'grpcs'])

parser.add_argument('--http_port', default=None, type=int, help='''
The port to accept HTTP/1.x, HTTP/2, and gRPC connections.
Expand Down Expand Up @@ -510,16 +510,16 @@ def gen_proxy_config(args):
backend_protocol = "grpc"
backends = args.backend[len(GRPC_PREFIX):]
elif args.backend.startswith(HTTP_PREFIX):
backend_protocol = "http1"
backend_protocol = "http"
backends = args.backend[len(HTTP_PREFIX):]
elif args.backend.startswith(HTTPS_PREFIX):
backend_protocol = "http2"
backend_protocol = "https"
backend = args.backend[len(HTTPS_PREFIX):]
if not re.search(r':[0-9]+$', backend):
backend = backend + ':443'
backends = backend
else:
backend_protocol = "http1"
backend_protocol = "http"
backends = args.backend
else:
backend_protocol = args.backend_protocol
Expand Down
1 change: 0 additions & 1 deletion examples/auth/envoy_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@
"clusters": [
{
"connectTimeout": "20s",
"http2ProtocolOptions": {},
"loadAssignment": {
"clusterName": "127.0.0.1",
"endpoints": [
Expand Down
1 change: 0 additions & 1 deletion examples/dynamic_routing/envoy_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"clusters": [
{
"connectTimeout": "20s",
"http2ProtocolOptions": {},
"loadAssignment": {
"clusterName": "127.0.0.1",
"endpoints": [
Expand Down
8 changes: 4 additions & 4 deletions src/go/bootstrap/static/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestServiceToBootstrapConfig(t *testing.T) {
{
desc: "envoy config with service control, no tracing",
opt_mod: func(opt *options.ConfigGeneratorOptions) {
opt.BackendProtocol = "http1"
opt.BackendProtocol = "http"
opt.DisableTracing = true
},
serviceConfigPath: platform.GetFilePath(platform.ScServiceConfig),
Expand All @@ -54,7 +54,7 @@ func TestServiceToBootstrapConfig(t *testing.T) {
{
desc: "envoy config for auth",
opt_mod: func(opt *options.ConfigGeneratorOptions) {
opt.BackendProtocol = "http2"
opt.BackendProtocol = "http"
opt.DisableTracing = true
opt.SkipServiceControlFilter = true
},
Expand All @@ -64,7 +64,7 @@ func TestServiceToBootstrapConfig(t *testing.T) {
{
desc: "envoy config with dynamic routing",
opt_mod: func(opt *options.ConfigGeneratorOptions) {
opt.BackendProtocol = "http2"
opt.BackendProtocol = "http"
opt.DisableTracing = true
opt.SkipServiceControlFilter = true
},
Expand All @@ -74,7 +74,7 @@ func TestServiceToBootstrapConfig(t *testing.T) {
{
desc: "envoy config for path matcher",
opt_mod: func(opt *options.ConfigGeneratorOptions) {
opt.BackendProtocol = "http2"
opt.BackendProtocol = "http"
opt.DisableTracing = true
opt.SkipServiceControlFilter = true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"clusters": [
{
"connectTimeout": "20s",
"http2ProtocolOptions": {},
"loadAssignment": {
"clusterName": "127.0.0.1",
"endpoints": [
Expand Down
2 changes: 1 addition & 1 deletion src/go/configgenerator/cluster_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func makeBackendCluster(opt *options.ConfigGeneratorOptions, brc *sc.BackendRout
ClusterDiscoveryType: &v2pb.Cluster_Type{v2pb.Cluster_LOGICAL_DNS},
LoadAssignment: util.CreateLoadAssignment(brc.Hostname, brc.Port),
}
isHttp2 := brc.Protocol != util.HTTP1
isHttp2 := brc.HttpProtocol == util.HTTP2 || brc.Protocol == util.GRPC

if brc.UseTLS {
var alpnProtocols []string
Expand Down
86 changes: 10 additions & 76 deletions src/go/configgenerator/cluster_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestMakeServiceControlCluster(t *testing.T) {
Environment: "http://127.0.0.1:8000",
},
},
backendProtocol: "http1",
backendProtocol: "http",
wantedCluster: v2pb.Cluster{
Name: "service-control-cluster",
ConnectTimeout: ptypes.DurationProto(5 * time.Second),
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
},
},
},
backendProtocol: "http1",
backendProtocol: "http",
wantedClusters: []*v2pb.Cluster{
{
Name: "mybackend.com:443",
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
},
},
},
backendProtocol: "http1",
backendProtocol: "http",
wantedClusters: []*v2pb.Cluster{
{
Name: "mybackend.com:80",
Expand All @@ -250,7 +250,7 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
},
},
{
desc: "Success for mixed http, https, http1, http1s, http2, http2s backends",
desc: "Success for mixed http, https backends",
fakeServiceConfig: &confpb.Service{
Name: testProjectName,
Apis: []*apipb.Api{
Expand All @@ -265,28 +265,6 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
},
},
},
{
Name: "2.cloudesf_testing_cloud_goog",
Methods: []*apipb.Method{
{
Name: "Foo",
},
{
Name: "Bar",
},
},
},
{
Name: "3.cloudesf_testing_cloud_goog",
Methods: []*apipb.Method{
{
Name: "Foo",
},
{
Name: "Bar",
},
},
},
},
Http: &annotationspb.Http{
Rules: []*annotationspb.HttpRule{
Expand All @@ -308,26 +286,10 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
Address: "https://mybackend_https.com",
Selector: "1.cloudesf_testing_cloud_goog.Bar",
},
{
Address: "http1://mybackend_http1.com",
Selector: "2.cloudesf_testing_cloud_goog.Foo",
},
{
Address: "http1s://mybackend_http1s.com",
Selector: "2.cloudesf_testing_cloud_goog.Bar",
},
{
Address: "http2://mybackend_http2.com",
Selector: "3.cloudesf_testing_cloud_goog.Foo",
},
{
Address: "http2s://mybackend_http2s.com",
Selector: "3.cloudesf_testing_cloud_goog.Bar",
},
},
},
},
backendProtocol: "http1",
backendProtocol: "http",
wantedClusters: []*v2pb.Cluster{
{
Name: "mybackend_http.com:80",
Expand All @@ -342,34 +304,6 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
LoadAssignment: util.CreateLoadAssignment("mybackend_https.com", 443),
TransportSocket: createTransportSocket("mybackend_https.com"),
},
{
Name: "mybackend_http1.com:80",
ConnectTimeout: ptypes.DurationProto(20 * time.Second),
ClusterDiscoveryType: &v2pb.Cluster_Type{v2pb.Cluster_LOGICAL_DNS},
LoadAssignment: util.CreateLoadAssignment("mybackend_http1.com", 80),
},
{
Name: "mybackend_http1s.com:443",
ConnectTimeout: ptypes.DurationProto(20 * time.Second),
ClusterDiscoveryType: &v2pb.Cluster_Type{v2pb.Cluster_LOGICAL_DNS},
LoadAssignment: util.CreateLoadAssignment("mybackend_http1s.com", 443),
TransportSocket: createTransportSocket("mybackend_http1s.com"),
},
{
Name: "mybackend_http2.com:80",
ConnectTimeout: ptypes.DurationProto(20 * time.Second),
ClusterDiscoveryType: &v2pb.Cluster_Type{v2pb.Cluster_LOGICAL_DNS},
LoadAssignment: util.CreateLoadAssignment("mybackend_http2.com", 80),
Http2ProtocolOptions: &corepb.Http2ProtocolOptions{},
},
{
Name: "mybackend_http2s.com:443",
ConnectTimeout: ptypes.DurationProto(20 * time.Second),
ClusterDiscoveryType: &v2pb.Cluster_Type{v2pb.Cluster_LOGICAL_DNS},
LoadAssignment: util.CreateLoadAssignment("mybackend_http2s.com", 443),
TransportSocket: createH2TransportSocket("mybackend_http2s.com"),
Http2ProtocolOptions: &corepb.Http2ProtocolOptions{},
},
},
},
{
Expand Down Expand Up @@ -412,7 +346,7 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
},
},
},
backendProtocol: "http1",
backendProtocol: "http",
wantedClusters: []*v2pb.Cluster{
{
Name: "mybackend.com:443",
Expand Down Expand Up @@ -457,7 +391,7 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
},
},
},
backendProtocol: "http1",
backendProtocol: "http",
wantedClusters: []*v2pb.Cluster{
{
Name: "mybackend.com:80",
Expand Down Expand Up @@ -508,7 +442,7 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
},
},
},
backendProtocol: "http1",
backendProtocol: "http",
wantedClusters: []*v2pb.Cluster{
{
Name: "mybackend_http.com:80",
Expand Down Expand Up @@ -565,7 +499,7 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
},
},
},
backendProtocol: "http1",
backendProtocol: "http",
wantedClusters: []*v2pb.Cluster{
{
Name: "mybackend.run.app:443",
Expand Down Expand Up @@ -615,7 +549,7 @@ func TestMakeBackendRoutingCluster(t *testing.T) {
},
},
},
backendProtocol: "http1",
backendProtocol: "http",
wantedError: "Invalid DnsLookupFamily: v5only;",
},
}
Expand Down
7 changes: 6 additions & 1 deletion src/go/configgenerator/listener_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,12 @@ func makeServiceControlFilter(serviceInfo *sc.ServiceInfo) *hcmpb.HttpFilter {
return nil
}

lowercaseProtocol := strings.ToLower(serviceInfo.Options.BackendProtocol)
// Only used for Report: either http or grpc
// TODO(qiwzhang): clean up to use http. Now use http1 since cc code is expecting
lowercaseProtocol := "http1"
if serviceInfo.BackendIsGrpc {
lowercaseProtocol = "grpc"
}
serviceName := serviceInfo.ServiceConfig().GetName()
service := &scpb.Service{
ServiceName: serviceName,
Expand Down
16 changes: 8 additions & 8 deletions src/go/configgenerator/listener_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ func TestBackendRoutingFilter(t *testing.T) {
}`,
},
{
desc: "Success, generate backend routing filter for http2",
protocol: "http2",
desc: "Success, generate backend routing filter for http",
protocol: "http",
fakeServiceConfig: &confpb.Service{
Name: testProjectName,
Apis: []*apipb.Api{
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestBackendRoutingFilter(t *testing.T) {
},
{
desc: "Success, generate backend routing filter with allow Cors",
protocol: "http1",
protocol: "http",
fakeServiceConfig: &confpb.Service{
Name: testProjectName,
Endpoints: []*confpb.Endpoint{
Expand Down Expand Up @@ -725,7 +725,7 @@ func TestPathMatcherFilter(t *testing.T) {
},
},
},
backendProtocol: "HTTP1",
backendProtocol: "HTTP",
healthz: "/",
wantPathMatcherFilter: `
{
Expand Down Expand Up @@ -813,7 +813,7 @@ func TestPathMatcherFilter(t *testing.T) {
},
},
},
backendProtocol: "HTTP1",
backendProtocol: "HTTP",
wantPathMatcherFilter: `
{
"name":"envoy.filters.http.path_matcher",
Expand Down Expand Up @@ -871,7 +871,7 @@ func TestPathMatcherFilter(t *testing.T) {
},
},
},
backendProtocol: "HTTP1",
backendProtocol: "HTTP",
wantPathMatcherFilter: `
{
"name":"envoy.filters.http.path_matcher",
Expand Down Expand Up @@ -944,7 +944,7 @@ func TestPathMatcherFilter(t *testing.T) {
},
},
},
backendProtocol: "http1",
backendProtocol: "http",
wantPathMatcherFilter: `
{
"name":"envoy.filters.http.path_matcher",
Expand Down Expand Up @@ -1032,7 +1032,7 @@ func TestHealthCheckFilter(t *testing.T) {
},
{
desc: "Success, generate health check filter for http",
protocol: "http2",
protocol: "http",
healthz: "/",
fakeServiceConfig: &confpb.Service{
Name: "foo.endpoints.bar.cloud.goog",
Expand Down
Loading

0 comments on commit f4a215b

Please sign in to comment.