Skip to content

Commit 5f52a9b

Browse files
committed
graph: Log queries that the LoadManager puts in jail
1 parent e864b3c commit 5f52a9b

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

graph/src/data/graphql/effort.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl LoadManager {
268268
/// case, we also do not take any locks when asked to update statistics,
269269
/// or to check whether we are overloaded; these operations amount to
270270
/// noops.
271-
pub fn decline(&self, shape_hash: u64) -> bool {
271+
pub fn decline(&self, shape_hash: u64, query: &str) -> bool {
272272
if self.blocked_queries.contains(&shape_hash) {
273273
return true;
274274
}
@@ -304,6 +304,10 @@ impl LoadManager {
304304
if known_query && query_effort / total_effort > *JAIL_THRESHOLD {
305305
// Any single query that causes at least JAIL_THRESHOLD of the
306306
// effort in an overload situation gets killed
307+
warn!(self.logger, "Jailing query";
308+
"query" => query,
309+
"query_effort_ms" => query_effort,
310+
"total_effort_ms" => total_effort);
307311
self.jailed_queries.write().unwrap().insert(shape_hash);
308312
return true;
309313
}

graphql/src/runner.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ where
127127
) -> Result<QueryResult, Vec<QueryExecutionError>> {
128128
let max_depth = max_depth.unwrap_or(*GRAPHQL_MAX_DEPTH);
129129
let query = crate::execution::Query::new(query, max_complexity, max_depth)?;
130+
131+
if self
132+
.load_manager
133+
.decline(query.shape_hash, query.query_text.as_ref())
134+
{
135+
return Err(vec![QueryExecutionError::TooExpensive]);
136+
}
137+
130138
let mut values = BTreeMap::new();
131139
let mut errors = Vec::new();
132140
for (bc, selection_set) in query.block_constraint()? {
@@ -154,14 +162,6 @@ where
154162
Ok(QueryResult::new(Some(q::Value::Object(values))))
155163
}
156164
}
157-
158-
pub fn check_too_expensive(&self, query: &Query) -> Result<(), Vec<QueryExecutionError>> {
159-
if self.load_manager.decline(query.shape_hash) {
160-
Err(vec![QueryExecutionError::TooExpensive])
161-
} else {
162-
Ok(())
163-
}
164-
}
165165
}
166166

167167
impl<S> GraphQlRunnerTrait for GraphQlRunner<S>
@@ -185,18 +185,12 @@ where
185185
max_first: Option<u32>,
186186
) -> QueryResultFuture {
187187
let result = self
188-
.check_too_expensive(&query)
189-
.and_then(|_| self.execute(query, max_complexity, max_depth, max_first))
188+
.execute(query, max_complexity, max_depth, max_first)
190189
.unwrap_or_else(|e| QueryResult::from(e));
191190
Box::new(future::ok(result))
192191
}
193192

194193
fn run_subscription(&self, subscription: Subscription) -> SubscriptionResultFuture {
195-
if let Err(errs) = self.check_too_expensive(&subscription.query) {
196-
let err = SubscriptionError::GraphQLError(errs);
197-
return Box::new(future::result(Err(err)));
198-
}
199-
200194
let query = match crate::execution::Query::new(
201195
subscription.query,
202196
*GRAPHQL_MAX_COMPLEXITY,
@@ -206,6 +200,14 @@ where
206200
Err(e) => return Box::new(future::err(e.into())),
207201
};
208202

203+
if self
204+
.load_manager
205+
.decline(query.shape_hash, query.query_text.as_ref())
206+
{
207+
let err = SubscriptionError::GraphQLError(vec![QueryExecutionError::TooExpensive]);
208+
return Box::new(future::result(Err(err)));
209+
}
210+
209211
let result = execute_prepared_subscription(
210212
query,
211213
SubscriptionExecutionOptions {

0 commit comments

Comments
 (0)