Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit ALERT metrics to 31 days #722

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading