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

Show subscriptions to event types in Backstage #24

Merged
merged 25 commits into from
Feb 7, 2024

Conversation

aliok
Copy link
Member

@aliok aliok commented Feb 5, 2024

Changes

(see release note below for more details)

Backend:

  • Return the Backstage ids of the subscribers of the event types in the Knative Eventing plugin.

Plugin:

Fixes #20

Release Note

Knative event mesh plugin will now show the subscribers of the event types.

It will show this relation if the subscriber is already registered in the Backstage catalog.

Limitations:
- Only the subscriptions via Brokers and Triggers are supported.
- Finding consumers via CloudEvents SQL is not supported yet. See https://github.com/knative-extensions/backstage-plugins/issues/26.
- Relation will only show if the component registered can be matched using the [`backstage.io/kubernetes-id ` label](https://backstage.io/docs/features/kubernetes/configuration#common-backstageiokubernetes-id-label). 
- Finding consumers via [label selectors](https://backstage.io/docs/features/kubernetes/configuration#label-selector-query-annotation) is not supported yet. See https://github.com/knative-extensions/backstage-plugins/issues/30.
- [`backstage.io/kubernetes-namespace` annotation](https://backstage.io/docs/features/kubernetes/configuration#common-backstageiokubernetes-id-label) is currently ignored. See https://github.com/knative-extensions/backstage-plugins/issues/29.
- When trying to match the consumers of eventTypes on Backstage side, pagination is not handled yet. See https://github.com/knative-extensions/backstage-plugins/issues/28.

Signed-off-by: Ali Ok <aliok@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>
Signed-off-by: Ali Ok <aliok@redhat.com>
Copy link

knative-prow bot commented Feb 5, 2024

@aliok: The label(s) kind/<kind> cannot be applied, because the repository doesn't have them.

In response to this:

Changes

  • Show subscriptions to event types in Backstage (see release note below for more)
  • Diagram: https://gist.github.com/aliok/45d80cb82822142dd6a978c9cc44e12e
  • WIP PR created for early feedback:
  • My efforts to use the subscriber information in the Backstage plugin failed as entity providers cannot create the ApiConsumedBy relationship from the API entity side. It needs to be set on the Component entity side. This entity cannot be reached in a provider.
  • There are missing tests for the backend. Similarly, there are some linting issues.

/kind

Fixes #

Release Note

Knative event mesh plugin will now show the subscribers of the event types.

It will show this relation if the subscriber is already registered in the Backstage catalog.
Only the subscriptions via Brokers and Triggers are supported. CloudEvents SQL is not supported yet.

Docs


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/test-infra repository.

@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 5, 2024
@knative-prow knative-prow bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 5, 2024
Signed-off-by: Ali Ok <aliok@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>
Signed-off-by: Ali Ok <aliok@redhat.com>
Signed-off-by: Ali Ok <aliok@redhat.com>
Comment on lines 224 to 235
// TODO: we don't handle the CESQL yet
if trigger.Spec.Filter != nil && len(trigger.Spec.Filter.Attributes) > 0 {
// check if "type" attribute is present
if subscribedEventType, ok := trigger.Spec.Filter.Attributes["type"]; ok {
// it can be present but empty
// in that case, we assume the trigger is subscribed to all event types
if subscribedEventType != eventingv1.TriggerAnyFilter {
// if type is present and not empty, that means the trigger is subscribed to a specific event type
return []string{subscribedEventType}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/knative/eventing/blob/main/pkg/eventfilter/subscriptionsapi/
https://github.com/knative/eventing/blob/main/pkg/eventfilter/attributes/

subscriptionsapi.NewAllFilter(...)
attributes.NewFilter()

Example:

# trigger filter
random: foo
# Event type spec
spec:
  attributes:
    random:
       type: string
e := cloudevents.NewEvent()
e.SetExtension("random", <random-string>)

Copy link
Member Author

Choose a reason for hiding this comment

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

#26

Signed-off-by: Ali Ok <aliok@redhat.com>
Signed-off-by: Ali Ok <aliok@redhat.com>
Signed-off-by: Ali Ok <aliok@redhat.com>
backends/pkg/reconciler/eventmesh/handler.go Outdated Show resolved Hide resolved
backends/pkg/reconciler/eventmesh/handler.go Outdated Show resolved Hide resolved
backends/pkg/reconciler/eventmesh/handler.go Outdated Show resolved Hide resolved
backends/pkg/reconciler/eventmesh/handler.go Outdated Show resolved Hide resolved
backends/pkg/reconciler/eventmesh/handler.go Outdated Show resolved Hide resolved
backends/pkg/reconciler/eventmesh/handler.go Outdated Show resolved Hide resolved
backends/pkg/reconciler/eventmesh/handler.go Outdated Show resolved Hide resolved
backends/pkg/reconciler/eventmesh/handler.go Outdated Show resolved Hide resolved
backends/pkg/reconciler/eventmesh/handler.go Outdated Show resolved Hide resolved
Signed-off-by: Ali Ok <aliok@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>
Signed-off-by: Ali Ok <aliok@redhat.com>
Signed-off-by: Ali Ok <aliok@redhat.com>
Signed-off-by: Ali Ok <aliok@redhat.com>
@pierDipi
Copy link
Member

pierDipi commented Feb 6, 2024

There are linting errors

@pierDipi
Copy link
Member

pierDipi commented Feb 6, 2024

LGTM

Signed-off-by: Ali Ok <aliok@redhat.com>
Signed-off-by: Ali Ok <aliok@redhat.com>
Signed-off-by: Ali Ok <aliok@redhat.com>
@aliok aliok changed the title [WIP] Show subscriptions to event types in Backstage Show subscriptions to event types in Backstage Feb 7, 2024
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 7, 2024
@aliok
Copy link
Member Author

aliok commented Feb 7, 2024

Screenshots for this setup:

  • 3 event types: paymentreceived, paymentprocessed, frauddetected
  • 3 consumers: payment-processor, fraud-detector, fraud-logger (these process the events above in the order they're written)
  • 1 additional consumer that consumes all events (Trigger w/o filter): all-events-logger
  • 1 event generator: payment-event-generator-source (relation not shown in Backstage as we don't show the event sources as a relation)

Components

Already registered on Backstage:

apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: payment-processor
  annotations:
    backstage.io/kubernetes-id: payment-processor
spec:
  lifecycle: production
  owner: guests
  type: service
---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: payment-event-generator-source
  annotations:
    backstage.io/kubernetes-id: payment-event-generator-source
spec:
  lifecycle: production
  owner: guests
  type: service
---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: fraud-detector
  annotations:
    backstage.io/kubernetes-id: fraud-detector
spec:
  lifecycle: production
  owner: guests
  type: service
---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: fraud-logger
  annotations:
    backstage.io/kubernetes-id: fraud-logger
spec:
  lifecycle: production
  owner: guests
  type: service
---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: all-events-logger
  annotations:
    backstage.io/kubernetes-id: all-events-logger
spec:
  lifecycle: production
  owner: guests
  type: service

Screenshot 2024-02-07 at 11 20 50

Event types

Screenshot 2024-02-07 at 11 21 03

Event type detail view

Screenshot 2024-02-07 at 11 21 32

all-events-logger component graph

Screenshot 2024-02-07 at 11 22 19

Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Feb 7, 2024
Copy link

knative-prow bot commented Feb 7, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aliok, pierDipi

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 merged commit 408beed into knative-extensions:main Feb 7, 2024
19 checks passed
@aliok aliok deleted the 2024-02-05-subscribers branch February 7, 2024 10:09
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. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show triggers/subscribers in Backstage
2 participants