Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Oct 1, 2024
1 parent 46f76f5 commit af69a5b
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 1 deletion.
25 changes: 25 additions & 0 deletions fixtures/datasources/alertmanager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: 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);
73 changes: 73 additions & 0 deletions fixtures/elasticsearch/stateful_metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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: "http://elasticsearch.canaries.svc.cluster.local:9200/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()
: '{}'
11 changes: 11 additions & 0 deletions fixtures/minimal/display-with-cel_pass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: currency-converter-display-cel
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)"
11 changes: 11 additions & 0 deletions fixtures/minimal/display-with-gotemplate_pass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: currency-converter-display-gotemplate
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}}"
19 changes: 19 additions & 0 deletions fixtures/minimal/display-with-javascript_pass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: currency-converter-display-js
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) {
display.push(currency + " = " + currencyCodes[currency] + json.rates[currency])
}
// final output to display
"$1 = " + display.join(", ")
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion fixtures/minimal/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ resources:
- dns_pass.yaml
- http_fail.yaml
- http_pass_single.yaml
- http_timeout_fail.yaml
- http_timeout_fail.yaml
- http_auth_static.yaml
- display-with-cel.yaml
- display-with-gotemplate.yaml
- display-with-javascript.yaml

0 comments on commit af69a5b

Please sign in to comment.