Skip to content

Commit

Permalink
feat!: Remove slack_webhook config parameter and route based on url i…
Browse files Browse the repository at this point in the history
…nstead
  • Loading branch information
stevensdavid committed Jun 25, 2024
1 parent a162489 commit 79fda1f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 45 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ If expectations aren't met for a Probe or Story, a webhook will be sent to any u
...
alerts:
- url: https://webhook.site/54a9a526-c104-42a7-9b76-788e897390d8
- slack_webhook: https://hooks.slack.com/services/T000/B000/XXXX
- url: https://hooks.slack.com/services/T000/B000/XXXX

```

Expand All @@ -161,16 +161,17 @@ The webhook looks as such:
"message": "Probe failed.",
"probe_name": "Your Probe",
"failure_timestamp": "2024-01-26T02:41:02.983025Z",
"trace_id": "123456789abcdef"
"trace_id": "123456789abcdef",
"error_message": "Failed to meet expectation for field 'StatusCode' with operation Equals \"200\". Received: status '500', body '\"Internal Server Error\"' (truncatated to 100 characters)."
}

```

Slack webhooks can also be used through the `slack_webhook` parameter, which are formatted like
Prodzilla will also recognize the Slack webhook domain `hooks.slack.com` and produce messages like:

> Probe Your Probe failed at 2024-06-10 08:16:33.935659994 UTC. Trace ID: 123456789abcdef
> Probe Your Probe failed at 2024-06-10 08:16:33.935659994 UTC. Trace ID: 123456789abcdef. Error: Failed to meet expectation for field 'StatusCode' with operation Equals "200". Received: status '500', body '"Internal Server Error"' (truncatated to 100 characters).
Slack, OpsGenie, and PagerDuty notification integrations are planned.
OpsGenie, and PagerDuty notification integrations are planned.

## Prodzilla Server Endpoints

Expand Down Expand Up @@ -262,8 +263,8 @@ It also outputs structured logs to standard out.
### Tracked metrics
Prodzilla tracks the following metrics:

| Name | Type | Description |
| -------- | -------------- | -------------------------------------------- | |
| Name | Type | Description |
| ---- | ---- | ----------- ||
| runs | Counter(u64) | The total number of executions for this test |
| duration | Histogram(u64) | Time taken to execute the test |
| errors | Counter(u64) | The total number of errors for this test |
Expand Down
55 changes: 25 additions & 30 deletions src/alerts/outbound_webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn alert_if_failure(
)
.await
{
errors.extend(e);
errors.push(e);
}
}
}
Expand Down Expand Up @@ -123,33 +123,29 @@ pub async fn send_alert(
error_message: &str,
failure_timestamp: DateTime<Utc>,
trace_id: Option<String>,
) -> Result<(), Vec<Box<dyn std::error::Error + Send>>> {
// When we have other alert types, add them in some kind of switch here
let mut errors = Vec::new();
if let Some(url) = &alert.url {
if let Err(e) = send_webhook_alert(
url,
probe_name.clone(),
error_message,
failure_timestamp,
trace_id.clone(),
)
.await
{
errors.push(e);
};
}
if let Some(url) = &alert.slack_webhook {
if let Err(e) =
send_slack_alert(url, probe_name, error_message, failure_timestamp, trace_id).await
{
errors.push(e);
};
}
if !errors.is_empty() {
Err(errors)
} else {
Ok(())
) -> Result<(), Box<dyn std::error::Error + Send>> {
let domain = alert.url.split('/').nth(2).unwrap_or("");
match domain {
"hooks.slack.com" => {
send_slack_alert(
&alert.url,
probe_name.clone(),
error_message,
failure_timestamp,
trace_id.clone(),
)
.await
}
_ => {
send_webhook_alert(
&alert.url,
probe_name.clone(),
error_message,
failure_timestamp,
trace_id.clone(),
)
.await
}
}
}

Expand Down Expand Up @@ -178,8 +174,7 @@ mod webhook_tests {

let probe_name = "Some Flow".to_owned();
let alerts = Some(vec![ProbeAlert {
url: Some(format!("{}{}", mock_server.uri(), alert_url.to_owned())),
slack_webhook: None,
url: format!("{}{}", mock_server.uri(), alert_url.to_owned()),
}]);
let failure_timestamp = Utc::now();

Expand Down
5 changes: 1 addition & 4 deletions src/probe/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ pub struct ProbeScheduleParameters {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProbeAlert {
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub slack_webhook: Option<String>,
pub url: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
3 changes: 1 addition & 2 deletions src/probe/probe_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ mod probe_logic_tests {
interval: 0,
},
alerts: Some(vec![ProbeAlert {
url: Some(format!("{}{}", mock_server.uri(), alert_path.to_owned())),
slack_webhook: None,
url: format!("{}{}", mock_server.uri(), alert_path.to_owned()),
}]),
};

Expand Down
3 changes: 1 addition & 2 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ pub mod probe_test_utils {
interval: 0,
},
alerts: Some(vec![ProbeAlert {
url: Some(alert_url),
slack_webhook: None,
url: alert_url,
}]),
}
}
Expand Down

0 comments on commit 79fda1f

Please sign in to comment.