Skip to content

Commit 640ee44

Browse files
author
Devdutt Shenoi
authored
feat: standardize field names for counts API (#1111)
1 parent 800118b commit 640ee44

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

src/handlers/http/query.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<HttpRespons
114114
};
115115
let count_records = counts_req.get_bin_density().await?;
116116
// NOTE: this should not panic, since there is atleast one bin, always
117-
let log_count = count_records[0].log_count;
117+
let count = count_records[0].count;
118118
let response = if query_request.fields {
119119
json!({
120120
"fields": [&column_name],
121-
"records": [json!({column_name: log_count})]
121+
"records": [json!({column_name: count})]
122122
})
123123
} else {
124-
Value::Array(vec![json!({column_name: log_count})])
124+
Value::Array(vec![json!({column_name: count})])
125125
};
126126

127127
let time = time.elapsed().as_secs_f64();
@@ -164,11 +164,7 @@ pub async fn get_counts(
164164
let records = counts_request.get_bin_density().await?;
165165

166166
Ok(web::Json(CountsResponse {
167-
fields: vec![
168-
"counts_start_timestamp".into(),
169-
"counts_end_timestamp".into(),
170-
"log_count".into(),
171-
],
167+
fields: vec!["start_time".into(), "end_time".into(), "count".into()],
172168
records,
173169
}))
174170
}

src/query/mod.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ impl Query {
248248
#[derive(Debug, Serialize, Clone)]
249249
pub struct CountsRecord {
250250
/// Start time of the bin
251-
pub counts_start_timestamp: String,
251+
pub start_time: String,
252252
/// End time of the bin
253-
pub counts_end_timestamp: String,
253+
pub end_time: String,
254254
/// Number of logs in the bin
255-
pub log_count: u64,
255+
pub count: u64,
256256
}
257257

258258
struct TimeBounds {
@@ -299,10 +299,8 @@ impl CountsRequest {
299299

300300
for bin in counts {
301301
// extract start and end time to compare
302-
let counts_start_timestamp = bin.start.timestamp_millis();
303-
let counts_end_timestamp = bin.end.timestamp_millis();
304302
// Sum up the number of rows that fall within the bin
305-
let log_count: u64 = all_manifest_files
303+
let count: u64 = all_manifest_files
306304
.iter()
307305
.flat_map(|m| &m.files)
308306
.filter_map(|f| {
@@ -324,13 +322,9 @@ impl CountsRequest {
324322
.sum();
325323

326324
counts_records.push(CountsRecord {
327-
counts_start_timestamp: DateTime::from_timestamp_millis(counts_start_timestamp)
328-
.unwrap()
329-
.to_rfc3339(),
330-
counts_end_timestamp: DateTime::from_timestamp_millis(counts_end_timestamp)
331-
.unwrap()
332-
.to_rfc3339(),
333-
log_count,
325+
start_time: bin.start.to_rfc3339(),
326+
end_time: bin.end.to_rfc3339(),
327+
count,
334328
});
335329
}
336330
Ok(counts_records)

0 commit comments

Comments
 (0)