From 0a1915e18b6f7edf0d5af1a7e48c7263bdec84e2 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Tue, 1 Oct 2024 11:07:55 +0545 Subject: [PATCH] chore: more fixtures --- fixtures/datasources/alertmanager.yaml | 25 +++++++ fixtures/datasources/kustomization.yaml | 1 + fixtures/elasticsearch/kustomization.yaml | 1 + fixtures/elasticsearch/stateful_metrics.yaml | 73 +++++++++++++++++++ fixtures/minimal/display-with-cel.yaml | 11 +++ fixtures/minimal/display-with-gotemplate.yaml | 11 +++ fixtures/minimal/display-with-javascript.yaml | 19 +++++ fixtures/minimal/kustomization.yaml | 6 +- 8 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 fixtures/datasources/alertmanager.yaml create mode 100644 fixtures/elasticsearch/stateful_metrics.yaml create mode 100644 fixtures/minimal/display-with-cel.yaml create mode 100644 fixtures/minimal/display-with-gotemplate.yaml create mode 100644 fixtures/minimal/display-with-javascript.yaml diff --git a/fixtures/datasources/alertmanager.yaml b/fixtures/datasources/alertmanager.yaml new file mode 100644 index 000000000..12b2238a1 --- /dev/null +++ b/fixtures/datasources/alertmanager.yaml @@ -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); \ No newline at end of file diff --git a/fixtures/datasources/kustomization.yaml b/fixtures/datasources/kustomization.yaml index b3c4e1ece..b8e0e11a3 100644 --- a/fixtures/datasources/kustomization.yaml +++ b/fixtures/datasources/kustomization.yaml @@ -14,4 +14,5 @@ resources: - prometheus.yaml - redis_fail.yaml - redis_pass.yaml + - alertmanager.yaml - alertmanager_mix.yaml diff --git a/fixtures/elasticsearch/kustomization.yaml b/fixtures/elasticsearch/kustomization.yaml index c05738829..655b4e22e 100644 --- a/fixtures/elasticsearch/kustomization.yaml +++ b/fixtures/elasticsearch/kustomization.yaml @@ -5,3 +5,4 @@ resources: - _setup.yaml - elasticsearch_fail.yaml - elasticsearch_pass.yaml + - stateful_metrics.yaml diff --git a/fixtures/elasticsearch/stateful_metrics.yaml b/fixtures/elasticsearch/stateful_metrics.yaml new file mode 100644 index 000000000..0c6f48b14 --- /dev/null +++ b/fixtures/elasticsearch/stateful_metrics.yaml @@ -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() + : '{}' diff --git a/fixtures/minimal/display-with-cel.yaml b/fixtures/minimal/display-with-cel.yaml new file mode 100644 index 000000000..06d69f00a --- /dev/null +++ b/fixtures/minimal/display-with-cel.yaml @@ -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)" diff --git a/fixtures/minimal/display-with-gotemplate.yaml b/fixtures/minimal/display-with-gotemplate.yaml new file mode 100644 index 000000000..3679c442b --- /dev/null +++ b/fixtures/minimal/display-with-gotemplate.yaml @@ -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}}" diff --git a/fixtures/minimal/display-with-javascript.yaml b/fixtures/minimal/display-with-javascript.yaml new file mode 100644 index 000000000..291ae5106 --- /dev/null +++ b/fixtures/minimal/display-with-javascript.yaml @@ -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(", ") diff --git a/fixtures/minimal/kustomization.yaml b/fixtures/minimal/kustomization.yaml index 8963661ac..9b254014f 100644 --- a/fixtures/minimal/kustomization.yaml +++ b/fixtures/minimal/kustomization.yaml @@ -5,4 +5,8 @@ resources: - dns_pass.yaml - http_fail.yaml - http_pass_single.yaml - - http_timeout_fail.yaml \ No newline at end of file + - http_timeout_fail.yaml + - http_auth_static.yaml + - display-with-cel.yaml + - display-with-gotemplate.yaml + - display-with-javascript.yaml \ No newline at end of file