Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: treat all number types as field candidates #3670

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/servers/src/http/prometheus_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use super::header::{collect_plan_metrics, GREPTIME_DB_HEADER_METRICS};
use super::prometheus::{
PromData, PromQueryResult, PromSeriesMatrix, PromSeriesVector, PrometheusResponse,
};
use crate::error::{CollectRecordbatchSnafu, InternalSnafu, Result};
use crate::error::{CollectRecordbatchSnafu, Result, UnexpectedResultSnafu};

#[derive(Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct PrometheusJsonResponse {
Expand Down Expand Up @@ -183,7 +183,17 @@ impl PrometheusJsonResponse {
timestamp_column_index = Some(i);
}
}
ConcreteDataType::Float64(_) => {
// Treat all value types as field
ConcreteDataType::Float32(_)
| ConcreteDataType::Float64(_)
| ConcreteDataType::Int8(_)
| ConcreteDataType::Int16(_)
| ConcreteDataType::Int32(_)
| ConcreteDataType::Int64(_)
| ConcreteDataType::UInt8(_)
| ConcreteDataType::UInt16(_)
| ConcreteDataType::UInt32(_)
| ConcreteDataType::UInt64(_) => {
if first_field_column_index.is_none() {
first_field_column_index = Some(i);
}
Expand All @@ -195,11 +205,11 @@ impl PrometheusJsonResponse {
}
}

let timestamp_column_index = timestamp_column_index.context(InternalSnafu {
err_msg: "no timestamp column found".to_string(),
let timestamp_column_index = timestamp_column_index.context(UnexpectedResultSnafu {
reason: "no timestamp column found".to_string(),
})?;
let first_field_column_index = first_field_column_index.context(InternalSnafu {
err_msg: "no value column found".to_string(),
let first_field_column_index = first_field_column_index.context(UnexpectedResultSnafu {
reason: "no value column found".to_string(),
})?;

let metric_name = (METRIC_NAME.to_string(), metric_name);
Expand All @@ -226,8 +236,11 @@ impl PrometheusJsonResponse {
.as_any()
.downcast_ref::<TimestampMillisecondVector>()
.unwrap();
let field_column = batch
let casted_field_column = batch
.column(first_field_column_index)
.cast(&ConcreteDataType::float64_datatype())
.unwrap();
let field_column = casted_field_column
.as_any()
.downcast_ref::<Float64Vector>()
.unwrap();
Expand Down
6 changes: 6 additions & 0 deletions tests-integration/tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ pub async fn test_prom_http_api(store_type: StorageType) {
.send()
.await;
assert_eq!(res.status(), StatusCode::OK);
let res = client
.post("/v1/prometheus/api/v1/query_range?query=count(count(up))&start=1&end=100&step=5")
.header("Content-Type", "application/x-www-form-urlencoded")
.send()
.await;
assert_eq!(res.status(), StatusCode::OK);

// labels
let res = client
Expand Down