parseable icon indicating copy to clipboard operation
parseable copied to clipboard

Refactor alerts

Open trueleo opened this issue 3 years ago • 3 comments

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:

  • [ ] been tested to ensure log ingestion and log query works.
  • [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • [ ] added documentation for new or modified features or behaviors.

trueleo avatar Oct 22 '22 07:10 trueleo

Tested the PR, few observations:

  1. Incorrect alert field causes server to panic. Alert config
{
	"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:

thread 'actix-rt|system:0|arbiter:4' panicked at 'field exists', server/src/alerts.rs:87:51
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

nitisht avatar Oct 23 '22 15:10 nitisht

1. Incorrect alert field causes server to panic. Alert config

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.

trueleo avatar Oct 23 '22 16:10 trueleo

1. Incorrect alert field causes server to panic. Alert config

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.

nitisht avatar Oct 23 '22 16:10 nitisht