mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-03 11:52:54 +00:00
fix(query_range): skip data field on errors (#5520)
* fix: skip serializing PrometheusResponse when None * fix: fix unit test * chore: clippy
This commit is contained in:
@@ -95,7 +95,7 @@ pub struct PromData {
|
||||
pub result: PromQueryResult,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
#[derive(Debug, Default, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(untagged)]
|
||||
pub enum PrometheusResponse {
|
||||
PromData(PromData),
|
||||
@@ -106,6 +106,8 @@ pub enum PrometheusResponse {
|
||||
BuildInfo(OwnedBuildInfo),
|
||||
#[serde(skip_deserializing)]
|
||||
ParseResult(promql_parser::parser::Expr),
|
||||
#[default]
|
||||
None,
|
||||
}
|
||||
|
||||
impl PrometheusResponse {
|
||||
@@ -144,11 +146,9 @@ impl PrometheusResponse {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PrometheusResponse {
|
||||
fn default() -> Self {
|
||||
PrometheusResponse::PromData(Default::default())
|
||||
pub fn is_none(&self) -> bool {
|
||||
matches!(self, PrometheusResponse::None)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ use crate::http::prometheus::{
|
||||
#[derive(Debug, Default, Serialize, Deserialize, PartialEq)]
|
||||
pub struct PrometheusJsonResponse {
|
||||
pub status: String,
|
||||
#[serde(skip_serializing_if = "PrometheusResponse::is_none")]
|
||||
#[serde(default)]
|
||||
pub data: PrometheusResponse,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error: Option<String>,
|
||||
@@ -90,7 +92,7 @@ impl PrometheusJsonResponse {
|
||||
{
|
||||
PrometheusJsonResponse {
|
||||
status: "error".to_string(),
|
||||
data: PrometheusResponse::default(),
|
||||
data: PrometheusResponse::None,
|
||||
error: Some(reason.into()),
|
||||
error_type: Some(error_type.to_string()),
|
||||
warnings: None,
|
||||
|
||||
@@ -766,7 +766,7 @@ pub async fn test_prom_http_api(store_type: StorageType) {
|
||||
.await;
|
||||
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
|
||||
let data = res.text().await;
|
||||
let expected = "{\"status\":\"error\",\"data\":{\"resultType\":\"\",\"result\":[]},\"error\":\"invalid promql query\",\"errorType\":\"InvalidArguments\"}";
|
||||
let expected = "{\"status\":\"error\",\"error\":\"invalid promql query\",\"errorType\":\"InvalidArguments\"}";
|
||||
assert_eq!(expected, data);
|
||||
|
||||
// range_query with __name__ not-equal matcher
|
||||
|
||||
Reference in New Issue
Block a user