Skip to content

Commit

Permalink
limit ALERT metrics to 31 days (#722)
Browse files Browse the repository at this point in the history
Co-authored-by: Darren B <68653294+Devd0@users.noreply.github.com>
  • Loading branch information
DarrenBaldwin07 and DarrenBaldwin07 committed Apr 18, 2024
1 parent 7dc4c26 commit 5c41481
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dataplane-webserver/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use log::error;
use reqwest::{Client, Response};
use serde_json::Value;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

pub mod expression_validator;
pub mod types;

Expand Down Expand Up @@ -132,12 +131,18 @@ pub async fn query_prometheus(
// Check if the time range is within the allowed limits (e.g., 1 day)
let start_sec = start.parse::<u64>().unwrap();
let end_sec = end.parse::<u64>().unwrap();
if end_sec - start_sec > 86_400 {
if end_sec - start_sec > 86_400 && !query.starts_with("ALERTS{") {
// 1 day in seconds
return HttpResponse::BadRequest()
.json("Time range too large, must be less than or equal to 1 day");
}

if query.starts_with("ALERTS{") && end_sec - start_sec > 2_678_400 {
// 31 days in seconds
return HttpResponse::BadRequest()
.json("Time range too large, must be less than or equal to 31 days for ALERT metrics");
}

// Construct query URL
let query_url = format!(
"{}/api/v1/query_range",
Expand Down

0 comments on commit 5c41481

Please sign in to comment.