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
spec:
schedule: "@every 5m"
alertmanager:
- url: http://kube-prometheus-stack-alertmanager.monitoring:9093
name: alertmanager-check
alerts:
- .*
ignore:
- KubeScheduler.*
exclude_filters:
namespace: elastic-system
transform:
expr: |
results.alerts.map(r, {
'name': r.name + r.fingerprint,
'namespace': 'namespace' in r.labels ? r.labels.namespace : '',
'labels': r.labels,
'icon': 'alert',
'message': r.message,
'description': r.message,
}).toJSON()
relationships:
components:
- name:
label: pod
namespace:
label: namespace
type:
value: KubernetesPod
configs:
- name:
label: pod
namespace:
label: namespace
type:
value: Kubernetes::Pod
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 |
| |
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.