Skip to content

Commit

Permalink
feat(demotion_monitor): add geo to alert
Browse files Browse the repository at this point in the history
  • Loading branch information
blombern committed Sep 4, 2024
1 parent 81a25f5 commit f7007c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/phoenix/demotion_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::{

#[derive(Debug, Clone)]
pub struct BuilderDemotion {
pub geo: String,
pub builder_pubkey: String,
pub builder_id: Option<String>,
pub slot: i64,
Expand All @@ -34,6 +35,7 @@ pub async fn get_builder_demotions(
) -> Result<Vec<BuilderDemotion>> {
let query = "
SELECT
bd.geo,
bd.builder_pubkey,
bb.builder_id,
bd.slot,
Expand All @@ -54,6 +56,7 @@ pub async fn get_builder_demotions(
.map(|rows| {
rows.iter()
.map(|row| BuilderDemotion {
geo: row.get("geo"),
builder_pubkey: row.get("builder_pubkey"),
builder_id: row.try_get("builder_id").ok(),
slot: row.get("slot"),
Expand Down Expand Up @@ -110,11 +113,13 @@ fn format_demotion_message(demotion: &BuilderDemotion) -> String {
let escaped_builder_id = telegram::escape_str(builder_id);
let builder_pubkey = &demotion.builder_pubkey;
let error = telegram::escape_code_block(&demotion.sim_error);
let slot = demotion.slot;
let slot = &demotion.slot;
let geo = &demotion.geo;
formatdoc!(
"
[beaconcha\\.in/slot/{slot}]({explorer_url}/slot/{slot})
slot: `{slot}`
geo: `{geo}`
builder\\_id: `{escaped_builder_id}`
builder\\_pubkey: `{builder_pubkey}`
```
Expand Down
10 changes: 10 additions & 0 deletions src/phoenix/promotion_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ mod tests {
fn test_get_eligible_builders_all_eligible() {
let demotions = vec![
BuilderDemotion {
geo: "rbx".to_string(),
builder_pubkey: "pubkey1".to_string(),
sim_error: "json error: request timeout hit before processing".to_string(),
slot: 1,
builder_id: Some("builder1".to_string()),
},
BuilderDemotion {
geo: "rbx".to_string(),
builder_pubkey: "pubkey2".to_string(),
sim_error: "simulation failed: unknown ancestor".to_string(),
slot: 2,
Expand All @@ -187,12 +189,14 @@ mod tests {
fn test_get_eligible_builders_none_eligible() {
let demotions = vec![
BuilderDemotion {
geo: "rbx".to_string(),
builder_pubkey: "pubkey1".to_string(),
sim_error: "invalid error".to_string(),
slot: 1,
builder_id: Some("builder1".to_string()),
},
BuilderDemotion {
geo: "rbx".to_string(),
builder_pubkey: "pubkey2".to_string(),
sim_error: "simulation failed: unknown ancestor".to_string(),
slot: 2,
Expand All @@ -210,18 +214,21 @@ mod tests {
fn test_get_eligible_builders_some_eligible() {
let demotions = vec![
BuilderDemotion {
geo: "rbx".to_string(),
builder_pubkey: "pubkey1".to_string(),
sim_error: "json error: request timeout hit before processing".to_string(),
slot: 1,
builder_id: Some("builder1".to_string()),
},
BuilderDemotion {
geo: "rbx".to_string(),
builder_pubkey: "pubkey2".to_string(),
sim_error: "invalid error".to_string(),
slot: 2,
builder_id: Some("builder2".to_string()),
},
BuilderDemotion {
geo: "rbx".to_string(),
builder_pubkey: "pubkey2".to_string(),
sim_error: "simulation failed: unknown ancestor".to_string(),
slot: 3,
Expand All @@ -239,18 +246,21 @@ mod tests {
fn test_same_slot_both_valid_and_invalid() {
let demotions = vec![
BuilderDemotion {
geo: "rbx".to_string(),
builder_pubkey: "pubkey2".to_string(),
sim_error: "invalid error".to_string(),
slot: 2,
builder_id: Some("builder2".to_string()),
},
BuilderDemotion {
geo: "rbx".to_string(),
builder_pubkey: "pubkey1".to_string(),
sim_error: "json error: request timeout hit before processing".to_string(),
slot: 1,
builder_id: Some("builder1".to_string()),
},
BuilderDemotion {
geo: "rbx".to_string(),
builder_pubkey: "pubkey2".to_string(),
sim_error: "simulation failed: unknown ancestor".to_string(),
slot: 2,
Expand Down

0 comments on commit f7007c3

Please sign in to comment.