Add filter evaluator

What does this MR do and why?

In !212797 (merged) we added pipeline events as a flow trigger, with the intention to follow up by adding the remaining webhook event types (issues, merge requests, notes etc).

A pipeline event currently fires every time a pipeline status changes. This will essentially be 3 times for every pipeline: created, running, success/failure.

This leads us to create flows with prompts to do the filtering. But this is an inefficient and costly use of an LLM and pipeline.

We need a way to filter the triggers so we don't run the flow unless we want to. For example, we may only want to trigger it when the status is failure. Or perhaps we want to exclude pipelines created by a certain bot user.

This problem will be hugely exacerbated as we introduce the other trigger types. So, we need to come up with a flexible solution for implementing dynamic filters.

The hope is that the same filtering functionality can also be used for webhooks too, which will add enormous value!

If you checkout the first commit from this MR !223472 (80fd0e97) you can see a POC adding the database column to store the filters and implements the business logic to process the filters for pipeline hooks.

For now though this MR is stripped back to just add the engine and we'll split out MRs adding the database and business logic (potentially to flow triggers and webhooks in parallel)

References

Screenshots or screen recordings

From !223472 (80fd0e97)

image

image

How to set up and validate locally

Only the tests are really available to validate this MR, but if you want to checkout !223472 (80fd0e97) you can...

  1. Enable ff: ai_flow_trigger_pipeline_hooks
  2. Create a flow and enable it in a group/project with the pipeline event trigger
  3. Trigger a pipeline and witness 3 agent-session pipelines created
  4. Add a filter to the trigger via the rails console:
    a = Ai::FlowTrigger.last
    a.filter = {"pipeline_hooks"=>{"rules"=>[{"field"=>"object_attributes.status", "operator"=>"eq", "value"=>"failed"}]}}
    a.save
  5. Trigger a successful pipeline and witness 0 agent-session pipelines created
  6. Trigger a failed pipeline and witness 1 agent-session pipeline created

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Lee Tickett

Merge request reports

Loading