Skip to content

Commit 6a2ff2e

Browse files
committed
coderabbit suggestions
- added length check to `merge_queried_stats`
1 parent c07edf1 commit 6a2ff2e

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/handlers/http/cluster/utils.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use crate::{
2020
INTRA_CLUSTER_CLIENT,
2121
handlers::http::{base_path_without_preceding_slash, modal::NodeType},
22+
prism::logstream::PrismLogstreamError,
2223
};
2324
use actix_web::http::header;
2425
use chrono::{DateTime, Utc};
@@ -135,7 +136,12 @@ impl StorageStats {
135136
}
136137
}
137138

138-
pub fn merge_queried_stats(stats: Vec<QueriedStats>) -> QueriedStats {
139+
pub fn merge_queried_stats(stats: Vec<QueriedStats>) -> Result<QueriedStats, PrismLogstreamError> {
140+
if stats.len() < 2 {
141+
return Err(PrismLogstreamError::Anyhow(anyhow::Error::msg(
142+
"Expected at least two logstreams in merge_queried_stats",
143+
)));
144+
}
139145
// get the stream name
140146
let stream_name = stats[1].stream.clone();
141147

@@ -167,12 +173,12 @@ pub fn merge_queried_stats(stats: Vec<QueriedStats>) -> QueriedStats {
167173
deleted_size: acc.deleted_size + x.deleted_size,
168174
});
169175

170-
QueriedStats::new(
176+
Ok(QueriedStats::new(
171177
&stream_name,
172178
min_time,
173179
cumulative_ingestion,
174180
cumulative_storage,
175-
)
181+
))
176182
}
177183

178184
pub async fn check_liveness(domain_name: &str) -> bool {

src/handlers/http/modal/query/querier_logstream.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ pub async fn get_stats(
232232
let stats = if let Some(mut ingestor_stats) = ingestor_stats {
233233
ingestor_stats.push(stats);
234234
merge_queried_stats(ingestor_stats)
235+
.map_err(|e| StreamError::Anyhow(anyhow::Error::msg(e.to_string())))?
235236
} else {
236237
stats
237238
};

src/prism/logstream/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async fn get_stats(stream_name: &str) -> Result<QueriedStats, PrismLogstreamErro
136136

137137
let stats = if let Some(mut ingestor_stats) = ingestor_stats {
138138
ingestor_stats.push(stats);
139-
merge_queried_stats(ingestor_stats)
139+
merge_queried_stats(ingestor_stats)?
140140
} else {
141141
stats
142142
};

0 commit comments

Comments
 (0)