Skip to content

Commit

Permalink
refactor: avoid unnecessary alloc by using unwrap_or_else (GreptimeTe…
Browse files Browse the repository at this point in the history
…am#3742)

feat(promql): address post-merge CR
  • Loading branch information
etolbakov authored Apr 19, 2024
1 parent 314f270 commit 2114b15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/operator/src/statement/tql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ impl StatementExecutor {
end: eval.end,
step: eval.step,
query: eval.query,
lookback: eval.lookback.unwrap_or(DEFAULT_LOOKBACK_STRING.to_string()),
lookback: eval
.lookback
.unwrap_or_else(|| DEFAULT_LOOKBACK_STRING.to_string()),
};
QueryLanguageParser::parse_promql(&promql, &query_ctx).context(ParseQuerySnafu)?
}
Expand All @@ -46,7 +48,7 @@ impl StatementExecutor {
query: explain.query,
lookback: explain
.lookback
.unwrap_or(DEFAULT_LOOKBACK_STRING.to_string()),
.unwrap_or_else(|| DEFAULT_LOOKBACK_STRING.to_string()),
..PromQuery::default()
};
let explain_node_name = if explain.is_verbose {
Expand All @@ -69,7 +71,7 @@ impl StatementExecutor {
query: analyze.query,
lookback: analyze
.lookback
.unwrap_or(DEFAULT_LOOKBACK_STRING.to_string()),
.unwrap_or_else(|| DEFAULT_LOOKBACK_STRING.to_string()),
};
let analyze_node_name = if analyze.is_verbose {
ANALYZE_VERBOSE_NODE_NAME
Expand Down
2 changes: 1 addition & 1 deletion src/servers/src/http/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl From<PromqlQuery> for PromQuery {
step: query.step,
lookback: query
.lookback
.unwrap_or(DEFAULT_LOOKBACK_STRING.to_string()),
.unwrap_or_else(|| DEFAULT_LOOKBACK_STRING.to_string()),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/servers/src/http/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub async fn instant_query(
lookback: params
.lookback
.or(form_params.lookback)
.unwrap_or(DEFAULT_LOOKBACK_STRING.to_string()),
.unwrap_or_else(|| DEFAULT_LOOKBACK_STRING.to_string()),
};

let result = handler.do_query(&prom_query, query_ctx).await;
Expand Down Expand Up @@ -225,7 +225,7 @@ pub async fn range_query(
lookback: params
.lookback
.or(form_params.lookback)
.unwrap_or(DEFAULT_LOOKBACK_STRING.to_string()),
.unwrap_or_else(|| DEFAULT_LOOKBACK_STRING.to_string()),
};

let result = handler.do_query(&prom_query, query_ctx).await;
Expand Down Expand Up @@ -324,7 +324,7 @@ pub async fn labels_query(
let lookback = params
.lookback
.or(form_params.lookback)
.unwrap_or(DEFAULT_LOOKBACK_STRING.to_string());
.unwrap_or_else(|| DEFAULT_LOOKBACK_STRING.to_string());

let mut labels = HashSet::new();
let _ = labels.insert(METRIC_NAME.to_string());
Expand Down Expand Up @@ -607,7 +607,7 @@ pub async fn label_values_query(
let end = params.end.unwrap_or_else(current_time_rfc3339);
let lookback = params
.lookback
.unwrap_or(DEFAULT_LOOKBACK_STRING.to_string());
.unwrap_or_else(|| DEFAULT_LOOKBACK_STRING.to_string());

let mut label_values = HashSet::new();

Expand Down Expand Up @@ -752,7 +752,7 @@ pub async fn series_query(
let lookback = params
.lookback
.or(form_params.lookback)
.unwrap_or(DEFAULT_LOOKBACK_STRING.to_string());
.unwrap_or_else(|| DEFAULT_LOOKBACK_STRING.to_string());

let mut series = Vec::new();
let mut merge_map = HashMap::new();
Expand Down

0 comments on commit 2114b15

Please sign in to comment.