Skip to content

Routing rules execute all matching rules' actions instead of stopping at first match #878

@Setsushin

Description

@Setsushin

Description

When using file-based routing rules, the gateway executes actions for all rules whose conditions evaluate to true, rather than stopping at the first matching rule. This leads to unexpected behavior where later rules can silently overwrite the routing decisions of earlier rules.

Expected Behavior

When a rule's condition matches, its actions should be executed and rule evaluation should stop (similar to most rule engines like Drools, Easy Rules, etc.).

Actual Behavior

All rules are evaluated, and all matching rules' actions are executed in priority order. The last matching rule's routingGroup value wins.

Steps to Reproduce

  1. Configure routing rules:
---                                                                                                                                                                                                                       
name: "specific-user"                                                                                                                                                                                                     
priority: 1                                                                                                                                                                                                               
condition: |                                                                                                                                                                                                              
  request.getHeader("X-Trino-User") == "admin"                                                                                                                                                                            
actions:                                                                                                                                                                                                                  
  - |                                                                                                                                                                                                                     
    result.put("routingGroup", "admin-cluster")                                                                                                                                                                           
---                                                                                                                                                                                                                       
name: "default"                                                                                                                                                                                                           
priority: 100                                                                                                                                                                                                             
condition: "true"                                                                                                                                                                                                         
actions:                                                                                                                                                                                                                  
  - |                                                                                                                                                                                                                     
    result.put("routingGroup", "default-cluster")     
  1. Send request with X-Trino-User: admin
  2. Request is routed to default-cluster instead of admin-cluster

Workaround

Make all rule conditions mutually exclusive:

  condition: |                                                                                                                                                                                                              
    request.getHeader("X-Trino-User") != "admin"                                                                                                                                                                            

This becomes unwieldy as the number of rules grows.

Environment

  • Trino Gateway version: 16
  • Helm chart: trino-gateway-1.16.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions