From 8e5cf2af0c8cebdf6c7dfc4a45a3076cef7ed7a6 Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Thu, 25 May 2023 17:21:00 +0800 Subject: [PATCH] support literal on HTTP gateway Signed-off-by: Ruihang Xia --- src/servers/src/prom.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/servers/src/prom.rs b/src/servers/src/prom.rs index 4669a36fe2b4..61dc205bc978 100644 --- a/src/servers/src/prom.rs +++ b/src/servers/src/prom.rs @@ -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, @@ -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 @@ -686,8 +689,8 @@ fn promql_expr_to_metric_name(expr: &PromqlExpr) -> Option { } 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()