Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion oximeter/types/versions/src/impls/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ where
}

fn validate_timeseries_name(s: &str) -> Result<&str, MetricsError> {
if regex::Regex::new(TIMESERIES_NAME_REGEX).unwrap().is_match(s) {
if TIMESERIES_NAME_REGEX.is_match(s) {
Ok(s)
} else {
Err(MetricsError::InvalidTimeseriesName)
Expand Down
10 changes: 8 additions & 2 deletions oximeter/types/versions/src/initial/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ use chrono::DateTime;
use chrono::Utc;
use parse_display::Display;
use parse_display::FromStr;
use regex::Regex;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use std::collections::BTreeSet;
use std::num::NonZeroU8;
use std::sync::LazyLock;

pub type TimeseriesKey = u64;

Expand Down Expand Up @@ -158,8 +160,12 @@ pub struct TimeseriesSchema {
// - Zero or more of the above, delimited by '-'.
//
// That describes the target/metric name, and the timeseries is two of those, joined with ':'.
pub(crate) const TIMESERIES_NAME_REGEX: &str =
"^(([a-z]+[a-z0-9]*)(_([a-z0-9]+))*):(([a-z]+[a-z0-9]*)(_([a-z0-9]+))*)$";
pub(crate) static TIMESERIES_NAME_REGEX: LazyLock<Regex> = LazyLock::new(
|| {
Regex::new("^(([a-z]+[a-z0-9]*)(_([a-z0-9]+))*):(([a-z]+[a-z0-9]*)(_([a-z0-9]+))*)$")
.expect("timeseries name validation regex should be valid")
},
);

/// Authorization scope for a timeseries.
///
Expand Down
Loading