Skip to content

Commit 82cf29a

Browse files
committed
fix(graph): produce consistent query hashes for logging
1 parent 2df58ab commit 82cf29a

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

graph/src/amp/client/flight_client.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
use std::{
2-
collections::HashMap,
3-
hash::{Hash, Hasher},
4-
ops::RangeInclusive,
5-
time::Duration,
6-
};
1+
use std::{collections::HashMap, ops::RangeInclusive, time::Duration};
72

8-
use ahash::AHasher;
3+
use ahash::RandomState;
94
use alloy::primitives::{BlockHash, BlockNumber};
105
use arrow::{datatypes::Schema, error::ArrowError};
116
use arrow_flight::{
@@ -109,9 +104,15 @@ impl Client for FlightClient {
109104
request_metadata: Option<RequestMetadata>,
110105
) -> BoxStream<'static, Result<ResponseBatch, Self::Error>> {
111106
let query = query.to_string();
107+
108+
// Generates a hash from the SQL query for log correlation.
109+
// The hash allows connecting related logs without including the full SQL query in every log message.
110+
// Constant seeds ensure consistent hashes for the same query.
111+
let hasher = RandomState::with_seeds(0, 0, 0, 0);
112+
112113
let logger = logger
113114
.component("AmpFlightClient")
114-
.new(slog::o!("query_id" => query_id(&query)));
115+
.new(slog::o!("query_hash" => hasher.hash_one(&query)));
115116

116117
let mut raw_client = self.raw_client();
117118
let mut prev_block_ranges: Vec<BlockRange> = Vec::new();
@@ -306,16 +307,6 @@ impl From<ResumeStreamingQuery> for BlockRange {
306307
}
307308
}
308309

309-
/// Generates an ID from a SQL query for log correlation.
310-
///
311-
/// The ID allows connecting related logs without including the full SQL
312-
/// query in every log message.
313-
fn query_id(query: &str) -> u32 {
314-
let mut hasher = AHasher::default();
315-
query.hash(&mut hasher);
316-
hasher.finish() as u32
317-
}
318-
319310
/// Serializes the information required to resume a streaming SQL query to JSON.
320311
fn serialize_resume_streaming_query(resume_streaming_query: Vec<ResumeStreamingQuery>) -> String {
321312
#[derive(Serialize)]

0 commit comments

Comments
 (0)