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

EventSource's webhook has a filter issue #3403

Open
Alphamic opened this issue Dec 24, 2024 · 0 comments
Open

EventSource's webhook has a filter issue #3403

Alphamic opened this issue Dec 24, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Alphamic
Copy link

Describe the bug
When I use filter.expression of EventSource, it doesn't match no matter how I modify it. and the error shows "Filter condition not met, skip dispatching".
But I did my own test with argo's eventing code, using the same expression, and it matched. refer the below link.
https://github.com/argoproj/argo-events/blob/master/pkg/eventsources/eventing.go#L633

To Reproduce

  1. EventSource yaml configuration.
apiVersion: argoproj.io/v1alpha1
kind: EventSource
metadata:
  name: yunxiao
spec:
  eventBusName: default
  # service:
  #   ports:
  #     - port: 12000
  #       targetPort: 12000
  webhook:
    example:
      filter:
        expression: "header['X-Codeup-Token'] == 'yunxiao-webhook-token' && header['X-Codeup-Event'] in ['Push Hook', 'Merge Request Hook']"
      port: "12000"
      endpoint: /example
      method: POST
  1. about expression syntax problem
"(header['X-Codeup-Token'] == 'yunxiao-webhook-token') && (header['X-Codeup-Event'] in ['Push Hook', 'Merge Request Hook'])"
"header['X-Codeup-Token'] == 'yunxiao-webhook-token' && header['X-Codeup-Event'] in ['Push Hook', 'Merge Request Hook']"

I used the above two syntax to successfully match in our test code.

  1. my partial the test code.

I was able to successfully match the HTTP request text using the below refer test code.

package main

import (
	"encoding/json"
	"fmt"
	exprlang "github.com/antonmedv/expr"
	"github.com/argoproj/argo-events/pkg/shared/expr"
	"strings"
)

type EventSourceFilter struct {
	Expression string `json:"expression,omitempty" protobuf:"bytes,1,opt,name=expression"`
}

// https://github.com/argoproj/argo-events/blob/master/pkg/eventsources/eventing.go#L633
func filterEvent(data []byte, filter *EventSourceFilter) (bool, error) {
	dataMap := make(map[string]interface{})
	err := json.Unmarshal(data, &dataMap)
	if err != nil {
		return false, fmt.Errorf("failed to unmarshal data, %w", err)
	}

	params := make(map[string]interface{})
	for key, value := range dataMap {
		params[strings.ReplaceAll(key, "-", "_")] = value
	}

	env := expr.GetFuncMap(params)

	program, err := exprlang.Compile(filter.Expression)
	fmt.Println(program)
	output, err := exprlang.Run(program, env)
	fmt.Println(output)

	return expr.EvalBool(filter.Expression, env)
}
  1. But when I applied expression to EventSource, it told me there was no match

Expected behavior

trigger the webhook manually:

curl -X POST <ip_address>:12000/example -H 'X-Codeup-Event: Push Hook' -H 'X-Codeup-Token: yunxiao-webhook-token' -d '{"repository":{"name": "test"}}'

View the log of eventsource's pod: kubectl logs <eventsource_pod>

{"level":"info","ts":1735028081.8492208,"logger":"argo-events.eventsource","caller":"eventsources/eventing.go:544","msg":"Filter condition not met, skip dispatching","eventSourceName":"yunxiao"}

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • Kubernetes: v1.31.1
  • helm version: argo/argo-events --version 2.4.8

Additional context
Add any other context about the problem here.


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.

@Alphamic Alphamic added the bug Something isn't working label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant