Skip to content

Commit

Permalink
fix: add start and end timestamp to counts api response (#1109)
Browse files Browse the repository at this point in the history
new structure of records in response json to /counts api

```
{
  "counts_start_timestamp": "2025-01-16T17:34:00+00:00",
  "counts_end_timestamp": "2025-01-16T17:47:00+00:00",
  "log_count": 4203450
}
```
  • Loading branch information
nikhilsinhaparseable authored Jan 17, 2025
1 parent 15b903e commit 800118b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/handlers/http/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ pub async fn get_counts(
let records = counts_request.get_bin_density().await?;

Ok(web::Json(CountsResponse {
fields: vec!["counts_timestamp".into(), "log_count".into()],
fields: vec![
"counts_start_timestamp".into(),
"counts_end_timestamp".into(),
"log_count".into(),
],
records,
}))
}
Expand Down
13 changes: 9 additions & 4 deletions src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ impl Query {
#[derive(Debug, Serialize, Clone)]
pub struct CountsRecord {
/// Start time of the bin
pub counts_timestamp: String,
pub counts_start_timestamp: String,
/// End time of the bin
pub counts_end_timestamp: String,
/// Number of logs in the bin
pub log_count: u64,
}
Expand Down Expand Up @@ -297,8 +299,8 @@ impl CountsRequest {

for bin in counts {
// extract start and end time to compare
let counts_timestamp = bin.start.timestamp_millis();

let counts_start_timestamp = bin.start.timestamp_millis();
let counts_end_timestamp = bin.end.timestamp_millis();
// Sum up the number of rows that fall within the bin
let log_count: u64 = all_manifest_files
.iter()
Expand All @@ -322,7 +324,10 @@ impl CountsRequest {
.sum();

counts_records.push(CountsRecord {
counts_timestamp: DateTime::from_timestamp_millis(counts_timestamp)
counts_start_timestamp: DateTime::from_timestamp_millis(counts_start_timestamp)
.unwrap()
.to_rfc3339(),
counts_end_timestamp: DateTime::from_timestamp_millis(counts_end_timestamp)
.unwrap()
.to_rfc3339(),
log_count,
Expand Down

0 comments on commit 800118b

Please sign in to comment.