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 3605a8a
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 665 deletions.
100 changes: 0 additions & 100 deletions canary-checker/docs/cli.mdx

This file was deleted.

46 changes: 3 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,7 @@ 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 +23,14 @@ 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
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
75 changes: 1 addition & 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,7 @@ 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
82 changes: 5 additions & 77 deletions canary-checker/docs/concepts/secret-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Avoid inlining secrets, use `valueFrom` and <CommonLink to="authentication">EnvV

Using a HTTP health check as an example for static values:

```yaml title="http-basic-auth-static.yaml" file=../../../modules/canary-checker/fixtures/minimal/http_auth.yaml
```yaml title="http-basic-auth.yaml" file=../../../modules/canary-checker/fixtures/minimal/http_auth_static_pass.yaml
```

## Configmaps
Expand All @@ -32,26 +32,7 @@ To use a configmap, we first need to create the configmap:
kubectl create configmap basic-auth --from-literal=user=hello --from-literal=pass=world -n default
```

```yaml title="http-basic-auth-configmap.yaml"
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-basic-auth-configmap
spec:
http:
- url: https://httpbin.org/basic-auth/hello/world
responseCodes: [200]
authentication:
username:
valueFrom:
configMapKeyRef:
name: basic-auth
key: user
password:
valueFrom:
configMapKeyRef:
name: basic-auth
key: pass
```yaml title="http-basic-auth.yaml" file=../../../modules/canary-checker/fixtures/minimal/http_auth_from_config_map.yaml
```

## Secrets
Expand All @@ -62,24 +43,7 @@ To use a secret, first we create the secret:
kubectl create secret generic basic-auth --from-literal=user=hello --from-literal=pass=world -n default
```

```yaml title="http-basic-auth-secret.yaml"
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-basic-auth-configmap
spec:
http:
- url: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
username:
valueFrom:
secretKeyRef:
name: basic-auth
key: user
password:
valueFrom:
secretKeyRef:
name: basic-auth
key: pass
```yaml title="http-basic-auth.yaml" file=../../../modules/canary-checker/fixtures/minimal/http_auth_from_secret.yaml
```

## Helm Values
Expand All @@ -90,50 +54,14 @@ To use a secret, first we deploy a helm chart
helm install podinfo podinfo/podinfo -n podinfo --set ingress.enabled=true
```

```yaml title="http-from-helm.yaml"
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-from-helm
spec:
http:
- env:
- name: url
valueFrom:
helmRef:
name: podinfo
key: .ingress.hosts[0].host

url: $(url)
```yaml title="http-from-helm.yaml" file=../../../modules/canary-checker/fixtures/minimal/http_auth_from_helm_ref.yaml
```

## Service Accounts

Checks can use service accounts for authentication with external services that have existing trust established

```yaml title="http-service-accounts.yaml"
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-basic-auth-configmap
spec:
http:

interval: 30
http:
- name: vault-example-sre
description: "HashiCorp Vault functionality check."
url: https://vault.example/v1/auth/kubernetes/login
env:
- name: TOKEN
valueFrom:
serviceAccount: default-account
templateBody: true
body: |
{
"jwt": "$(TOKEN)",
"role": "example-role"
}
```yaml title="http-service-accounts.yaml" file=../../../modules/canary-checker/fixtures/minimal/http_auth_from_service_account.yaml

```

Expand Down
Loading

0 comments on commit 3605a8a

Please sign in to comment.