diff --git a/internal/gatewayapi/listener.go b/internal/gatewayapi/listener.go index 07d71bfd172b..3c7aa41945c6 100644 --- a/internal/gatewayapi/listener.go +++ b/internal/gatewayapi/listener.go @@ -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 @@ -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 { @@ -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 { @@ -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, diff --git a/internal/gatewayapi/listener_test.go b/internal/gatewayapi/listener_test.go index 6cdd4a696593..92384872bbc3 100644 --- a/internal/gatewayapi/listener_test.go +++ b/internal/gatewayapi/listener_test.go @@ -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 }{ @@ -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{ @@ -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) }) }