Skip to content

Commit

Permalink
fix: match serviceName in tracing with mergedGateways topology (#3214)
Browse files Browse the repository at this point in the history
* fix: match serviceName in tracing with mergedGateways topology

Signed-off-by: Karol Szwaj <[email protected]>

* add testdata

Signed-off-by: Karol Szwaj <[email protected]>

---------

Signed-off-by: Karol Szwaj <[email protected]>
Co-authored-by: zirain <[email protected]>
  • Loading branch information
cnvergence and zirain authored Apr 19, 2024
1 parent db41b16 commit e1a3ab4
Show file tree
Hide file tree
Showing 6 changed files with 859 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
envoyproxy:
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
namespace: envoy-gateway
name: test
spec:
mergeGateways: true
telemetry:
tracing:
samplingRate: 100
provider:
host: otel-collector.monitoring.svc.cluster.local
port: 4317
type: OpenTelemetry
gateways:
- apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
hostname: "*.envoyproxy.io"
allowedRoutes:
namespaces:
from: All
- apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: gateway-2
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http-2
port: 8888
protocol: HTTP
- name: http-3
hostname: example.com
port: 8888
protocol: HTTP
allowedRoutes:
namespaces:
from: All
httpRoutes:
- apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
namespace: default
name: httproute-1
spec:
hostnames:
- gateway.envoyproxy.io
parentRefs:
- namespace: envoy-gateway
name: gateway-1
sectionName: http
rules:
- matches:
- path:
value: "/"
backendRefs:
- name: service-1
port: 8080
- apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
namespace: default
name: httproute-2
spec:
hostnames:
- example.com
parentRefs:
- namespace: envoy-gateway
name: gateway-2
sectionName: http-3
rules:
- matches:
- path:
value: "/"
backendRefs:
- name: service-2
port: 8080
Loading

0 comments on commit e1a3ab4

Please sign in to comment.