New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor alerts #179
Refactor alerts #179
Conversation
Tested the PR, few observations:
{
"alerts": [{
"name": "server-fail-alert1",
"message": "server reported error status",
"rule": {
"field": "http_status",
"operator": "equalTo",
"value": 500,
"repeats": 2,
"within": "5m"
},
"targets": [{
"name": "slack-target",
"server_url": "https://webhook.site/70659a77-386b-4543-ab1d-98addddceeb1",
"api_key": ""
}]
}]
} Error:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The target struct should have format like this
"target_1": {
"type": "webhook",
"url": "https://webhook.site/70659a77-386b-4543-ab1d-98addddceeb1",
"username": "", //optional
"password": "" //optional
"token": "" //optional
},
i.e. add a type
field, that will allow adding more types later
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum Operator { | ||
pub enum NumericOperator { | ||
EqualTo, | ||
GreaterThan, | ||
LessThan, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add more rules here NotEqualTo
, GreaterThanEquals
, LessThanEquals
.
#[serde(rename_all = "camelCase")] | ||
pub struct Alerts { | ||
pub alerts: Vec<Alert>, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Alert { | ||
pub name: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed, let's add a system generated id
here apart from alert name. While saving this to S3, let's use the id
as the file name.
server/src/alerts.rs
Outdated
#[serde(rename_all = "camelCase")] | ||
pub struct Rule { | ||
pub struct NumericRule { | ||
pub field: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of field
, let's call it column
- makes it simpler to understand
field should be checked at time of registering alert. I will add that to validation. It does not make sense to have a fallible code in there. |
Yes, I am not asking to validate after saving. |
Alerts are stored on metadata map which is behind and rwlock. This is fine but having to hold writer lock for alert check is not ideal. This PR refactors code around alerts implementation. Each alerts rule should be self contained with its own interior mutable state if it requires any. Interior mutablity pattern allows for alert to be resolved with shared reference. An alert can now contain different variant of rules which can be state or stateless.
Description
Alerts are stored on metadata map which is behind and rwlock. This is fine but having to hold writer lock for alert check is not ideal. This PR refactors code around alerts implementation. Each alerts rule should be self contained with its own interior mutable state if it requires any. Interior mutablity pattern allows for alert to be resolved with shared reference. An alert can now contain different variant of rules which can be state or stateless.
This PR has: