From 959d9913b891ecb0f67bd564a6591df5685e786c Mon Sep 17 00:00:00 2001 From: freddygv Date: Thu, 3 Sep 2020 16:19:58 -0600 Subject: [PATCH] Add server receiver to routes and log tgw err --- agent/xds/routes.go | 10 +++++++--- agent/xds/routes_test.go | 7 ++++++- agent/xds/server.go | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/agent/xds/routes.go b/agent/xds/routes.go index 0f73e2bb47..3c3e79222f 100644 --- a/agent/xds/routes.go +++ b/agent/xds/routes.go @@ -3,6 +3,7 @@ package xds import ( "errors" "fmt" + "github.com/hashicorp/consul/logging" "net" "strings" @@ -18,7 +19,7 @@ import ( // routesFromSnapshot returns the xDS API representation of the "routes" in the // snapshot. -func routesFromSnapshot(cInfo connectionInfo, cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, error) { +func (s *Server) routesFromSnapshot(cInfo connectionInfo, cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, error) { if cfgSnap == nil { return nil, errors.New("nil config given") } @@ -29,7 +30,7 @@ func routesFromSnapshot(cInfo connectionInfo, cfgSnap *proxycfg.ConfigSnapshot) case structs.ServiceKindIngressGateway: return routesForIngressGateway(cInfo, cfgSnap.IngressGateway.Upstreams, cfgSnap.IngressGateway.DiscoveryChain) case structs.ServiceKindTerminatingGateway: - return routesFromSnapshotTerminatingGateway(cInfo, cfgSnap) + return s.routesFromSnapshotTerminatingGateway(cInfo, cfgSnap) default: return nil, fmt.Errorf("Invalid service kind: %v", cfgSnap.Kind) } @@ -37,10 +38,11 @@ func routesFromSnapshot(cInfo connectionInfo, cfgSnap *proxycfg.ConfigSnapshot) // routesFromSnapshotTerminatingGateway returns the xDS API representation of the "routes" in the snapshot. // For any HTTP service we will return a default route. -func routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, error) { +func (s *Server) routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, error) { if cfgSnap == nil { return nil, errors.New("nil config given") } + logger := s.Logger.Named(logging.TerminatingGateway) var resources []proto.Message for _, svc := range cfgSnap.TerminatingGateway.ValidServices() { @@ -69,6 +71,7 @@ func routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap *proxycfg.Co } route, err := makeNamedDefaultRouteWithLB(clusterName, lb) if err != nil { + logger.Error("failed to make route", "cluster", clusterName, "error", err) continue } resources = append(resources, route) @@ -78,6 +81,7 @@ func routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap *proxycfg.Co clusterName = connect.ServiceSNI(svc.Name, name, svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain) route, err := makeNamedDefaultRouteWithLB(clusterName, lb) if err != nil { + logger.Error("failed to make route", "cluster", clusterName, "error", err) continue } resources = append(resources, route) diff --git a/agent/xds/routes_test.go b/agent/xds/routes_test.go index 5181023215..600d8ee6d5 100644 --- a/agent/xds/routes_test.go +++ b/agent/xds/routes_test.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/consul/agent/proxycfg" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/xds/proxysupport" + "github.com/hashicorp/consul/sdk/testutil" testinf "github.com/mitchellh/go-testing-interface" "github.com/stretchr/testify/require" ) @@ -257,11 +258,15 @@ func TestRoutesFromSnapshot(t *testing.T) { tt.setup(snap) } + logger := testutil.Logger(t) + s := Server{ + Logger: logger, + } cInfo := connectionInfo{ Token: "my-token", ProxyFeatures: sf, } - routes, err := routesFromSnapshot(cInfo, snap) + routes, err := s.routesFromSnapshot(cInfo, snap) require.NoError(err) sort.Slice(routes, func(i, j int) bool { return routes[i].(*envoy.RouteConfiguration).Name < routes[j].(*envoy.RouteConfiguration).Name diff --git a/agent/xds/server.go b/agent/xds/server.go index 8eaa299d91..ed148da495 100644 --- a/agent/xds/server.go +++ b/agent/xds/server.go @@ -218,7 +218,7 @@ func (s *Server) process(stream ADSStream, reqCh <-chan *envoy.DiscoveryRequest) }, RouteType: { typeURL: RouteType, - resources: routesFromSnapshot, + resources: s.routesFromSnapshot, stream: stream, allowEmptyFn: func(cfgSnap *proxycfg.ConfigSnapshot) bool { return cfgSnap.Kind == structs.ServiceKindIngressGateway