Skip to content

feat(server): #21109 support leading wildcards in resource matching o…#21110

Open
clifflau1120 wants to merge 1 commit intoPrefectHQ:mainfrom
clifflau1120:21109-support-leading-wildcard-in-resource-matching-of-event-triggers
Open

feat(server): #21109 support leading wildcards in resource matching o…#21110
clifflau1120 wants to merge 1 commit intoPrefectHQ:mainfrom
clifflau1120:21109-support-leading-wildcard-in-resource-matching-of-event-triggers

Conversation

@clifflau1120
Copy link

Overview

This PR closes #21109.

It adds support to leading wildcards while matching resources against events.

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 13, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing clifflau1120:21109-support-leading-wildcard-in-resource-matching-of-event-triggers (0dc2463) with main (447059a)

Open in CodSpeed

@clifflau1120 clifflau1120 force-pushed the 21109-support-leading-wildcard-in-resource-matching-of-event-triggers branch from 2a809ee to 0dc2463 Compare March 13, 2026 07:07
@clifflau1120 clifflau1120 marked this pull request as ready for review March 13, 2026 07:08
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @clifflau1120 ! The in-memory matching change looks correct directionally, but I think there are a few things that need to be addressed before this is ready to merge:

  1. Handle the double-wildcard case (*foo*)

As written, a pattern like *middle* will hit the startswith("*") branch and do value.endswith("middle*") — matching on a literal trailing *, which is almost certainly not what a user would intend. This needs to be handled, either as a contains check or explicitly rejected with a validation error:

if expected.startswith("*") and expected.endswith("*") and len(expected) > 1:
    match = expected[1:-1] in value
elif expected.startswith("*"):
    match = value.endswith(expected[1:])
elif expected.endswith("*"):
    match = value.startswith(expected[:-1])
  1. LabelOperations in filters.py needs matching changes

This is the important one. The LabelOperations class translates wildcard patterns into SQL for database queries, and it currently only understands trailing wildcards (→ startswith/LIKE 'prefix%') or exact match. A leading wildcard like *.csv will fall into the simple (exact match) bucket and generate resource_id IN ('*.csv') instead of the correct LIKE '%.csv'.

This means triggers will evaluate events correctly in real-time (in-memory path), but historical event queries and the events API will silently return wrong results (DB path).

  1. Minor things
  • The docstring on matches() should be updated to mention leading wildcards
  • The original test case ("any.old.*", "any.old.stuff") was removed rather than kept alongside the new case — would be good to keep it for trailing-wildcard coverage
  • Worth adding test cases for the negation + leading wildcard combo ("!*.csv")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support leading wildcards or regular expressions in resource matching of event triggers

2 participants