Skip to content

Commit

Permalink
chore: add request param duration parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
etolbakov authored Dec 8, 2023
1 parent 40400b1 commit de10253
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
7 changes: 7 additions & 0 deletions quickwit/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions quickwit/quickwit-serve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bytesize = { workspace = true }
elasticsearch-dsl = "0.4.15"
futures = { workspace = true }
futures-util = { workspace = true }
go-parse-duration = "0.1.1"
humantime = { workspace = true }
http-serde = { workspace = true }
hyper = { workspace = true }
Expand Down
6 changes: 4 additions & 2 deletions quickwit/quickwit-serve/src/jaeger_api/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ impl JaegerSpan {
.collect_vec();

// TODO what's the best way to handle unwrap here?
let process: JaegerProcess = JaegerProcess::convert_from_proto(span.process.clone().unwrap());
let process: JaegerProcess =
JaegerProcess::convert_from_proto(span.process.clone().unwrap());

Self {
trace_id: bytes_to_hex_string(&span.trace_id),
Expand All @@ -190,7 +191,8 @@ impl JaegerSpan {
tags,
logs,
process,
process_id: "no_value".to_string(), // TODO we need to initialize it somehow to mutate it further
process_id: "no_value".to_string(), /* TODO we need to initialize it somehow to
* mutate it further */
warnings: span.warnings.iter().map(|s| s.to_string()).collect_vec(),
}
}
Expand Down
20 changes: 7 additions & 13 deletions quickwit/quickwit-serve/src/jaeger_api/rest_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ use crate::jaeger_api::model::{
JaegerError, JaegerResponseBody, JaegerSpan, JaegerTrace, TracesSearchQueryParams,
ALL_OPERATIONS, DEFAULT_NUMBER_OF_TRACES,
};
use crate::jaeger_api::util::{hex_string_to_bytes, to_well_known_timestamp};
use crate::jaeger_api::util::{
hex_string_to_bytes, parse_duration_with_units, to_well_known_timestamp,
};
use crate::json_api_response::JsonApiResponse;
use crate::{require, BodyFormat};

Expand Down Expand Up @@ -153,7 +155,6 @@ async fn jaeger_services(
async fn jaeger_service_operations(
service_name: String,
jaeger_service: JaegerService,
// ) -> Result<JaegerSearchBody, JaegerError> {
) -> Result<JaegerResponseBody<Vec<String>>, JaegerError> {
let get_operations_request = GetOperationsRequest {
service: service_name,
Expand All @@ -171,29 +172,22 @@ async fn jaeger_service_operations(
.map(|op| op.name)
.collect_vec();
Ok(JaegerResponseBody::<Vec<String>> { data: operations })
// Ok(JaegerSearchBody {
// data: Some(
// vec,
// ),
// })
}

async fn jaeger_traces_search(
search_params: TracesSearchQueryParams,
jaeger_service: JaegerService,
) -> Result<JaegerResponseBody<Vec<JaegerTrace>>, JaegerError> {
let start_time_min = search_params.start.map(to_well_known_timestamp);
let start_time_max = search_params.end.map(to_well_known_timestamp);
let query = TraceQueryParameters {
service_name: search_params.service.unwrap_or_default(),
operation_name: search_params
.operation
.unwrap_or(ALL_OPERATIONS.to_string()),
tags: Default::default(),
start_time_min,
start_time_max,
duration_min: None, // TODO, e.g. 1.2s, 100ms, 500us
duration_max: None, // TODO, e.g. 1.2s, 100ms, 500us
start_time_min: search_params.start.map(to_well_known_timestamp),
start_time_max: search_params.end.map(to_well_known_timestamp),
duration_min: parse_duration_with_units(search_params.min_duration),
duration_max: parse_duration_with_units(search_params.max_duration),
num_traces: search_params.limit.unwrap_or(DEFAULT_NUMBER_OF_TRACES),
};
let find_traces_request = FindTracesRequest { query: Some(query) };
Expand Down
13 changes: 13 additions & 0 deletions quickwit/quickwit-serve/src/jaeger_api/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use go_parse_duration::parse_duration;
use prost_types::{Duration as WellKnownDuration, Timestamp as WellKnownTimestamp};

// TODO move to `TraceId` and simplify if possible
Expand Down Expand Up @@ -47,6 +48,18 @@ pub fn from_well_known_timestamp(timestamp_opt: &Option<WellKnownTimestamp>) ->
}
}

pub fn parse_duration_with_units(duration_string_opt: Option<String>) -> Option<WellKnownDuration> {
duration_string_opt
.and_then(|duration_string| parse_duration(duration_string.as_str()).ok())
.map(to_well_known_duration)
}

fn to_well_known_duration(timestamp_nanos: i64) -> WellKnownDuration {
let seconds = timestamp_nanos / 1_000_000;
let nanos = (timestamp_nanos % 1_000_000) as i32;
WellKnownDuration { seconds, nanos }
}

pub fn from_well_known_duration(duration_opt: &Option<WellKnownDuration>) -> i64 {
match duration_opt {
Some(duration) => duration.seconds * 1_000_000 + i64::from(duration.nanos / 1000),
Expand Down

0 comments on commit de10253

Please sign in to comment.