Skip to content

Commit 2660449

Browse files
authored
fix: first_event_at value in cluster info (#719)
fix: first_event_at value in GET cluster/info API
1 parent c254fd6 commit 2660449

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

server/src/handlers/http/cluster/utils.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub fn merge_quried_stats(stats: Vec<QueriedStats>) -> QueriedStats {
123123
.iter()
124124
.map(|x| x.creation_time.parse::<DateTime<Utc>>().unwrap())
125125
.min()
126-
.unwrap_or_default();
126+
.unwrap(); // should never be None
127127

128128
// get the stream name
129129
let stream_name = stats[0].stream.clone();
@@ -132,11 +132,13 @@ pub fn merge_quried_stats(stats: Vec<QueriedStats>) -> QueriedStats {
132132
let min_first_event_at = stats
133133
.iter()
134134
.map(|x| match x.first_event_at.as_ref() {
135-
Some(fea) => fea.parse::<DateTime<Utc>>().unwrap_or_default(),
136-
None => Utc::now(),
135+
// we can directly unwrap here because
136+
// we are sure that the first_event_at is a valid date
137+
Some(fea) => fea.parse::<DateTime<Utc>>().unwrap(),
138+
None => Utc::now(), // current time ie the max time
137139
})
138140
.min()
139-
.unwrap_or_else(Utc::now);
141+
.unwrap(); // should never be None
140142

141143
let min_time = stats.iter().map(|x| x.time).min().unwrap_or_else(Utc::now);
142144

server/src/handlers/http/logstream.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ pub async fn get_stats(req: HttpRequest) -> Result<impl Responder, StreamError>
317317
)
318318
}
319319

320-
// ? this case should not happen
321320
None => {
322321
let ingestion_stats = IngestionStats::new(
323322
stats.events,
@@ -330,7 +329,7 @@ pub async fn get_stats(req: HttpRequest) -> Result<impl Responder, StreamError>
330329
QueriedStats::new(
331330
&stream_name,
332331
&stream_meta.created_at,
333-
Some('0'.to_string()),
332+
None,
334333
time,
335334
ingestion_stats,
336335
storage_stats,

0 commit comments

Comments
 (0)