Skip to content

Commit

Permalink
traffic mirroing control plane impl (#220)
Browse files Browse the repository at this point in the history
Signed-off-by: Xunzhuo <mixdeers@gmail.com>
  • Loading branch information
Xunzhuo authored May 16, 2022
1 parent 98f1779 commit 9ed629f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ BINARY_NAME?=$(OUT)/aeraki
BINARY_NAME_DARWIN?=$(BINARY_NAME)-darwin
MAIN_PATH_CONSUL_MCP=./cmd/aeraki/main.go

.DEFAULT_GOAL := build

install:
bash demo/install-aeraki.sh
install-for-tcm:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ replace github.com/imdario/mergo => github.com/imdario/mergo v0.3.5
//replace github.com/aeraki-mesh/meta-protocol-control-plane-api => github.com/aeraki-mesh/meta-protocol-control-plane-api v0.0.0-20220325074604-63adf119a7bc

require (
github.com/aeraki-mesh/meta-protocol-control-plane-api v1.0.6
github.com/aeraki-mesh/meta-protocol-control-plane-api v0.0.0-20220515142731-39ec5b3fe065
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/envoyproxy/go-control-plane v0.10.2-0.20211130161932-f62def555c97
github.com/gogo/protobuf v1.3.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/aeraki-mesh/meta-protocol-control-plane-api v1.0.6 h1:p8KjPd8MRHw4n9g5b0ZzXAhhxPI5BGOpQBivsM4rdHY=
github.com/aeraki-mesh/meta-protocol-control-plane-api v1.0.6/go.mod h1:kBlB/k9X2I3yO6mZyS1tcdUfJy3cz4u+z97kmpo8qD4=
github.com/aeraki-mesh/meta-protocol-control-plane-api v0.0.0-20220515142731-39ec5b3fe065 h1:tCN/qxAscDP1Kr84avXfHGjansdsX803pq++PIZNBps=
github.com/aeraki-mesh/meta-protocol-control-plane-api v0.0.0-20220515142731-39ec5b3fe065/go.mod h1:kBlB/k9X2I3yO6mZyS1tcdUfJy3cz4u+z97kmpo8qD4=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
github.com/ahmetb/gen-crd-api-reference-docs v0.3.0/go.mod h1:TdjdkYhlOifCQWPs1UdTma97kQQMozf5h26hTuG70u8=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down
13 changes: 13 additions & 0 deletions pkg/xds/cache_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

metaprotocolapi "github.com/aeraki-mesh/aeraki/api/metaprotocol/v1alpha1"
metaprotocol "github.com/aeraki-mesh/aeraki/client-go/pkg/apis/metaprotocol/v1alpha1"
corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
istioconfig "istio.io/istio/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -265,6 +266,18 @@ func (c *CacheMgr) constructAction(port *networking.Port,
},
}
}

if route.Mirror != nil {
routeAction.RequestMirrorPolicies = []*metaroute.RouteAction_RequestMirrorPolicy{
{
Cluster: model.BuildClusterName(model.TrafficDirectionOutbound, route.Mirror.Subset,
route.Mirror.Host, int(route.Mirror.Port.Number)),
RuntimeFraction: &corev3.RuntimeFractionalPercent{
DefaultValue: translatePercentToFractionalPercent(route.MirrorPercentage.Value),
},
},
}
}
}
if dr != nil && dr.Spec.TrafficPolicy != nil && dr.Spec.TrafficPolicy.LoadBalancer != nil && dr.Spec.TrafficPolicy.
LoadBalancer.GetConsistentHash() != nil && dr.Spec.TrafficPolicy.
Expand Down
17 changes: 17 additions & 0 deletions pkg/xds/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strconv"
"time"

typev3 "github.com/envoyproxy/go-control-plane/envoy/type/v3"
"github.com/envoyproxy/go-control-plane/pkg/resource/v3"

httpcore "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
Expand Down Expand Up @@ -69,6 +70,15 @@ func metaProtocolRoute2HttpRoute(metaRoute *metaroute.RouteConfiguration) *httpr
}
}

routeAction.RequestMirrorPolicies = make([]*httproute.
RouteAction_RequestMirrorPolicy, len(route.Route.RequestMirrorPolicies))
for i, mirrorPolicy := range route.Route.RequestMirrorPolicies {
routeAction.RequestMirrorPolicies[i] = &httproute.RouteAction_RequestMirrorPolicy{
Cluster: mirrorPolicy.Cluster,
RuntimeFraction: mirrorPolicy.RuntimeFraction,
}
}

if route.Route.HashPolicy != nil && len(route.Route.HashPolicy) > 0 {
routeAction.HashPolicy = []*httproute.RouteAction_HashPolicy{
{
Expand Down Expand Up @@ -178,3 +188,10 @@ func isCatchAllHeaderMatch(in *userapi.StringMatch) bool {

return catchall
}

func translatePercentToFractionalPercent(p float64) *typev3.FractionalPercent {
return &typev3.FractionalPercent{
Numerator: uint32(p * 10000),
Denominator: typev3.FractionalPercent_MILLION,
}
}

0 comments on commit 9ed629f

Please sign in to comment.