Skip to content

Commit

Permalink
fix: match serviceName in tracing with mergedGateways topology
Browse files Browse the repository at this point in the history
Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
  • Loading branch information
cnvergence committed Apr 17, 2024
1 parent a7b4b55 commit 70be6a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
20 changes: 14 additions & 6 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR XdsIRMap
if resources.EnvoyProxy != nil {
infraIR[irKey].Proxy.Config = resources.EnvoyProxy
}

xdsIR[irKey].AccessLog = processAccessLog(infraIR[irKey].Proxy.Config)
xdsIR[irKey].Tracing = processTracing(gateway.Gateway, infraIR[irKey].Proxy.Config)
xdsIR[irKey].Metrics = processMetrics(infraIR[irKey].Proxy.Config)
t.processProxyObservability(gateway.Gateway, xdsIR[irKey], infraIR[irKey].Proxy.Config)

for _, listener := range gateway.listeners {
// Process protocol & supported kinds
Expand Down Expand Up @@ -130,6 +127,12 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR XdsIRMap
}
}

func (t *Translator) processProxyObservability(gw *gwapiv1.Gateway, xdsIR *ir.Xds, envoyProxy *egv1a1.EnvoyProxy) {
xdsIR.AccessLog = processAccessLog(envoyProxy)
xdsIR.Tracing = processTracing(gw, envoyProxy, t.MergeGateways)
xdsIR.Metrics = processMetrics(envoyProxy)
}

func (t *Translator) processInfraIRListener(listener *ListenerContext, infraIR InfraIRMap, irKey string, servicePort *protocolPort) {
var proto ir.ProtocolType
switch listener.Protocol {
Expand Down Expand Up @@ -242,7 +245,7 @@ func processAccessLog(envoyproxy *egv1a1.EnvoyProxy) *ir.AccessLog {
return irAccessLog
}

func processTracing(gw *gwapiv1.Gateway, envoyproxy *egv1a1.EnvoyProxy) *ir.Tracing {
func processTracing(gw *gwapiv1.Gateway, envoyproxy *egv1a1.EnvoyProxy, mergeGateways bool) *ir.Tracing {
if envoyproxy == nil ||
envoyproxy.Spec.Telemetry == nil ||
envoyproxy.Spec.Telemetry.Tracing == nil {
Expand All @@ -265,8 +268,13 @@ func processTracing(gw *gwapiv1.Gateway, envoyproxy *egv1a1.EnvoyProxy) *ir.Trac
samplingRate = float64(*tracing.SamplingRate)
}

serviceName := naming.ServiceName(utils.NamespacedName(gw))
if mergeGateways {
serviceName = string(gw.Spec.GatewayClassName)
}

return &ir.Tracing{
ServiceName: naming.ServiceName(utils.NamespacedName(gw)),
ServiceName: serviceName,
Host: host,
Port: port,
SamplingRate: samplingRate,
Expand Down
30 changes: 27 additions & 3 deletions internal/gatewayapi/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (

func TestProcessTracing(t *testing.T) {
cases := []struct {
gw gwapiv1.Gateway
proxy *egcfgv1a1.EnvoyProxy
gw gwapiv1.Gateway
proxy *egcfgv1a1.EnvoyProxy
mergedgw bool

expected *ir.Tracing
}{
Expand All @@ -44,6 +45,29 @@ func TestProcessTracing(t *testing.T) {
SamplingRate: 100.0,
},
},
{
gw: gwapiv1.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-gw",
Namespace: "fake-ns",
},
Spec: gwapiv1.GatewaySpec{
GatewayClassName: "fake-gateway-class",
},
},
proxy: &egcfgv1a1.EnvoyProxy{
Spec: egcfgv1a1.EnvoyProxySpec{
Telemetry: &egcfgv1a1.ProxyTelemetry{
Tracing: &egcfgv1a1.ProxyTracing{},
},
},
},
mergedgw: true,
expected: &ir.Tracing{
ServiceName: "fake-gateway-class",
SamplingRate: 100.0,
},
},
{
gw: gwapiv1.Gateway{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -149,7 +173,7 @@ func TestProcessTracing(t *testing.T) {
for _, c := range cases {
c := c
t.Run("", func(t *testing.T) {
got := processTracing(&c.gw, c.proxy)
got := processTracing(&c.gw, c.proxy, c.mergedgw)
assert.Equal(t, c.expected, got)
})
}
Expand Down

0 comments on commit 70be6a5

Please sign in to comment.