Skip to content

Commit

Permalink
Use RESULTS_ROUTING_GROUP_KEY in routing rules
Browse files Browse the repository at this point in the history
  • Loading branch information
willmostly committed Jan 23, 2025
1 parent 70d5697 commit d9aef12
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions gateway-ha/src/test/resources/rules/routing_rules_atomic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: "airflow"
description: "if query from airflow, route to etl group"
condition: "request.getHeader(\"X-Trino-Source\") == \"airflow\" && (request.getHeader(\"X-Trino-Client-Tags\") == null || request.getHeader(\"X-Trino-Client-Tags\").isEmpty())"
actions:
- "result.put(\"routingGroup\", \"etl\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"etl\")"
---
name: "airflow special"
description: "if query from airflow with special label, route to etl-special group"
condition: "request.getHeader(\"X-Trino-Source\") == \"airflow\" && request.getHeader(\"X-Trino-Client-Tags\") contains \"label=special\""
actions:
- "result.put(\"routingGroup\", \"etl-special\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"etl-special\")"
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: "if query from airflow, route to etl group"
condition: "request.getHeader(\"X-Trino-Source\") == \"airflow\""
actions:
- "if (request.getHeader(\"X-Trino-Client-Tags\") contains \"label=special\") {
result.put(\"routingGroup\", \"etl-special\")
result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"etl-special\")
}
else {
result.put(\"routingGroup\", \"etl\")
result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"etl\")
}"
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ description: "if query from airflow, route to etl group"
priority: 0
condition: "request.getHeader(\"X-Trino-Source\") == \"airflow\""
actions:
- "result.put(\"routingGroup\", \"etl\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"etl\")"
---
name: "airflow special"
description: "if query from airflow with special label, route to etl-special group"
priority: 1
condition: "request.getHeader(\"X-Trino-Source\") == \"airflow\" && request.getHeader(\"X-Trino-Client-Tags\") contains \"label=special\""
actions:
- "result.put(\"routingGroup\", \"etl-special\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"etl-special\")"
4 changes: 2 additions & 2 deletions gateway-ha/src/test/resources/rules/routing_rules_state.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ condition: |
request.getHeader("X-Trino-Source") == "airflow"
actions:
- |
result.put("routingGroup", "etl")
result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, "etl")
- |
state.get("triggeredRules").add("airflow")
---
Expand All @@ -28,4 +28,4 @@ condition: |
state.get("triggeredRules").contains("airflow") && request.getHeader("X-Trino-Client-Tags") contains "label=special"
actions:
- |
result.put("routingGroup", "etl-special")
result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, "etl-special")
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "user"
description: "if user is will, route to will-group"
condition: "trinoRequestUser.userExistsAndEquals(\"will\")"
actions:
- "result.put(\"routingGroup\", \"will-group\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"will-group\")"
---
name: "query"
description: "test extraction of tables and schemas in conjunction with default catalog and schema"
Expand All @@ -14,7 +14,7 @@ condition: |
&& trinoQueryProperties.getSchemas().contains("schemy")
&& trinoQueryProperties.getCatalogs().contains("catx")
actions:
- "result.put(\"routingGroup\", \"tbl-group\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"tbl-group\")"
---
name: "catalog-schema"
description: "test that catalogSchemas with default catalog and schema"
Expand All @@ -23,21 +23,21 @@ condition: |
&& trinoQueryProperties.getCatalogSchemas.contains("caty.default")
&& !trinoQueryProperties.getCatalogSchemas.contains("catx.default")
actions:
- "result.put(\"routingGroup\", \"catalog-schema-group\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"catalog-schema-group\")"
---
name: "query-type"
description: "test table type"
condition: |
trinoQueryProperties.getQueryType().toLowerCase.equals("insert")
actions:
- "result.put(\"routingGroup\", \"type-group\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"type-group\")"
---
name: "prepared-statement-header"
description: "test execute with multiple prepared statements"
condition: |
trinoQueryProperties.getQueryType().toLowerCase.equals("query") && trinoQueryProperties.tablesContains("cat.schem.foo")
actions:
- "result.put(\"routingGroup\", \"statement-header-group\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"statement-header-group\")"
---
name: "defaults-group"
description: "test default schema and catalog"
Expand All @@ -46,19 +46,19 @@ condition: |
&& trinoQueryProperties.getDefaultSchema().equals(java.util.Optional.of("other_schema"))
actions:
- "result.put(\"routingGroup\", \"defaults-group\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"defaults-group\")"
---
name: "system-group"
description: "capture queries to system catalog"
condition: |
trinoQueryProperties.getCatalogs().contains("system")
actions:
- "result.put(\"routingGroup\", \"system\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"system\")"

---
name: "nomatch"
priority: -1
description: "default group to catch if no other rules fired"
condition: "true"
actions:
- "result.put(\"routingGroup\", \"no-match\")"
- "result.put(FileBasedRoutingGroupSelector.RESULTS_ROUTING_GROUP_KEY, \"no-match\")"

0 comments on commit d9aef12

Please sign in to comment.