Skip to content

Commit

Permalink
chore: fixture updates
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Oct 1, 2024
1 parent db554c9 commit 0777c64
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 666 deletions.
100 changes: 0 additions & 100 deletions canary-checker/docs/cli.mdx

This file was deleted.

49 changes: 6 additions & 43 deletions canary-checker/docs/concepts/expressions/display-formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@ Canary checker can format the results of checks using the `display` field. All e

In this example we get the current exchange rate:

```yaml title="display-with-gotemplate.yaml"
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-check
spec:
http:
- name: USD
url: https://api.frankfurter.app/latest?from=USD&to=GBP,EUR,ILS,ZAR
display:
template: '$1 = €{{.json.rates.EUR}}, £{{.json.rates.GBP}}, ₪{{.json.rates.ILS}}'
```yaml title="display-with-gotemplate.yaml" file=../../../../modules/canary-checker/fixtures/minimal/display-with-gotemplate_pass.yaml

```

Which would display:
Expand All @@ -33,44 +24,16 @@ See <CommonLink to="gotemplate">Go Template</CommonLink>

The equivalent using CEL expressions would be:

```yaml title="display-with-cel.yaml"
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-check
spec:
http:
- name: USD
url: https://api.frankfurter.app/latest?from=USD&to=GBP,EUR,ILS,ZAR
display:
expr: "'$1 = €' + string(json.rates.EUR) + ', £' + string(json.rates.GBP) + ', ₪' + string(json.rates.ILS)"
```yaml title="display-with-cel.yaml" file=../../../../modules/canary-checker/fixtures/minimal/display-with-cel_pass.yaml

```

See <CommonLink to="cel">Cel Expressions</CommonLink> for a function reference

## Javascript

```yaml title="display-with-javascript.yaml"
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-check
spec:
http:
- name: USD
url: https://api.frankfurter.app/latest?from=USD&to=GBP,EUR,ILS
display:
javascript: |
currencyCodes = { "EUR": "€", "GBP": "£", "ILS": "₪"}
display = ""
for (var currency in json.rates) {
if (display != "") {
display += ", "
}
display += currency + " = " + currencyCodes[currency] + json.rates[currency] + ", "
}
"$1 = " + display
```yaml title="display-with-javascript.yaml" file=../../../../modules/canary-checker/fixtures/minimal/display-with-javascript_pass.yaml

```

:::info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ these default behaviors can be changed using the `test` field:
In the example below the http check fails if the HTTP response header contains an 'Authorization' field.

```yaml title=http-check-expr.yaml file=../../../../modules/canary-checker/fixtures/minimal/http_no_auth_pass.yaml

```

:::info Boolean
Expand Down
27 changes: 1 addition & 26 deletions canary-checker/docs/concepts/expressions/transforms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,7 @@ import TransformFields from './_transform_fields.mdx'

The `transform` can be used to convert one check into multiple checks programmatically.

```yaml
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: alertmanager-check
spec:
schedule: "*/5 * * * *"
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);
```yaml title="alertmanager-check.yaml" file=../../../../modules/canary-checker/fixtures/datasources/alertmanager.yaml
```

In the above example, the check returns multiple alerts from alertmanager. By default, all those alerts are grouped in a single check.
Expand Down
1 change: 1 addition & 0 deletions canary-checker/docs/concepts/metrics/custom-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Canary checker can export custom metrics from any check type, replacing and/or c
In the example below, exchange rates against the USD are exported by first calling an HTTP api and then using the values from the JSON response to create the metrics:

```yaml title="exchange-rates-exporter.yaml" file=../../../../modules/canary-checker/fixtures/minimal/metrics-multiple.yaml

```

Which would output:
Expand Down
76 changes: 2 additions & 74 deletions canary-checker/docs/concepts/metrics/stateful-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,8 @@ title: Stateful Metrics

Metrics can be generated from time based data, e.g. logs per minute, logins per second by using the output of one check execution as the input to the next.

```yaml
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: 'container-log-counts'
namespace: observability
# The schedule can be as short or as long as you want, the query will always search for log
# since the last query
schedule: '@every 5m'
http:
- name: container_log_volume
url: 'https://elasticsearch/logstash-*/_search'
headers:
- name: Content-Type
value: application/json
templateBody: true
test:
# if no logs are found, fail the health check
expr: json.?aggregations.logs.doc_count.orValue(0) > 0
# query for log counts by namespace, container and pod that have been created since the last check
body: >-
{
"size": 0,
"aggs": {
"logs": {
"filter": {
"range": {
"@timestamp" : {
{{- if last_result.results.max }}
"gte": "{{ last_result.results.max }}"
{{- else }}
"gte": "now-5m"
{{- end }}
}
}
},
"aggs": {
"age": {
"max": {
"field": "@timestamp"
}
},
"labels": {
"multi_terms": {
"terms": [
{ "field": "kubernetes_namespace_name.keyword"},
{ "field": "kubernetes_container_name.keyword"},
{ "field": "kubernetes_pod_name.keyword"}
],
"size": 1000
}
}
}
}
}
}
transform:
# Save the maximum age for usage in subsequent queries and create a metric for each pair
expr: |
json.orValue(null) != null ?
[{
'detail': { 'max': string(json.?aggregations.logs.age.value_as_string.orValue(last_result().?results.max.orValue(time.Now()))) },
'metrics': json.?aggregations.logs.labels.buckets.orValue([]).map(k, {
'name': "namespace_log_count",
'type': "counter",
'value': double(k.doc_count),
'labels': {
"namespace": k.key[0],
"container": k.key[1],
"pod": k.key[2]
}
})
}].toJSON()
: '{}'
```yaml file=../../../../modules/canary-checker/fixtures/elasticsearch/stateful_metrics.yaml

```

This snippet retrieves the `last_result.results.max` value from the last execution ensuring data is not duplicated or missed
Expand Down
Loading

0 comments on commit 0777c64

Please sign in to comment.