argoproj / argo-events

Event-driven Automation Framework for Kubernetes
https://argoproj.github.io/argo-events/
Apache License 2.0
2.38k stars 740 forks source link

Be able to generate events with different eventNames from a single data source #1755

Open whynowy opened 2 years ago

whynowy commented 2 years ago

Is your feature request related to a problem? Please describe. Today, one EventSource object can be configured with multiple events configuration, this can reduce the K8s resources usage such as the number of created pods. For example, you can configure a Kafka EventSource object, with 2 events, both pointing to the same kafka topic, but using 2 different event source filters. However, this sort of EventSource configuration can not reduce the connection to the kafka brokers, if that particular kafka topic is used for many event sources, that will use lots of client subscriptions.

Describe the solution you'd like

  1. An event source can be used to subscribe to a single data source, using filters to publish events with different eventNames.
  2. This should support all the existing event sources.

Describe alternatives you've considered This could be achieved by extending existing EventSource spec, or adding a new CRD.


Message from the maintainers:

If you wish to see this enhancement implemented please add a đź‘Ť reaction to this issue! We often sort issues this way to know what to prioritize.

gtato commented 1 year ago

From the documentation, I would have implied that this feature is already in place. But i tried it with the webhook, and I am getting a weird behaviour:

whynowy commented 1 year ago

From the documentation, I would have implied that this feature is already in place. But i tried it with the webhook, and I am getting a weird behaviour:

This feature request is different from the documentation.

whynowy commented 1 year ago

From the documentation, I would have implied that this feature is already in place. But i tried it with the webhook, and I am getting a weird behaviour:

What was the weird behavior?

gtato commented 1 year ago

So I had 2 events (e1 and e2) from the same event source (a webhook), and a sensor listening to these events and starting a workflow (w1 or w2) accordingly. When I wrote this message, I was seeing that when event e1 fired, nothing would start. However, when e2 fired, both w1 and w2 would start. Then I put conditions in the sensor trigger, and it was working as expected. I still think that is a bug though, because if no conditions are in place I would expect both events to trigger both workflows.

whynowy commented 1 year ago

If you define both dependencies (2 events) in one sensor, by default the triggers use && operator unless you explicitly define trigger conditions. See https://github.com/argoproj/argo-events/blob/master/docs/sensors/trigger-conditions.md#triggers-without-conditions

NWCalvank commented 1 month ago

If you have multiple events (eventName) on one EventSource, what is the expected behaviour? Example:

apiVersion: argoproj.io/v1alpha1
kind: EventSource
metadata:
  name: test
  namespace: argo-events
spec:
  sqs:
    event-1: &event
      jsonBody: true
      accessKey:
        key: AWS_ACCESS_KEY_ID
        name: aws-secret
      secretKey:
        key: AWS_SECRET_ACCESS_KEY
        name: aws-secret
      region: us-west-2
      queue: argo-staging
      waitTimeSeconds: 20
      filter:
          expression: "body.type == 'event-1'"
    event-2:
      <<: *event
      filter:
          expression: "body.type == 'event-2'"
    event-3:
      <<: *event
      filter:
          expression: "body.type == 'event-3'"

If I send a payload with {"type": "event-1"}, sometimes, event-1 is triggered. Other times, there is no matching event, as per the EventSource logs: Filter condition not met, skip dispatching.

Re-sending the same payload 5 times resulted (just now) in 2 failures and 3 successes. Similarly for {"type": "event-2"} (3 failures, and 2 successes).

I'd have expected the behaviour to be that any matching events were triggered, but it appears that the events are tested at-random and the first one tested either passes or fails, and no other events are emitted.

Is there a way to configure an EventSource to test the message against all event filters? I feel like I must be missing something, otherwise having multiple eventNames on an EventSource seems pointless


Seems like I'm trying to accomplish something similar to this comment