Skip to content

Commit

Permalink
Reset analysis data when new month beging (#22)
Browse files Browse the repository at this point in the history
* todo

* Clean analysis data monthly

* Fix compile
  • Loading branch information
fewensa authored Aug 4, 2023
1 parent b44109c commit c2dd63f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions analysis/fishnet/src/store/cluster_store.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::Datelike;
use std::path::PathBuf;

use tokio::fs;
Expand Down Expand Up @@ -94,6 +95,21 @@ impl ClusterState {
let rq_timeout = hstat_plus.value_int("rq_timeout").unwrap_or(0);
let rq_total = hstat_plus.value_int("rq_total").unwrap_or(0);

// check first day of month, and reset month data
let current_date = chrono::Utc::now();
let day = current_date.day();
if day == 1 {
let total_latest = latests
.iter()
.find(|item| item.id == id)
.map(|item| item.rq_total)
.unwrap_or(0);
// if current rq_total less then latest, indicates that envoy has performed a monthly reset
if rq_total < total_latest {
self.reports.retain(|item| item.id != id);
}
}

// update month report
match self.reports.iter_mut().find(|report| report.id == id) {
None => {
Expand Down

0 comments on commit c2dd63f

Please sign in to comment.