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

Expand filtering options for resources_in_roles in /api/events/filter #16978

Open
ogenstad opened this issue Feb 5, 2025 · 0 comments
Open
Labels
enhancement An improvement of an existing feature

Comments

@ogenstad
Copy link

ogenstad commented Feb 5, 2025

Describe the current behavior

Currently when listing events you can filter them by using a EventFilter object in JSON format. This allows you to search for events based on the event name, resource, related resource.

However the engine is quite opinionated with regards to how the filter is then used to query the database. For example when using related nodes by specifying an EventRelatedFilter we can see that we can specify a list of key-pairs of prefect.resource.role and prefect.resource.id in the resources_in_roles attribute. The resulting query is then using sa.or_ as seen here:

        if self.resources_in_roles:
            filters.append(
                sa.or_(
                    *(
                        sa.and_(
                            db.EventResource.resource_id == resource_id,
                            db.EventResource.resource_role == role,
                        )
                        for resource_id, role in self.resources_in_roles
                    )
                )
            )

Describe the proposed behavior

For my use-case I'd want this to be an sa.and_ instead, and while I don't expect a breaking change here it would be nice to be able to control this behaviour. Perhaps by introducing a resources_in_roles_operation which would default a value indicating sa.or_ but that you could then set to sa.and_.

The goal would be to use the resources_in_roles as a constraint to further filter the events to a smaller set instead of including additional events for each pair of role and resource_id.

Example Use

No response

Additional context

It looks like the /api/automation/filter supports this concept of operator in one location.

@ogenstad ogenstad added the enhancement An improvement of an existing feature label Feb 5, 2025
@ogenstad ogenstad changed the title Expand filtering options for /api/events/filter Expand filtering options for resources_in_roles in /api/events/filter Feb 5, 2025
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

No branches or pull requests

1 participant