Skip to content

Commit 5dab3d3

Browse files
Shared utilities to handle VRL expressions (#540)
Co-authored-by: knope-bot[bot] <152252888+knope-bot[bot]@users.noreply.github.com>
1 parent c6040d6 commit 5dab3d3

File tree

15 files changed

+208
-274
lines changed

15 files changed

+208
-274
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
default: minor
3+
---
4+
5+
# Breaking
6+
7+
Removed `pool_idle_timeout_seconds` from `traffic_shaping`, instead use `pool_idle_timeout` with duration format.
8+
9+
```diff
10+
traffic_shaping:
11+
- pool_idle_timeout_seconds: 30
12+
+ pool_idle_timeout: 30s
13+
```
14+
15+
#540 by @ardatan

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/router/src/pipeline/progressive_override.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
use std::collections::{BTreeMap, HashMap, HashSet};
22

33
use hive_router_config::override_labels::{LabelOverrideValue, OverrideLabelsConfig};
4-
use hive_router_plan_executor::execution::client_request_details::ClientRequestDetails;
4+
use hive_router_plan_executor::{
5+
execution::client_request_details::ClientRequestDetails, utils::expression::compile_expression,
6+
};
57
use hive_router_query_planner::{
68
graph::{PlannerOverrideContext, PERCENTAGE_SCALE_FACTOR},
79
state::supergraph_state::SupergraphState,
810
};
911
use rand::Rng;
1012
use vrl::{
11-
compiler::{compile as vrl_compile, Program as VrlProgram, TargetValue as VrlTargetValue},
13+
compiler::Program as VrlProgram,
14+
compiler::TargetValue as VrlTargetValue,
1215
core::Value as VrlValue,
1316
prelude::{
1417
state::RuntimeState as VrlState, Context as VrlContext, ExpressionError,
1518
TimeZone as VrlTimeZone,
1619
},
17-
stdlib::all as vrl_build_functions,
1820
value::Secrets as VrlSecrets,
1921
};
2022

@@ -126,27 +128,20 @@ impl OverrideLabelsEvaluator {
126128
) -> Result<Self, OverrideLabelsCompileError> {
127129
let mut static_enabled_labels = HashSet::new();
128130
let mut expressions = HashMap::new();
129-
let vrl_functions = vrl_build_functions();
130131

131132
for (label, value) in override_labels_config.iter() {
132133
match value {
133134
LabelOverrideValue::Boolean(true) => {
134135
static_enabled_labels.insert(label.clone());
135136
}
136137
LabelOverrideValue::Expression { expression } => {
137-
let compilation_result =
138-
vrl_compile(expression, &vrl_functions).map_err(|diagnostics| {
139-
OverrideLabelsCompileError {
140-
label: label.clone(),
141-
error: diagnostics
142-
.errors()
143-
.into_iter()
144-
.map(|d| d.code.to_string() + ": " + &d.message)
145-
.collect::<Vec<_>>()
146-
.join(", "),
147-
}
148-
})?;
149-
expressions.insert(label.clone(), compilation_result.program);
138+
let program = compile_expression(expression, None).map_err(|err| {
139+
OverrideLabelsCompileError {
140+
label: label.clone(),
141+
error: err.to_string(),
142+
}
143+
})?;
144+
expressions.insert(label.clone(), program);
150145
}
151146
_ => {} // Skip false booleans
152147
}

docs/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
|[**override\_subgraph\_urls**](#override_subgraph_urls)|`object`|Configuration for overriding subgraph URLs.<br/>Default: `{}`<br/>||
1616
|[**query\_planner**](#query_planner)|`object`|Query planning configuration.<br/>Default: `{"allow_expose":false,"timeout":"10s"}`<br/>||
1717
|[**supergraph**](#supergraph)|`object`|Configuration for the Federation supergraph source. By default, the router will use a local file-based supergraph source (`./supergraph.graphql`).<br/>||
18-
|[**traffic\_shaping**](#traffic_shaping)|`object`|Configuration for the traffic-shaper executor. Use these configurations to control how requests are being executed to subgraphs.<br/>Default: `{"dedupe_enabled":true,"max_connections_per_host":100,"pool_idle_timeout_seconds":50}`<br/>||
18+
|[**traffic\_shaping**](#traffic_shaping)|`object`|Configuration for the traffic-shaping of the executor. Use these configurations to control how requests are being executed to subgraphs.<br/>Default: `{"dedupe_enabled":true,"max_connections_per_host":100,"pool_idle_timeout":"50s"}`<br/>||
1919

2020
**Additional Properties:** not allowed
2121
**Example**
@@ -109,7 +109,7 @@ supergraph: {}
109109
traffic_shaping:
110110
dedupe_enabled: true
111111
max_connections_per_host: 100
112-
pool_idle_timeout_seconds: 50
112+
pool_idle_timeout: 50s
113113

114114
```
115115

@@ -1832,7 +1832,7 @@ max_retries: 10
18321832
<a name="traffic_shaping"></a>
18331833
## traffic\_shaping: object
18341834

1835-
Configuration for the traffic-shaper executor. Use these configurations to control how requests are being executed to subgraphs.
1835+
Configuration for the traffic-shaping of the executor. Use these configurations to control how requests are being executed to subgraphs.
18361836

18371837

18381838
**Properties**
@@ -1841,15 +1841,15 @@ Configuration for the traffic-shaper executor. Use these configurations to contr
18411841
|----|----|-----------|--------|
18421842
|**dedupe\_enabled**|`boolean`|Enables/disables request deduplication to subgraphs.<br/><br/>When requests exactly matches the hashing mechanism (e.g., subgraph name, URL, headers, query, variables), and are executed at the same time, they will<br/>be deduplicated by sharing the response of other in-flight requests.<br/>Default: `true`<br/>||
18431843
|**max\_connections\_per\_host**|`integer`|Limits the concurrent amount of requests/connections per host/subgraph.<br/>Default: `100`<br/>Format: `"uint"`<br/>Minimum: `0`<br/>||
1844-
|**pool\_idle\_timeout\_seconds**|`integer`|Timeout for idle sockets being kept-alive.<br/>Default: `50`<br/>Format: `"uint64"`<br/>Minimum: `0`<br/>||
1844+
|**pool\_idle\_timeout**|`string`|Timeout for idle sockets being kept-alive.<br/>Default: `"50s"`<br/>||
18451845

18461846
**Additional Properties:** not allowed
18471847
**Example**
18481848

18491849
```yaml
18501850
dedupe_enabled: true
18511851
max_connections_per_host: 100
1852-
pool_idle_timeout_seconds: 50
1852+
pool_idle_timeout: 50s
18531853
18541854
```
18551855

lib/executor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ itoa = "1.0.15"
4949
ryu = "1.0.20"
5050
indexmap = "2.10.0"
5151
bumpalo = "3.19.0"
52+
once_cell = "1.21.3"
5253

5354
[dev-dependencies]
5455
subgraphs = { path = "../../bench/subgraphs" }

lib/executor/src/executors/error.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use vrl::{diagnostic::DiagnosticList, prelude::ExpressionError};
1+
use vrl::prelude::ExpressionError;
22

33
use crate::response::graphql_error::{GraphQLError, GraphQLErrorExtensions};
44

@@ -34,21 +34,6 @@ impl From<SubgraphExecutorError> for GraphQLError {
3434
}
3535

3636
impl SubgraphExecutorError {
37-
pub fn new_endpoint_expression_build(
38-
subgraph_name: String,
39-
diagnostics: DiagnosticList,
40-
) -> Self {
41-
SubgraphExecutorError::EndpointExpressionBuild(
42-
subgraph_name,
43-
diagnostics
44-
.errors()
45-
.into_iter()
46-
.map(|d| d.code.to_string() + ": " + &d.message)
47-
.collect::<Vec<_>>()
48-
.join(", "),
49-
)
50-
}
51-
5237
pub fn new_endpoint_expression_resolution_failure(
5338
subgraph_name: String,
5439
error: ExpressionError,

0 commit comments

Comments
 (0)