@@ -282,11 +282,11 @@ impl JaegerService {
282
282
} ;
283
283
let search_response = self . search_service . root_search ( search_request) . await ?;
284
284
285
- let Some ( agg_result_json ) = search_response. aggregation else {
285
+ let Some ( agg_result_postcard ) = search_response. aggregation_postcard else {
286
286
debug ! ( "the query matched no traces" ) ;
287
287
return Ok ( ( Vec :: new ( ) , 0 ..=0 ) ) ;
288
288
} ;
289
- let trace_ids = collect_trace_ids ( & agg_result_json ) ?;
289
+ let trace_ids = collect_trace_ids ( & agg_result_postcard ) ?;
290
290
debug ! ( "the query matched {} traces." , trace_ids. 0 . len( ) ) ;
291
291
Ok ( trace_ids)
292
292
}
@@ -1087,9 +1087,11 @@ fn qw_event_to_jaeger_log(event: QwEvent) -> Result<JaegerLog, Status> {
1087
1087
Ok ( log)
1088
1088
}
1089
1089
1090
- fn collect_trace_ids ( trace_ids_json : & str ) -> Result < ( Vec < TraceId > , TimeIntervalSecs ) , Status > {
1090
+ fn collect_trace_ids (
1091
+ trace_ids_postcard : & [ u8 ] ,
1092
+ ) -> Result < ( Vec < TraceId > , TimeIntervalSecs ) , Status > {
1091
1093
let collector_fruit: <FindTraceIdsCollector as Collector >:: Fruit =
1092
- json_deserialize ( trace_ids_json , "trace IDs aggregation" ) ?;
1094
+ postcard_deserialize ( trace_ids_postcard , "trace IDs aggregation" ) ?;
1093
1095
if collector_fruit. is_empty ( ) {
1094
1096
return Ok ( ( Vec :: new ( ) , 0 ..=0 ) ) ;
1095
1097
}
@@ -1118,6 +1120,19 @@ where T: Deserialize<'a> {
1118
1120
}
1119
1121
}
1120
1122
1123
+ fn postcard_deserialize < ' a , T > ( json : & ' a [ u8 ] , label : & ' static str ) -> Result < T , Status >
1124
+ where T : Deserialize < ' a > {
1125
+ match postcard:: from_bytes ( json) {
1126
+ Ok ( deserialized) => Ok ( deserialized) ,
1127
+ Err ( error) => {
1128
+ error ! ( "failed to deserialize {label}: {error:?}" ) ;
1129
+ Err ( Status :: internal ( format ! (
1130
+ "Failed to deserialize {label}: {error:?}."
1131
+ ) ) )
1132
+ }
1133
+ }
1134
+ }
1135
+
1121
1136
#[ cfg( test) ]
1122
1137
mod tests {
1123
1138
use quickwit_opentelemetry:: otlp:: { OTEL_TRACES_INDEX_ID_PATTERN , OtelSignal } ;
@@ -2496,34 +2511,50 @@ mod tests {
2496
2511
2497
2512
#[ test]
2498
2513
fn test_collect_trace_ids ( ) {
2514
+ use quickwit_opentelemetry:: otlp:: TraceId ;
2515
+ use quickwit_search:: Span ;
2516
+ use tantivy:: DateTime ;
2499
2517
{
2500
- let agg_result_json = r#"[]"# ;
2501
- let ( trace_ids, _span_timestamps_range) = collect_trace_ids ( agg_result_json) . unwrap ( ) ;
2518
+ let agg_result: Vec < Span > = Vec :: new ( ) ;
2519
+ let agg_result_postcard = postcard:: to_stdvec ( & agg_result) . unwrap ( ) ;
2520
+ let ( trace_ids, _span_timestamps_range) =
2521
+ collect_trace_ids ( & agg_result_postcard) . unwrap ( ) ;
2502
2522
assert ! ( trace_ids. is_empty( ) ) ;
2503
2523
}
2504
2524
{
2505
- let agg_result_json = r#"[
2506
- {
2507
- "trace_id": "01010101010101010101010101010101",
2508
- "span_timestamp": 1684857492783747000
2509
- }
2510
- ]"# ;
2511
- let ( trace_ids, span_timestamps_range) = collect_trace_ids ( agg_result_json) . unwrap ( ) ;
2525
+ let agg_result = vec ! [ Span {
2526
+ trace_id: TraceId :: new( [
2527
+ 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 , 0x01 ,
2528
+ 0x01 , 0x01 , 0x01 ,
2529
+ ] ) ,
2530
+ span_timestamp: DateTime :: from_timestamp_nanos( 1684857492783747000 ) ,
2531
+ } ] ;
2532
+ let agg_result_postcard = postcard:: to_stdvec ( & agg_result) . unwrap ( ) ;
2533
+ let ( trace_ids, span_timestamps_range) =
2534
+ collect_trace_ids ( & agg_result_postcard) . unwrap ( ) ;
2512
2535
assert_eq ! ( trace_ids. len( ) , 1 ) ;
2513
2536
assert_eq ! ( span_timestamps_range, 1684857492 ..=1684857492 ) ;
2514
2537
}
2515
2538
{
2516
- let agg_result_json = r#"[
2517
- {
2518
- "trace_id": "0102030405060708090a0b0c0d0e0f10",
2519
- "span_timestamp": 1684857492783747000
2539
+ let agg_result = vec ! [
2540
+ Span {
2541
+ trace_id: TraceId :: new( [
2542
+ 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0a , 0x0b , 0x0c ,
2543
+ 0x0d , 0x0e , 0x0f , 0x10 ,
2544
+ ] ) ,
2545
+ span_timestamp: DateTime :: from_timestamp_nanos( 1684857492783747000 ) ,
2520
2546
} ,
2521
- {
2522
- "trace_id": "02020202020202020202020202020202",
2523
- "span_timestamp": 1684857826019627000
2524
- }
2525
- ]"# ;
2526
- let ( trace_ids, span_timestamps_range) = collect_trace_ids ( agg_result_json) . unwrap ( ) ;
2547
+ Span {
2548
+ trace_id: TraceId :: new( [
2549
+ 0x02 , 0x02 , 0x02 , 0x02 , 0x02 , 0x02 , 0x02 , 0x02 , 0x02 , 0x02 , 0x02 , 0x02 ,
2550
+ 0x02 , 0x02 , 0x02 , 0x02 ,
2551
+ ] ) ,
2552
+ span_timestamp: DateTime :: from_timestamp_nanos( 1684857826019627000 ) ,
2553
+ } ,
2554
+ ] ;
2555
+ let agg_result_postcard = postcard:: to_stdvec ( & agg_result) . unwrap ( ) ;
2556
+ let ( trace_ids, span_timestamps_range) =
2557
+ collect_trace_ids ( & agg_result_postcard) . unwrap ( ) ;
2527
2558
assert_eq ! ( trace_ids. len( ) , 2 ) ;
2528
2559
assert_eq ! ( span_timestamps_range, 1684857492 ..=1684857826 ) ;
2529
2560
}
0 commit comments