From 00d62e62f2dd3fc2a9946b7aee484985d994ce11 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Thu, 30 Jan 2020 22:58:52 +0100 Subject: [PATCH] Move to version 3 of the API Signed-off-by: Miek Gieben --- go.mod | 3 +-- go.sum | 6 ++++++ plugin/traffic/README.md | 12 ++---------- plugin/traffic/xds/assignment.go | 12 ++++++------ plugin/traffic/xds/client.go | 23 +++++++++++------------ 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index 60b97b1e8..208b3d781 100644 --- a/go.mod +++ b/go.mod @@ -16,11 +16,10 @@ require ( github.com/coreos/go-systemd v0.0.0-20190212144455-93d5ec2c7f76 // indirect github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect github.com/dnstap/golang-dnstap v0.0.0-20170829151710-2cf77a2b5e11 - github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473 + github.com/envoyproxy/go-control-plane v0.9.3-0.20200130194102-ccc9f873c822 github.com/farsightsec/golang-framestream v0.0.0-20181102145529-8a0cb8ba8710 github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect github.com/golang/protobuf v1.3.2 - github.com/google/go-cmp v0.3.1 github.com/googleapis/gnostic v0.2.0 // indirect github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 github.com/imdario/mergo v0.3.7 // indirect diff --git a/go.sum b/go.sum index be128c24a..13d1f434c 100644 --- a/go.sum +++ b/go.sum @@ -84,6 +84,8 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.10.2/go.mod h1:qhVI5MKwBGhdNU89ZRz2plgYutcJ5PCekLxXn56w6SY= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f h1:WBZRG4aNOuI15bLRrCgN8fCq8E5Xuty6jGbmSNEvSsU= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa h1:OaNxuTZr7kxeODyLWsRMC+OD03aFUH+mW6r2d+MWa5Y= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/coredns/federation v0.0.0-20190818181423-e032b096babe h1:ND08lR/TclI9W4dScCwdRESOacCCdF3FkuB5pBIOv1U= @@ -124,8 +126,11 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473 h1:4cmBvAEBNJaGARUEs3/suWRyfyBfhf7I60WBZq+bv2w= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.3-0.20200130194102-ccc9f873c822 h1:X+GjtbvVIpRg4PT7OXOElI1SgdZRYSCYbox7ZIerTJM= +github.com/envoyproxy/go-control-plane v0.9.3-0.20200130194102-ccc9f873c822/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v4.2.0+incompatible h1:fUDGZCv/7iAN7u0puUVhvKCcsR6vRfwrJatElLBEf0I= @@ -565,6 +570,7 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/DataDog/dd-trace-go.v1 v1.20.0 h1:OUvLkkEtg2HpDS9g+GeNKDnJtx9zVbqCh2hGH7jHHfg= diff --git a/plugin/traffic/README.md b/plugin/traffic/README.md index e8bec7fcb..73d14575a 100644 --- a/plugin/traffic/README.md +++ b/plugin/traffic/README.md @@ -41,6 +41,8 @@ responding server (CoreDNS) has no idea how many clients use this resolver. So r +1 on the CoreDNS side can results in anything from 1 to 1000+ of queries on the endpoint, making the load reporting from *traffic* highly inaccurate. +*Traffic* implements version 3 of the xDS API. + ## Syntax ~~~ @@ -155,16 +157,6 @@ lb.example.org { This will load balance any names under `lb.example.org` using the data from the manager running on localhost on port 18000. The node ID will be `test-id` and no TLS will be used. -## Also See - -The following documents provide some background on Envoy's control plane. - - * - - * - - * - ## Bugs Priority and locality information from ClusterLoadAssignments is not used. Multiple **TO** addresses diff --git a/plugin/traffic/xds/assignment.go b/plugin/traffic/xds/assignment.go index 3608f9fbb..dcb803841 100644 --- a/plugin/traffic/xds/assignment.go +++ b/plugin/traffic/xds/assignment.go @@ -5,8 +5,8 @@ import ( "net" "sync" - xdspb "github.com/envoyproxy/go-control-plane/envoy/api/v2" - corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" + corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" + endpointpb "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3" ) // SocketAddress holds a corepb.SocketAddress. @@ -22,16 +22,16 @@ func (s *SocketAddress) Port() uint16 { return uint16(s.GetPortValue()) } type assignment struct { mu sync.RWMutex - cla map[string]*xdspb.ClusterLoadAssignment + cla map[string]*endpointpb.ClusterLoadAssignment } // NewAssignment returns a pointer to an assignment. func NewAssignment() *assignment { - return &assignment{cla: make(map[string]*xdspb.ClusterLoadAssignment)} + return &assignment{cla: make(map[string]*endpointpb.ClusterLoadAssignment)} } // SetClusterLoadAssignment sets the assignment for the cluster to cla. -func (a *assignment) SetClusterLoadAssignment(cluster string, cla *xdspb.ClusterLoadAssignment) { +func (a *assignment) SetClusterLoadAssignment(cluster string, cla *endpointpb.ClusterLoadAssignment) { // If cla is nil we just found a cluster, check if we already know about it, or if we need to make a new entry. a.mu.Lock() defer a.mu.Unlock() @@ -48,7 +48,7 @@ func (a *assignment) SetClusterLoadAssignment(cluster string, cla *xdspb.Cluster } // ClusterLoadAssignment returns the assignment for the cluster or nil if there is none. -func (a *assignment) ClusterLoadAssignment(cluster string) *xdspb.ClusterLoadAssignment { +func (a *assignment) ClusterLoadAssignment(cluster string) *endpointpb.ClusterLoadAssignment { a.mu.RLock() cla, ok := a.cla[cluster] a.mu.RUnlock() diff --git a/plugin/traffic/xds/client.go b/plugin/traffic/xds/client.go index 80db96682..e9b593412 100644 --- a/plugin/traffic/xds/client.go +++ b/plugin/traffic/xds/client.go @@ -30,9 +30,10 @@ import ( "github.com/coredns/coredns/coremain" clog "github.com/coredns/coredns/plugin/pkg/log" - xdspb "github.com/envoyproxy/go-control-plane/envoy/api/v2" - corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" - adsgrpc "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v2" + clusterpb "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3" + corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" + endpointpb "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3" + xdspb "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3" "github.com/golang/protobuf/ptypes" structpb "github.com/golang/protobuf/ptypes/struct" "google.golang.org/grpc" @@ -45,7 +46,7 @@ const ( edsURL = "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment" ) -type adsStream adsgrpc.AggregatedDiscoveryService_StreamAggregatedResourcesClient +type adsStream xdspb.AggregatedDiscoveryService_StreamAggregatedResourcesClient // Client talks to the grpc manager's endpoint to get load assignments. type Client struct { @@ -72,15 +73,13 @@ func New(addr, node string, opts ...grpc.DialOption) (*Client, error) { c := &Client{cc: cc, to: addr, node: &corepb.Node{Id: node, Metadata: &structpb.Struct{ Fields: map[string]*structpb.Value{ - "HOSTNAME": { - Kind: &structpb.Value_StringValue{StringValue: hostname}, - }, + "HOSTNAME": {Kind: &structpb.Value_StringValue{StringValue: hostname}}, + "BUILDVERSION": {Kind: &structpb.Value_StringValue{StringValue: coremain.CoreVersion}}, }, }, - BuildVersion: coremain.CoreVersion, }, } - c.assignments = &assignment{cla: make(map[string]*xdspb.ClusterLoadAssignment)} + c.assignments = &assignment{cla: make(map[string]*endpointpb.ClusterLoadAssignment)} c.version, c.nonce = make(map[string]string), make(map[string]string) c.ctx, c.cancel = context.WithCancel(context.Background()) @@ -100,7 +99,7 @@ func (c *Client) Run() { default: } - cli := adsgrpc.NewAggregatedDiscoveryServiceClient(c.cc) + cli := xdspb.NewAggregatedDiscoveryServiceClient(c.cc) stream, err := cli.StreamAggregatedResources(c.ctx) if err != nil { log.Debug(err) @@ -183,7 +182,7 @@ func (c *Client) receive(stream adsStream) error { log.Debugf("Failed to unmarshal cluster discovery: %s", err) continue } - cluster, ok := any.Message.(*xdspb.Cluster) + cluster, ok := any.Message.(*clusterpb.Cluster) if !ok { continue } @@ -208,7 +207,7 @@ func (c *Client) receive(stream adsStream) error { log.Debugf("Failed to unmarshal endpoint discovery: %s", err) continue } - cla, ok := any.Message.(*xdspb.ClusterLoadAssignment) + cla, ok := any.Message.(*endpointpb.ClusterLoadAssignment) if !ok { continue }