-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9978e6
commit 1454d9a
Showing
5 changed files
with
82 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ | |
pub mod alert; | ||
pub mod replica_alerts; | ||
|
||
#[cfg(test)] | ||
mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use color_eyre::Result; | ||
use pretty_assertions::assert_eq; | ||
|
||
use crate::prometheus::alert::*; | ||
|
||
const SERIALIZED_PROM_ALERT: &str = r#" | ||
groups: | ||
- name: example | ||
rules: | ||
- alert: HighRequestLatency | ||
expr: job:request_latency_seconds:mean5m{job="myjob"} > 0.5 | ||
for: 10m | ||
labels: | ||
severity: page | ||
source: cloud | ||
owner: service | ||
annotations: | ||
summary: High request latency | ||
description: Request latency over 9000"#; | ||
|
||
#[test] | ||
fn test_serialisation_happy_path() -> Result<()> { | ||
let rust_repr = PromAlerts { | ||
groups: vec![AlertGroup { | ||
name: "example".into(), | ||
rules: vec![AlertRules { | ||
alert: "HighRequestLatency".into(), | ||
expr: r#"job:request_latency_seconds:mean5m{job="myjob"} > 0.5"#.into(), | ||
for_: "10m".into(), | ||
labels: Labels { | ||
severity: PrometheusSeverity::Page, | ||
source: "cloud".into(), | ||
owner: "service".into(), | ||
}, | ||
annotations: Annotations { | ||
summary: "High request latency".into(), | ||
description: "Request latency over 9000".into(), | ||
}, | ||
}], | ||
}], | ||
}; | ||
|
||
let yaml_repr: PromAlerts = serde_yaml::from_str(SERIALIZED_PROM_ALERT)?; | ||
assert_eq!(yaml_repr, rust_repr); | ||
|
||
Ok(()) | ||
} |