Skip to content

Commit

Permalink
chore: extract common logic into a method for traces
Browse files Browse the repository at this point in the history
  • Loading branch information
etolbakov authored Dec 9, 2023
1 parent 7e2fc6d commit 2153182
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions quickwit/quickwit-serve/src/jaeger_api/rest_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use hyper::StatusCode;
use itertools::Itertools;
use quickwit_jaeger::JaegerService;
use quickwit_proto::jaeger::api_v2::Span;
use quickwit_proto::jaeger::storage::v1::span_reader_plugin_server::SpanReaderPlugin;
use quickwit_proto::jaeger::storage::v1::{
FindTracesRequest, GetOperationsRequest, GetServicesRequest, GetTraceRequest,
Expand Down Expand Up @@ -198,18 +199,9 @@ async fn jaeger_traces_search(
.unwrap()
.into_inner();
let SpansResponseChunk { spans } = span_stream.next().await.unwrap().unwrap();

let result: Vec<JaegerTrace> = spans
.iter()
.map(JaegerSpan::find_better_name_for_pb_convert)
.group_by(|span| span.trace_id.clone())
.into_iter()
.map(|(span_id, group)| JaegerTrace::new(span_id, group.collect_vec()))
.collect_vec();

info!("traces {:?}", result);

Ok(JaegerResponseBody { data: result })
Ok(JaegerResponseBody {
data: create_jaeger_trace(spans),
})
}

async fn jaeger_get_trace_by_id(
Expand All @@ -224,16 +216,21 @@ async fn jaeger_get_trace_by_id(
.unwrap()
.into_inner();
let SpansResponseChunk { spans } = span_stream.next().await.unwrap().unwrap();
Ok(JaegerResponseBody {
data: create_jaeger_trace(spans),
})
}

fn create_jaeger_trace(spans: Vec<Span>) -> Vec<JaegerTrace> {
let result: Vec<JaegerTrace> = spans
.iter()
.map(JaegerSpan::find_better_name_for_pb_convert)
.group_by(|span| span.trace_id.clone())
.into_iter()
.map(|(span_id, group)| JaegerTrace::new(span_id, group.collect_vec()))
.collect_vec();

Ok(JaegerResponseBody { data: result })
info!("traces {:?}", result);
result
}

fn make_jaeger_api_response<T: serde::Serialize>(
Expand Down

0 comments on commit 2153182

Please sign in to comment.