Skip to content

Commit

Permalink
chore: fixtures for docs (#2191)
Browse files Browse the repository at this point in the history
* chore: update fixtures

* changes

* chore: replace `endpoint` with `url`
  • Loading branch information
adityathebe authored Oct 1, 2024
1 parent cd3d9d8 commit 7279dae
Show file tree
Hide file tree
Showing 34 changed files with 359 additions and 35 deletions.
3 changes: 2 additions & 1 deletion fixtures/aws/s3_bucket_pass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ spec:
schedule: "@every 5m"
folder:
# Check for any backup not older than 7 days and min size 25 bytes
- path: s3://flanksource-public
- name: folder check
path: s3://flanksource-public
awsConnection:
region: eu-central-1
minSize: 50M
Expand Down
2 changes: 1 addition & 1 deletion fixtures/datasources/GCP/database_backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ spec:
databaseBackup:
- name: backup
maxAge: 6h
GCP:
gcp:
project: google-project-name
instance: cloudsql-instance-name
18 changes: 18 additions & 0 deletions fixtures/datasources/GCP/database_backup_cred.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: database-backup-example
spec:
schedule: "@every 5m"
databaseBackup:
- name: backup
maxAge: 6h
gcp:
project: google-project-name
instance: cloudsql-instance-name
gcpConnection:
credentials:
valueFrom:
secretKeyRef:
name: gcp-credentials
key: AUTH_ACCESS_TOKEN
14 changes: 14 additions & 0 deletions fixtures/datasources/GCP/database_backup_cred_from_connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: database-backup-example
spec:
schedule: "@every 5m"
databaseBackup:
- name: backup
maxAge: 6h
gcp:
project: google-project-name
instance: cloudsql-instance-name
gcpConnection:
connection: connection://gcp/internal
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);
11 changes: 11 additions & 0 deletions fixtures/datasources/folder_single_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: folder-check
spec:
schedule: "@every 5m"
folder:
- path: /etc/
name: folder-check-min
description: Checks if there are at least 10 files in the folder
minCount: 10
13 changes: 13 additions & 0 deletions fixtures/datasources/folder_with_filter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: folder-check
spec:
schedule: "@every 5m"
folder:
- name: pg-backup checks
path: /data/backups
filter:
regex: "pg-backups-.*.zip"
maxAge: 1d # require a daily backup
minSize: 10mb # the backup should be at least 10mb
26 changes: 26 additions & 0 deletions fixtures/datasources/postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: postgres-check
spec:
schedule: '@every 30s'
postgres: # or mysql, mssql
- name: postgres schemas check
url: "postgres://$(username):$(password)@postgres.default.svc:5432/postgres?sslmode=disable"
username:
valueFrom:
secretKeyRef:
name: postgres-credentials
key: USERNAME
password:
valueFrom:
secretKeyRef:
name: postgres-credentials
key: PASSWORD
query: SELECT current_schemas(true)
display:
template: |
{{- range $r := .results.rows }}
{{- $r.current_schemas}}
{{- end}}
results: 1
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()
: '{}'
2 changes: 1 addition & 1 deletion fixtures/external/catalog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Canary
metadata:
name: node-catalogs
spec:
interval: 30
schedule: '@every 30s'
catalog:
- name: ingress-catalog-check
selector:
Expand Down
2 changes: 1 addition & 1 deletion fixtures/external/crossplane-kubernetes-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
bucketName: "{{ (index .resources 0).Object.metadata.name }}"
objectPath: dummy
region: "{{ (index .resources 0).Object.spec.forProvider.locationConstraint }}"
endpoint: http://localstack-localstack.localstack.svc.cluster.local:4566
url: http://localstack-localstack.localstack.svc.cluster.local:4566
usePathStyle: true
accessKey:
value: test
Expand Down
21 changes: 21 additions & 0 deletions fixtures/k8s/helm_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: helm-check
spec:
schedule: '@every 30s'
helm:
- name: helm check
chartmuseum: http://chartmuseum.default:8080
project: library
auth:
username:
valueFrom:
secretKeyRef:
name: helm-credentials
key: USERNAME
password:
valueFrom:
secretKeyRef:
name: helm-credentials
key: PASSWORD
3 changes: 2 additions & 1 deletion fixtures/k8s/http_auth_configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ metadata:
namespace: canaries
spec:
http:
- endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
- name: http basic auth check
url: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
responseCodes: [200]
username:
valueFrom:
Expand Down
3 changes: 2 additions & 1 deletion fixtures/k8s/http_auth_secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ metadata:
namespace: canaries
spec:
http:
- endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
- name: http basic auth check
url: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
responseCodes: [200]
username:
valueFrom:
Expand Down
11 changes: 11 additions & 0 deletions fixtures/minimal/containerd-pull.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: containerd-pull-check
spec:
schedule: '@every 30s'
containerd: # use docker if running outside kubernetes / docker
- name: pull image
image: docker.io/library/busybox:1.31.1
expectedDigest: sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209
expectedSize: 764556
11 changes: 11 additions & 0 deletions fixtures/minimal/containerd-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: containerd-push-check
spec:
schedule: '@every 30s'
containerdPush: # use dockerPush if running outside kubernetes / docker
- name: ContainerdPush Check
image: docker.io/library/busybox:1.31.1
username: <insert-username>
password: <insert-password>
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(", ")
14 changes: 10 additions & 4 deletions fixtures/minimal/http_auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ metadata:
spec:
http:
- name: "basic auth fail"
endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
url: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
responseCodes: [401]
- name: "basic auth pass"
endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
url: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
responseCodes: [200]
username:
value: hello
valueFrom:
secretKeyRef:
name: httpbin-secret
key: username
password:
value: world
valueFrom:
secretKeyRef:
name: httpbin-secret
key: password
16 changes: 16 additions & 0 deletions fixtures/minimal/http_auth_static_pass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: http-basic-auth-static
spec:
http:
- name: "basic auth fail"
url: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
responseCodes: [401]
- name: "basic auth pass"
url: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
responseCodes: [200]
username:
value: hello
password:
value: world
4 changes: 2 additions & 2 deletions fixtures/minimal/http_fail.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ metadata:
spec:
schedule: "@every 5m"
http:
- endpoint: https://httpbin.demo.aws.flanksource.com/status/500
- url: https://httpbin.demo.aws.flanksource.com/status/500
name: http fail response code check
responseCodes: [200]
- endpoint: https://httpbin.demo.aws.flanksource.com/status/200
- url: https://httpbin.demo.aws.flanksource.com/status/200
name: http fail test expr check
display:
expr: string(code) + " should be 500"
Expand Down
Loading

0 comments on commit 7279dae

Please sign in to comment.