Skip to content

Commit

Permalink
Reconcile backendRefs for metrics sinks and tracing on envoyproxies
Browse files Browse the repository at this point in the history
Signed-off-by: David Alger <davidmalger@gmail.com>
  • Loading branch information
davidalger committed Apr 15, 2024
1 parent ef45d25 commit da8d2d3
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 31 deletions.
50 changes: 36 additions & 14 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,31 +795,53 @@ func (r *gatewayAPIReconciler) processEnvoyProxies(ctx context.Context, managedG
// processEnvoyProxyObjectRefs adds the referenced resources in EnvoyProxies
// to the resourceTree
// - BackendRefs for AccessLog
// - BackendRefs for Metrics
// - BackendRefs for Tracing
func (r *gatewayAPIReconciler) processEnvoyProxyObjectRefs(resourceTree *gatewayapi.Resources, resourceMap *resourceMappings) {
if resourceTree.EnvoyProxy == nil {
return
}
envoyproxy := resourceTree.EnvoyProxy

if envoyproxy.Spec.Telemetry != nil && envoyproxy.Spec.Telemetry.AccessLog != nil {
if envoyproxy.Spec.Telemetry != nil {
backendRefs := []egv1a1.BackendRef{}

// Add the referenced BackendRefs in AccessLog to Maps for later processing
accessLog := envoyproxy.Spec.Telemetry.AccessLog
for _, settings := range accessLog.Settings {
for _, sink := range settings.Sinks {
if sink.OpenTelemetry != nil {
for _, backendRef := range sink.OpenTelemetry.BackendRefs {
backendNamespace := gatewayapi.NamespaceDerefOr(backendRef.Namespace, envoyproxy.Namespace)
resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{
Group: backendRef.Group,
Kind: backendRef.Kind,
Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace),
Name: backendRef.Name,
}] = struct{}{}
// Collect BackendRefs for access log sinks
if envoyproxy.Spec.Telemetry.AccessLog != nil {
for _, settings := range envoyproxy.Spec.Telemetry.AccessLog.Settings {
for _, sink := range settings.Sinks {
if sink.OpenTelemetry != nil {
backendRefs = append(backendRefs, sink.OpenTelemetry.BackendRefs...)
}
}
}
}

// Collect BackendRefs for metrics sinks
if envoyproxy.Spec.Telemetry.Metrics != nil {
for _, sink := range envoyproxy.Spec.Telemetry.Metrics.Sinks {
if sink.OpenTelemetry != nil {
backendRefs = append(backendRefs, sink.OpenTelemetry.BackendRefs...)
}
}

}

// Collect BackendRefs for tracing provider
if envoyproxy.Spec.Telemetry.Tracing != nil {
backendRefs = append(backendRefs, envoyproxy.Spec.Telemetry.Tracing.Provider.BackendRefs...)
}

// Append all referenced BackendRefs to maps
for _, backendRef := range backendRefs {
backendNamespace := gatewayapi.NamespaceDerefOr(backendRef.Namespace, envoyproxy.Namespace)
resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{
Group: backendRef.Group,
Kind: backendRef.Kind,
Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace),
Name: backendRef.Name,
}] = struct{}{}
}
}
}

Expand Down
57 changes: 40 additions & 17 deletions internal/provider/kubernetes/indexers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,53 @@ func addEnvoyProxyIndexers(ctx context.Context, mgr manager.Manager) error {

func backendEnvoyProxyIndexFunc(rawObj client.Object) []string {
envoyproxy := rawObj.(*v1alpha1.EnvoyProxy)
var backendRefs []string
var backendIndex []string

if envoyproxy.Spec.Telemetry != nil && envoyproxy.Spec.Telemetry.AccessLog != nil {
for _, settings := range envoyproxy.Spec.Telemetry.AccessLog.Settings {
for _, sink := range settings.Sinks {
if sink.OpenTelemetry != nil {
for _, backendRef := range sink.OpenTelemetry.BackendRefs {
if backendRef.Kind == nil || string(*backendRef.Kind) == gatewayapi.KindService {
// If an explicit Backend namespace is not provided, use the EnvoyProxy namespace to
// lookup the provided Gateway Name.
backendRefs = append(backendRefs,
types.NamespacedName{
Namespace: gatewayapi.NamespaceDerefOr(backendRef.Namespace, envoyproxy.Namespace),
Name: string(backendRef.Name),
}.String(),
)
}
if envoyproxy.Spec.Telemetry != nil {
backendRefs := []v1alpha1.BackendRef{}

// Collect BackendRefs for access log sinks
if envoyproxy.Spec.Telemetry.AccessLog != nil {
for _, settings := range envoyproxy.Spec.Telemetry.AccessLog.Settings {
for _, sink := range settings.Sinks {
if sink.OpenTelemetry != nil {
backendRefs = append(backendRefs, sink.OpenTelemetry.BackendRefs...)
}
}
}
}

// Collect BackendRefs for metrics sinks
if envoyproxy.Spec.Telemetry.Metrics != nil {
for _, sink := range envoyproxy.Spec.Telemetry.Metrics.Sinks {
if sink.OpenTelemetry != nil {
backendRefs = append(backendRefs, sink.OpenTelemetry.BackendRefs...)
}
}

}

// Collect BackendRefs for tracing provider
if envoyproxy.Spec.Telemetry.Tracing != nil {
backendRefs = append(backendRefs, envoyproxy.Spec.Telemetry.Tracing.Provider.BackendRefs...)
}

// Append all referenced BackendRefs to maps
for _, backendRef := range backendRefs {
if backendRef.Kind == nil || string(*backendRef.Kind) == gatewayapi.KindService {
// If an explicit Backend namespace is not provided, use the EnvoyProxy namespace to
// lookup the provided Gateway Name.
backendIndex = append(backendIndex,
types.NamespacedName{
Namespace: gatewayapi.NamespaceDerefOr(backendRef.Namespace, envoyproxy.Namespace),
Name: string(backendRef.Name),
}.String(),
)
}
}
}

return backendRefs
return backendIndex
}

// addHTTPRouteIndexers adds indexing on HTTPRoute.
Expand Down

0 comments on commit da8d2d3

Please sign in to comment.