Skip to content

Commit

Permalink
Move code out of balancer/xds.
Browse files Browse the repository at this point in the history
We will have a root level xds/ directory which will eventually contain
all xDS implementation including balancer, resolver, client etc.

The new structure looks something like this:

grpc/
|
+--xds/
    |
    +--internal/
    |  |
    |  +--balancer/
    |     |
    |     +--edsbalancer/
    |     |
    |     +--lrs/
    |     |
    |     +--orca/
    |
    +--experimental/

Users need to import grpc/xds/experimental package to get all xds
functionality, and this will eventually be moved to grpc/xds.

Also, moved grpc/balancer/internal/wrr to grpc/internal/wrr.
  • Loading branch information
easwars committed Aug 7, 2019
1 parent fde0cae commit 72fe8ff
Show file tree
Hide file tree
Showing 53 changed files with 162 additions and 132 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions vet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ staticcheck -go 1.9 -checks 'inherit,-ST1015' -ignore '
google.golang.org/grpc/balancer.go:SA1019
google.golang.org/grpc/balancer/grpclb/grpclb_remote_balancer.go:SA1019
google.golang.org/grpc/balancer/roundrobin/roundrobin_test.go:SA1019
google.golang.org/grpc/balancer/xds/edsbalancer/balancergroup.go:SA1019
google.golang.org/grpc/balancer/xds/xds.go:SA1019
google.golang.org/grpc/balancer/xds/xds_client.go:SA1019
google.golang.org/grpc/xds/internal/balancer/edsbalancer/balancergroup.go:SA1019
google.golang.org/grpc/xds/internal/balancer/xds.go:SA1019
google.golang.org/grpc/xds/internal/balancer/xds_client.go:SA1019
google.golang.org/grpc/balancer_conn_wrappers.go:SA1019
google.golang.org/grpc/balancer_test.go:SA1019
google.golang.org/grpc/benchmark/benchmain/main.go:SA1019
Expand Down
32 changes: 32 additions & 0 deletions xds/experimental/xds_experimental.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

// Package experimental contains xds implementation, still in experimental
// state. Users only need to import this package to get all xds functionality.
// Things are expected to change fast until we get to a stable state, at
// which point, all this will be moved to the xds package.
package experimental

import (
"google.golang.org/grpc/balancer"
xdsbalancer "google.golang.org/grpc/xds/internal/balancer"
)

func init() {
balancer.Register(xdsbalancer.NewBalancerBuilder())
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (

"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/base"
"google.golang.org/grpc/balancer/internal/wrr"
"google.golang.org/grpc/balancer/xds/internal"
orcapb "google.golang.org/grpc/balancer/xds/internal/proto/udpa/data/orca/v1/orca_load_report"
"google.golang.org/grpc/balancer/xds/lrs"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal/wrr"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/xds/internal"
"google.golang.org/grpc/xds/internal/balancer/lrs"
orcapb "google.golang.org/grpc/xds/internal/proto/udpa/data/orca/v1/orca_load_report"
)

type pickerState struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (

"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/roundrobin"
"google.golang.org/grpc/balancer/xds/internal"
orcapb "google.golang.org/grpc/balancer/xds/internal/proto/udpa/data/orca/v1/orca_load_report"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/xds/internal"
orcapb "google.golang.org/grpc/xds/internal/proto/udpa/data/orca/v1/orca_load_report"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ import (
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/roundrobin"
"google.golang.org/grpc/balancer/weightedroundrobin"
"google.golang.org/grpc/balancer/xds/internal"
edspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/eds"
endpointpb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/endpoint/endpoint"
percentpb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/type/percent"
"google.golang.org/grpc/balancer/xds/lrs"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/status"
"google.golang.org/grpc/xds/internal"
"google.golang.org/grpc/xds/internal/balancer/lrs"
edspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/eds"
endpointpb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/endpoint/endpoint"
percentpb "google.golang.org/grpc/xds/internal/proto/envoy/type/percent"
)

type localityConfig struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import (
typespb "github.com/golang/protobuf/ptypes/wrappers"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/roundrobin"
"google.golang.org/grpc/balancer/xds/internal"
addresspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/core/address"
basepb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/core/base"
edspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/eds"
endpointpb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/endpoint/endpoint"
percentpb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/type/percent"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/xds/internal"
addresspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/core/address"
basepb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/core/base"
edspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/eds"
endpointpb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/endpoint/endpoint"
percentpb "google.golang.org/grpc/xds/internal/proto/envoy/type/percent"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/xds/internal"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/xds/internal"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package edsbalancer

import "google.golang.org/grpc/balancer/internal/wrr"
import "google.golang.org/grpc/internal/wrr"

type dropper struct {
// Drop rate will be numerator/denominator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"sync"
"testing"

"google.golang.org/grpc/balancer/internal/wrr"
"google.golang.org/grpc/internal/wrr"
)

// testWRR is a deterministic WRR implementation.
Expand Down
10 changes: 5 additions & 5 deletions balancer/xds/lrs/lrs.go → xds/internal/balancer/lrs/lrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
"github.com/golang/protobuf/ptypes"
structpb "github.com/golang/protobuf/ptypes/struct"
"google.golang.org/grpc"
"google.golang.org/grpc/balancer/xds/internal"
basepb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/core/base"
loadreportpb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/endpoint/load_report"
lrsgrpc "google.golang.org/grpc/balancer/xds/internal/proto/envoy/service/load_stats/v2/lrs"
lrspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/service/load_stats/v2/lrs"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal/backoff"
"google.golang.org/grpc/xds/internal"
basepb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/core/base"
loadreportpb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/endpoint/load_report"
lrsgrpc "google.golang.org/grpc/xds/internal/proto/envoy/service/load_stats/v2/lrs"
lrspb "google.golang.org/grpc/xds/internal/proto/envoy/service/load_stats/v2/lrs"
)

const negativeOneUInt64 = ^uint64(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import (
structpb "github.com/golang/protobuf/ptypes/struct"
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc"
"google.golang.org/grpc/balancer/xds/internal"
basepb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/core/base"
loadreportpb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/endpoint/load_report"
lrsgrpc "google.golang.org/grpc/balancer/xds/internal/proto/envoy/service/load_stats/v2/lrs"
lrspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/service/load_stats/v2/lrs"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/grpc/xds/internal"
basepb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/core/base"
loadreportpb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/endpoint/load_report"
lrsgrpc "google.golang.org/grpc/xds/internal/proto/envoy/service/load_stats/v2/lrs"
lrspb "google.golang.org/grpc/xds/internal/proto/envoy/service/load_stats/v2/lrs"
)

const testService = "grpc.service.test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package orca

import (
"github.com/golang/protobuf/proto"
orcapb "google.golang.org/grpc/balancer/xds/internal/proto/udpa/data/orca/v1/orca_load_report"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal/balancerload"
"google.golang.org/grpc/metadata"
orcapb "google.golang.org/grpc/xds/internal/proto/udpa/data/orca/v1/orca_load_report"
)

const mdKey = "X-Endpoint-Load-Metrics-Bin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"testing"

"github.com/golang/protobuf/proto"
orcapb "google.golang.org/grpc/balancer/xds/internal/proto/udpa/data/orca/v1/orca_load_report"
"google.golang.org/grpc/metadata"
orcapb "google.golang.org/grpc/xds/internal/proto/udpa/data/orca/v1/orca_load_report"
)

var (
Expand Down
21 changes: 9 additions & 12 deletions balancer/xds/xds.go → xds/internal/balancer/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*
*/

// Package xds implements a balancer that communicates with a remote balancer using the Envoy xDS
// protocol.
package xds
// Package balancer contains xds balancer implementation.
package balancer

import (
"context"
Expand All @@ -30,14 +29,14 @@ import (

"github.com/golang/protobuf/proto"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/xds/edsbalancer"
cdspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/cds"
edspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/eds"
"google.golang.org/grpc/balancer/xds/lrs"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/serviceconfig"
"google.golang.org/grpc/xds/internal/balancer/edsbalancer"
"google.golang.org/grpc/xds/internal/balancer/lrs"
cdspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/cds"
edspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/eds"
)

const (
Expand All @@ -55,13 +54,11 @@ var (
}
)

func init() {
balancer.Register(newXDSBalancerBuilder())
}

type xdsBalancerBuilder struct{}

func newXDSBalancerBuilder() balancer.Builder {
// NewBalancerBuilder creates a new implementation of the balancer.Builder
// interface for the xDS balancer.
func NewBalancerBuilder() balancer.Builder {
return &xdsBalancerBuilder{}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

package xds
package balancer

import (
"context"
Expand All @@ -28,16 +28,16 @@ import (
structpb "github.com/golang/protobuf/ptypes/struct"
"google.golang.org/grpc"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/xds/internal"
cdspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/cds"
basepb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/core/base"
discoverypb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/discovery"
edspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/eds"
adsgrpc "google.golang.org/grpc/balancer/xds/internal/proto/envoy/service/discovery/v2/ads"
"google.golang.org/grpc/balancer/xds/lrs"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal/backoff"
"google.golang.org/grpc/internal/channelz"
"google.golang.org/grpc/xds/internal"
"google.golang.org/grpc/xds/internal/balancer/lrs"
cdspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/cds"
basepb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/core/base"
discoverypb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/discovery"
edspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/eds"
adsgrpc "google.golang.org/grpc/xds/internal/proto/envoy/service/discovery/v2/ads"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

package xds
package balancer

import (
"context"
Expand All @@ -33,18 +33,18 @@ import (
wrpb "github.com/golang/protobuf/ptypes/wrappers"
"google.golang.org/grpc"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/xds/internal"
cdspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/cds"
addresspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/core/address"
basepb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/core/base"
discoverypb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/discovery"
edspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/eds"
endpointpb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/endpoint/endpoint"
adsgrpc "google.golang.org/grpc/balancer/xds/internal/proto/envoy/service/discovery/v2/ads"
lrsgrpc "google.golang.org/grpc/balancer/xds/internal/proto/envoy/service/load_stats/v2/lrs"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/status"
"google.golang.org/grpc/xds/internal"
cdspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/cds"
addresspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/core/address"
basepb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/core/base"
discoverypb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/discovery"
edspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/eds"
endpointpb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/endpoint/endpoint"
adsgrpc "google.golang.org/grpc/xds/internal/proto/envoy/service/discovery/v2/ads"
lrsgrpc "google.golang.org/grpc/xds/internal/proto/envoy/service/load_stats/v2/lrs"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

package xds
package balancer

import (
"io"
Expand All @@ -29,13 +29,13 @@ import (
structpb "github.com/golang/protobuf/ptypes/struct"
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/xds/internal"
basepb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/core/base"
lrsgrpc "google.golang.org/grpc/balancer/xds/internal/proto/envoy/service/load_stats/v2/lrs"
lrspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/service/load_stats/v2/lrs"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/status"
"google.golang.org/grpc/xds/internal"
basepb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/core/base"
lrsgrpc "google.golang.org/grpc/xds/internal/proto/envoy/service/load_stats/v2/lrs"
lrspb "google.golang.org/grpc/xds/internal/proto/envoy/service/load_stats/v2/lrs"
)

type lrsServer struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

package xds
package balancer

import (
"encoding/json"
Expand All @@ -27,18 +27,19 @@ import (

"github.com/golang/protobuf/proto"
"google.golang.org/grpc/balancer"
discoverypb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/discovery"
edspb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/eds"
"google.golang.org/grpc/balancer/xds/lrs"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/internal/leakcheck"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/xds/internal/balancer/lrs"
discoverypb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/discovery"
edspb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/eds"
)

var lbABuilder = &balancerABuilder{}

func init() {
balancer.Register(&xdsBalancerBuilder{})
balancer.Register(lbABuilder)
balancer.Register(&balancerBBuilder{})
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package internal
import (
"fmt"

basepb "google.golang.org/grpc/balancer/xds/internal/proto/envoy/api/v2/core/base"
basepb "google.golang.org/grpc/xds/internal/proto/envoy/api/v2/core/base"
)

// Locality is xds.Locality without XXX fields, so it can be used as map
Expand Down
Loading

0 comments on commit 72fe8ff

Please sign in to comment.