Skip to content

Commit

Permalink
support literal on HTTP gateway
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia committed May 25, 2023
1 parent 9ebb212 commit 8e5cf2a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/servers/src/prom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,13 @@ impl PromJsonResponse {
.map(|(tags, mut values)| {
let metric = tags.into_iter().collect();
match result_type {
Some(ValueType::Vector) => Ok(PromSeries {
metric,
value: values.pop(),
..Default::default()
}),
Some(ValueType::Vector) | Some(ValueType::Scalar) | Some(ValueType::String) => {
Ok(PromSeries {
metric,
value: values.pop(),
..Default::default()
})
}
Some(ValueType::Matrix) => Ok(PromSeries {
metric,
values,
Expand Down Expand Up @@ -444,6 +446,7 @@ pub async fn instant_query(
let query_ctx = QueryContext::with(catalog, schema);

let result = handler.do_query(&prom_query, Arc::new(query_ctx)).await;
println!("result: {:?}", result);
let (metric_name, result_type) =
retrieve_metric_name_and_result_type(&prom_query.query).unwrap_or_default();
PromJsonResponse::from_query_result(result, metric_name, result_type).await
Expand Down Expand Up @@ -686,8 +689,8 @@ fn promql_expr_to_metric_name(expr: &PromqlExpr) -> Option<String> {
}
PromqlExpr::Paren(ParenExpr { expr }) => promql_expr_to_metric_name(expr),
PromqlExpr::Subquery(SubqueryExpr { expr, .. }) => promql_expr_to_metric_name(expr),
PromqlExpr::NumberLiteral(_) => None,
PromqlExpr::StringLiteral(_) => None,
PromqlExpr::NumberLiteral(_) => Some(String::new()),
PromqlExpr::StringLiteral(_) => Some(String::new()),
PromqlExpr::Extension(_) => None,
PromqlExpr::VectorSelector(VectorSelector { matchers, .. }) => {
matchers.find_matchers(METRIC_NAME).pop().cloned()
Expand Down

0 comments on commit 8e5cf2a

Please sign in to comment.