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

[WIP] feat: add constructor for full event lineage graph #7921

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Cali0707
Copy link
Member

Fixes #7694

Proposed Changes

  • Get resources from cluster and construct a graph

Signed-off-by: Calum Murray <cmurray@redhat.com>
@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 13, 2024
@Cali0707
Copy link
Member Author

/cc @pierDipi

@knative-prow knative-prow bot requested a review from pierDipi May 13, 2024 18:41
Copy link

knative-prow bot commented May 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Cali0707

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot requested review from aslom and matzew May 13, 2024 18:41
@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 13, 2024
pkg/graph/constructor.go Outdated Show resolved Hide resolved
@Cali0707
Copy link
Member Author

This is WIP because I want feedback on the approach before adding unit tests

Signed-off-by: Calum Murray <cmurray@redhat.com>
Copy link

codecov bot commented May 13, 2024

Codecov Report

Attention: Patch coverage is 9.67742% with 224 lines in your changes missing coverage. Please review.

Project coverage is 67.04%. Comparing base (2cc0a5b) to head (d60a069).
Report is 5 commits behind head on main.

Files Patch % Lines
pkg/graph/constructor.go 10.90% 196 Missing ⚠️
pkg/graph/types.go 0.00% 28 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7921      +/-   ##
==========================================
- Coverage   67.87%   67.04%   -0.83%     
==========================================
  Files         368      368              
  Lines       17551    17777     +226     
==========================================
+ Hits        11912    11918       +6     
- Misses       4894     5113     +219     
- Partials      745      746       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pkg/graph/constructor.go Outdated Show resolved Hide resolved
pkg/graph/constructor.go Outdated Show resolved Hide resolved
Signed-off-by: Calum Murray <cmurray@redhat.com>
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 16, 2024
Signed-off-by: Calum Murray <cmurray@redhat.com>
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 16, 2024
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
@Cali0707
Copy link
Member Author

/cc @pierDipi @aliok

@knative-prow knative-prow bot requested review from aliok and pierDipi July 23, 2024 03:51

g := NewGraph()

for _, ns := range config.Namespaces {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Backstage backend, we fetch brokers for all namespaces. It is a readonly view, so, should be fine.

We might add a config option in Backstage backend to consider specific namespaces.
However, there's still a need to fetch all brokers, all triggers, etc.

That can't be done by fetching all namespaces and then iterating over them though.

We should use brokers, err := clientset.EventingV1().Brokers(metav1.NamespaceAll).List(context.Background(), metav1.ListOptions{}).

Can we add a config option for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking for this you could just provide metav1.NamespaceAll as the only namespace in the config list. Would that work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would...

We might then need add a validation in the code to check if the list of namespaces contain "metav1.NamespaceAll" and if so, it should not have anything else.

Comment on lines 73 to 75
if err != nil && !apierrs.IsNotFound(err) && !apierrs.IsUnauthorized(err) && !apierrs.IsForbidden(err) {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should log with info/warn in case of apierrs.IsUnauthorized(err) or apierrs.IsForbidden(err)

Signed-off-by: Calum Murray <cmurray@redhat.com>
Comment on lines 43 to 48
ShouldAddBroker func(b eventingv1.Broker) bool
ShouldAddChannel func(c messagingv1.Channel) bool
ShouldAddSource func(s duckv1.Source) bool
ShouldAddTrigger func(t eventingv1.Trigger) bool
ShouldAddSubscription func(s messagingv1.Subscription) bool
ShouldAddEventType func(et eventingv1beta3.EventType) bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are nice, but the resources are fetched anyway. If I am not interested in channels, that shouldn't be fetched at all.

Can you create separate entries like fetchBrokers, etc defaulting to true?

Comment on lines 355 to 357
if err != nil {
return nil, fmt.Errorf("unable to list source CRDs: %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns error in case of 404 (when there are no source CRDs)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing, in case of 404s or Auth issues when fetching resources other than sources, we write a Warn log and continue. It might be nice to be more consistent.


return g, nil
}

func (g *Graph) AddBroker(broker eventingv1.Broker) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we actually embed the full broker resource in the graph here? Or make it a config option?

Because, for example in the Backstage backend, if I only have references, I will need to fetch the brokers again. But, we have the full resource here fetched anyway.

@aliok
Copy link
Member

aliok commented Jul 25, 2024

Kind of irrelevant for this PR, but it would be super nice if we have a stringer for graph and vertices for debugging purposes. A text like

A (broker.eventing.knative.dev) --> B (foo.bar)
...etc

@Cali0707
Copy link
Member Author

/cc @aliok
Thanks for all the feedback!!

@knative-prow knative-prow bot requested a review from aliok July 25, 2024 18:43
@Cali0707
Copy link
Member Author

Kind of irrelevant for this PR, but it would be super nice if we have a stringer for graph and vertices for debugging purposes. A text like

A (broker.eventing.knative.dev) --> B (foo.bar)
...etc

Yeah 100%, I thought about this too but I wasn't sure how to show a vertex with an arbitrary number of edges using just strings...

@aliok
Copy link
Member

aliok commented Jul 26, 2024

Yeah 100%, I thought about this too but I wasn't sure how to show a vertex with an arbitrary number of edges using just strings...

I added stringer impls for types now. It is ok-ish. Example:

Kind = Broker, Namespace = default, Name = test-broker, APIVersion = eventing.knative.dev/v1, Group = , Address = 
Kind = Broker, Namespace = default, Name = default, APIVersion = eventing.knative.dev/v1, Group = , Address = 
Kind = EventType, Namespace = default, Name = test-event-type, APIVersion = eventing.knative.dev/v1beta3, Group = , Address = 
Out Edges:
        [Kind = EventType, Namespace = default, Name = test-event-type, APIVersion = eventing.knative.dev/v1beta3, Group = , Address = ] --> [Kind = Broker, Namespace = default, Name = test-broker, APIVersion = eventing.knative.dev/v1, Group = , Address = ]

@aliok
Copy link
Member

aliok commented Jul 26, 2024

@Cali0707

Say we have an EventType:

kind: EventType
metadata:
  name: test-event-type
  namespace: default
spec:
  reference:
    apiVersion: eventing.knative.dev/v1
    kind: Broker
    name: test-broker

Currently the graph is constructed in a way that there is an edge from ET to Broker.

I think it should be the other way around.

Events of EventType is coming out of broker.

cc @pierDipi


v.AddEdge(to, dest, NoTransform{}, true)
}

func (g *Graph) AddEventType(et *eventingv1beta3.EventType) error {
func (g *Graph) AddEventType(et eventingv1beta3.EventType) error {
ref := &duckv1.KReference{
Name: et.Name,
Namespace: et.Namespace,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below this line, we have a APIVersion: "eventing.knative.dev/v1beta3".

This v1beta3 information is probably needed for this case for using as a map key. Group (eventing.k.d) should be enough, as there can't be another resource with the same name and group, but in a different version.

Ignoring the version can make things easier. Would we lose important information to be provided to the clients of this library?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern here is that if we get rid of the version, it might make it harder for clients of the library to understand what type to cast the interface{} value we are storing with the object to...

aliok and others added 5 commits July 29, 2024 15:04
for 3 entries, it was creating an array of 6

Signed-off-by: Ali Ok <aliok@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Ali Ok <aliok@redhat.com>
Signed-off-by: Ali Ok <aliok@redhat.com>
Signed-off-by: Ali Ok <aliok@redhat.com>
Copy link

knative-prow bot commented Jul 29, 2024

@Cali0707: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
reconciler-tests_eventing_main d60a069 link true /test reconciler-tests

Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@Cali0707
Copy link
Member Author

@aliok @pierDipi is there anything left for this PR? Should we merge this and move to some follow up issues/PRs for anything that comes up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Event Lineage: Create Graph from Cluster Resources
4 participants