Transformation
The transform
can be used to convert one check into multiple checks programmatically.
alertmanager-check.yamlapiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: alertmanager-check
spec:
schedule: "@every 5m"
alertmanager:
- url: alertmanager.example.com
name: alert-manager-transform
alerts:
- .*
ignore:
- KubeScheduler.*
transform:
javascript: |
var out = _.map(results, function(r) {
return {
name: r.name,
labels: r.labels,
icon: 'alert',
message: r.message,
description: r.message,
}
})
JSON.stringify(out);
In the above example, the check returns multiple alerts from alertmanager. By default, all those alerts are grouped in a single check.
But if we want to display each alert as its own check in the UI, we can use the transform
function for this. The transform function takes a Template
as input and the output from the template expected are the checks in JSON format.
For example, if there are 9 different alerts, each alert has its own check that can be managed and interacted with equally.
Transform Result
Field | Description | Scheme |
---|---|---|
name* | Name of the check to use, the name is used to lookup existing checks to update |
|
pass* | Set to true if the health check is passing |
|
duration | Time in ms for duration of the check | int64 |
invalid | Set to true if the check is not configured correctly, and can never pass |
|
deletedAt | The time the check or event logically ended | time.Time |
error | An error message to be shown, if non-empty sets |
|
icon | ||
labels | map[string]string | |
message | Informational message to be shown to users |
|
namespace |
| |
start | The time the check or event logically started (e.g if coming from an external source) | time.Time |
data | map[string]interface{} | |
description |
| |
detail | interface{} | |
displayType |
| |
endpoint |
| |
metrics | Add custom metrics to be exported | |
transformDeleteStrategy | How to handle checks that were returned in a previous transformation, but not in the current | MarkHealthy | MarkUnhealthy | Ignore |
type |
|
Transforms can either update checks in-place or return new checks.
Updating checks in-place
The update a check in place, return a JSON string of TransformResult
with the updated fields
Creating new checks
To create a new check, return a JSON string of []TransformResult
containing the new checks.