mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-04 12:22:55 +00:00
fix: label values potential panic (#5921)
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -161,15 +161,11 @@ impl Instance {
|
||||
|
||||
let mut results = Vec::with_capacity(batches.iter().map(|b| b.num_rows()).sum());
|
||||
for batch in batches {
|
||||
// Only one column the results, ensured by `prometheus::label_values_matchers_to_plan`.
|
||||
// Only one column in results, ensured by `prometheus::label_values_matchers_to_plan`.
|
||||
let names = batch.column(0);
|
||||
|
||||
for i in 0..names.len() {
|
||||
let Value::String(name) = names.get(i) else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
results.push(name.into_string());
|
||||
results.push(names.get(i).to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -503,6 +503,9 @@ pub async fn setup_test_prom_app_with_frontend(
|
||||
let sql =
|
||||
"INSERT INTO demo_metrics(idc, val, ts) VALUES ('idc1', 1.1, 0), ('idc2', 2.1, 600000)";
|
||||
run_sql(sql, &instance).await;
|
||||
// insert a row with empty label
|
||||
let sql = "INSERT INTO demo_metrics(val, ts) VALUES (1.1, 0)";
|
||||
run_sql(sql, &instance).await;
|
||||
|
||||
// build physical table
|
||||
let sql = "CREATE TABLE phy2 (ts timestamp(9) time index, val double, host string primary key) engine=metric with ('physical_metric_table' = '')";
|
||||
@@ -512,6 +515,12 @@ pub async fn setup_test_prom_app_with_frontend(
|
||||
let sql = "INSERT INTO demo_metrics_with_nanos(idc, val, ts) VALUES ('idc1', 1.1, 0)";
|
||||
run_sql(sql, &instance).await;
|
||||
|
||||
// a mito table with non-prometheus compatible values
|
||||
let sql = "CREATE TABLE mito (ts timestamp(9) time index, val double, host bigint primary key) engine=mito";
|
||||
run_sql(sql, &instance).await;
|
||||
let sql = "INSERT INTO mito(host, val, ts) VALUES (1, 1.1, 0)";
|
||||
run_sql(sql, &instance).await;
|
||||
|
||||
let http_opts = HttpOptions {
|
||||
addr: format!("127.0.0.1:{}", ports::get_port()),
|
||||
..Default::default()
|
||||
|
||||
@@ -765,6 +765,13 @@ pub async fn test_prom_http_api(store_type: StorageType) {
|
||||
assert!(prom_resp.error.is_none());
|
||||
assert!(prom_resp.error_type.is_none());
|
||||
|
||||
// query non-string value
|
||||
let res = client
|
||||
.get("/v1/prometheus/api/v1/label/host/values?match[]=mito")
|
||||
.send()
|
||||
.await;
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
|
||||
// query `__name__` without match[]
|
||||
// create a physical table and a logical table
|
||||
let res = client
|
||||
@@ -794,6 +801,7 @@ pub async fn test_prom_http_api(store_type: StorageType) {
|
||||
"demo_metrics".to_string(),
|
||||
"demo_metrics_with_nanos".to_string(),
|
||||
"logic_table".to_string(),
|
||||
"mito".to_string(),
|
||||
"numbers".to_string()
|
||||
])
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user