diff --git a/src/parser/ast.rs b/src/parser/ast.rs index 824967f..5241f9a 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -8,7 +8,6 @@ use crate::parser::TokenType; /// EvalStmt holds an expression and information on the range it should /// be evaluated on. -// TODO: pub struct EvalStmt { expr: Expr, // Expression to be evaluated. diff --git a/src/parser/promql.y b/src/parser/promql.y index 0600a24..2779f99 100644 --- a/src/parser/promql.y +++ b/src/parser/promql.y @@ -394,7 +394,6 @@ use std::time::{Duration, Instant}; use crate::parser::{lexeme_to_string, span_to_string, lexeme_to_token}; use crate::parser::{Expr, Token}; -use crate::parser::value::STALE_STR; use crate::label::{self, Label, Labels, MatchOp, Matcher, Matchers, METRIC_NAME, new_matcher}; diff --git a/src/parser/value.rs b/src/parser/value.rs index fe918ab..c76f6e4 100644 --- a/src/parser/value.rs +++ b/src/parser/value.rs @@ -1,7 +1,5 @@ use std::fmt::{self, Display}; -pub const STALE_STR: &'static str = "stale"; - #[derive(Debug, Clone, Copy, PartialEq)] pub enum ValueType { Vector, diff --git a/src/util/duration.rs b/src/util/duration.rs index ca541db..05c91f5 100644 --- a/src/util/duration.rs +++ b/src/util/duration.rs @@ -2,9 +2,6 @@ use lazy_static::lazy_static; use regex::Regex; use std::time::Duration; -/// 290 years -const MAX_DURATION: Duration = Duration::from_secs(60 * 60 * 24 * 365 * 290); - lazy_static! { static ref DURATION_RE: Regex = Regex::new( r"^((?P[0-9]+)y)?((?P[0-9]+)w)?((?P[0-9]+)d)?((?P[0-9]+)h)?((?P[0-9]+)m)?((?P[0-9]+)s)?((?P[0-9]+)ms)?$", @@ -56,7 +53,7 @@ pub fn parse_duration(ds: &str) -> Result { add("second", 1000); // s add("milli", 1); // ms - if result.as_secs() > MAX_DURATION.as_secs() { + if result > Duration::MAX { return Err("duration out of range".into()); } @@ -118,16 +115,10 @@ mod tests { #[test] fn test_invalid_duration() { let ds = vec![ - "1", - "1y1m1d", - "-1w", - "1.5d", - "d", - "294y", - "200y10400w", - "107675d", - "2584200h", + "1", "1y1m1d", "-1w", "1.5d", "d", "", + // these are invalid in PromQL Go Version + // "294y", "200y10400w", "107675d", "2584200h", ]; for d in ds { assert!(parse_duration(d).is_err(), "{} is invalid duration!", d);