Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add triggers to event lineage graph #7746

Merged
merged 3 commits into from Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions pkg/graph/constructor.go
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package graph

import (
"fmt"

eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"
Expand Down Expand Up @@ -94,3 +96,53 @@ func (g *Graph) AddChannel(channel messagingv1.Channel) {

v.AddEdge(to, dest, NoTransform)
Leo6Leo marked this conversation as resolved.
Show resolved Hide resolved
}

func (g *Graph) AddTrigger(trigger eventingv1.Trigger) error {
brokerRef := &duckv1.KReference{
Name: trigger.Spec.Broker,
Namespace: trigger.Namespace,
APIVersion: "eventing.knative.dev/v1",
Kind: "Broker",
}
brokerDest := &duckv1.Destination{Ref: brokerRef}
broker, ok := g.vertices[makeComparableDestination(brokerDest)]
if !ok {
Leo6Leo marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("trigger refers to a non existent broker, can't add it to the graph")
}

triggerRef := &duckv1.KReference{
Name: trigger.Name,
Namespace: trigger.Namespace,
APIVersion: "eventing.knative.dev/v1",
Kind: "Trigger",
}
triggerDest := &duckv1.Destination{Ref: triggerRef}

to, ok := g.vertices[makeComparableDestination(&trigger.Spec.Subscriber)]
if !ok {
to = &Vertex{
self: &trigger.Spec.Subscriber,
Leo6Leo marked this conversation as resolved.
Show resolved Hide resolved
}
g.vertices[makeComparableDestination(&trigger.Spec.Subscriber)] = to
}

//TODO: the transform function should be set according to the trigger filter - there are multiple open issues to address this later
broker.AddEdge(to, triggerDest, NoTransform)

if trigger.Spec.Delivery == nil || trigger.Spec.Delivery.DeadLetterSink == nil {
return nil
}

dls, ok := g.vertices[makeComparableDestination(trigger.Spec.Delivery.DeadLetterSink)]
if !ok {
dls = &Vertex{
self: trigger.Spec.Delivery.DeadLetterSink,
}
g.vertices[makeComparableDestination(trigger.Spec.Delivery.DeadLetterSink)] = dls
}

broker.AddEdge(dls, triggerDest, NoTransform)
Leo6Leo marked this conversation as resolved.
Show resolved Hide resolved

return nil

}