Skip to content

Commit

Permalink
Cleanup: gjson checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelThamm committed Sep 25, 2024
1 parent 5e0ff56 commit 6dfba14
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 42 deletions.
5 changes: 3 additions & 2 deletions goss/goss.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Import other goss.yaml files
gossfile:
goss_az_checks.yaml: {}
goss_k8s_checks.yaml: {}
goss_model_checks.yaml: {}
goss_network_checks.yaml: {}
goss_pebble_checks.yaml: {}
goss_relation_checks.yaml: {}

command:
# Grafana post-relation checks
{{ if .Vars.enable_post_relation_tests }}
grafana-related-dashboards:
exec: bash goss/scripts/compare-dashboard-uids.sh {{ .Vars.model_name }} {{ .Vars.apps.grafana.name }} {{ .Vars.apps.alertmanager.name }}
exec: bash goss/scripts/compare-dashboard-uids.sh {{ .Vars.model_name }} {{ .Vars.apps.k8s.grafana.name }} {{ .Vars.apps.k8s.alertmanager.name }}
exit-status: 0
stdout:
have-patterns:
Expand Down
14 changes: 14 additions & 0 deletions goss/goss_az_checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Availability Zone checks
command:
{{ if .Vars.enable_az_tests }}
app-az-distribution:
exec: juju status --format=json -m {{ .Vars.model_name }}
exit-status: 0
stdout:
gjson:
applications.{{ .Vars.apps.machine.prometheus_openstack_exporter.name }}.units.@values.#.machine:
consist-of:
- "0"
- "1"
- "2"
{{ end }}
21 changes: 13 additions & 8 deletions goss/goss_k8s_checks.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# Kubernetes-type checks
command:
{{ if .Vars.enable_k8s_tests }}
loki-pod-status-healthy:
exec: kubectl get pod {{ .Vars.apps.loki.name }}-0 -n {{ .Vars.model_name }} -o json | jq -r '[.status.conditions[] | .status == "True"] | all'
pod-status-healthy:
exec: kubectl get pods -n {{ .Vars.model_name }} --output=json
exit-status: 0
stdout:
have-patterns:
- 'true'
gjson:
items.#.status.conditions.#.status|@flatten:
not:
- "False"
stderr: ""
loki-pod-container-healthy:
exec: kubectl get pod {{ .Vars.apps.loki.name }}-0 -n {{ .Vars.model_name }} -o json | jq -r '[.status.containerStatuses[] | .ready == true] | all'

pod-container-healthy:
exec: kubectl get pods -n {{ .Vars.model_name }} --output=json
exit-status: 0
stdout:
have-patterns:
- 'true'
gjson:
items.#.status.containerStatuses.#.ready:
not:
- "false"
stderr: ""
{{ end }}
21 changes: 21 additions & 0 deletions goss/goss_model_checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Deployment relation checks
command:
{{ if .Vars.enable_model_tests }}
validate-model-configuration:
exec: juju status --format=json -m {{ .Vars.model_name }}
exit-status: 0
stdout:
gjson:
applications:
and:
- {have-key: {{ .Vars.apps.k8s.alertmanager.name }}}
- {have-key: {{ .Vars.apps.k8s.catalogue.name }}}
- {have-key: {{ .Vars.apps.k8s.grafana.name }}}
- {have-key: {{ .Vars.apps.k8s.loki.name }}}
- {have-key: {{ .Vars.apps.k8s.prometheus.name }}}
- {have-key: {{ .Vars.apps.k8s.traefik.name }}}
applications.{{ .Vars.apps.k8s.prometheus.name }}.relations:
and:
- {have-key: {{ .Vars.apps.k8s.alertmanager.name }}}
stderr: ""
{{ end }}
4 changes: 2 additions & 2 deletions goss/goss_network_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
command:
{{ if .Vars.enable_network_tests }}
loki-reachable-via-ingress-url:
exec: curl -s $(juju ssh -m {{ .Vars.model_name }} --container loki {{ .Vars.apps.loki.name }}/0 cat /etc/loki/loki-local-config.yaml | yq -r '.ruler.external_url')/ready
exec: curl -s $(juju ssh -m {{ .Vars.model_name }} --container loki {{ .Vars.apps.k8s.loki.name }}/0 cat /etc/loki/loki-local-config.yaml | yq -r '.ruler.external_url')/ready
exit-status: 0
stdout:
have-patterns:
- ready
stderr: ""
loki-can-reach-altermanager-internally:
exec: bash goss/scripts/test-internal-routing.sh {{ .Vars.model_name }} {{ .Vars.apps.loki.name }} {{ .Vars.apps.alertmanager.name }}
exec: bash goss/scripts/test-internal-routing.sh {{ .Vars.model_name }} {{ .Vars.apps.k8s.loki.name }} {{ .Vars.apps.k8s.alertmanager.name }}
exit-status: 0
stdout:
have-patterns:
Expand Down
5 changes: 2 additions & 3 deletions goss/goss_pebble_checks.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Charm Pebble health checks
command:
{{ if .Vars.enable_self_tests }}
{{ if .Vars.enable_pebble_tests }}
# $root is required to access the root context of the current template,
# which refers to the entire data structure being passed into the template.
# This provides access to .Vars and .Env in loops like the one below.
{{- $root := . -}}

{{range $app := .Vars.apps}}
{{range $app := .Vars.apps.k8s}}
pebble-{{$app.name}}:
exec: juju ssh -m {{ $root.Vars.model_name }} {{$app.name}}/0 /charm/bin/pebble health
exit-status: 0
Expand Down
11 changes: 0 additions & 11 deletions goss/goss_relation_checks.yaml

This file was deleted.

39 changes: 23 additions & 16 deletions goss/vars.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
model_name: cos-model

apps:
alertmanager:
name: alertmanager
catalogue:
name: catalogue
grafana:
name: grafana
loki:
name: loki
prometheus:
name: prometheus
traefik:
name: traefik
k8s:
alertmanager:
name: alertmanager
catalogue:
name: catalogue
grafana:
name: grafana
loki:
name: loki
prometheus:
name: prometheus
traefik:
name: traefik
machine:
# TODO: File an issue that keys cannot have '-' in the name, replace with _.
# E.g. app.machine.prometheus_openstack_exporter is valid but app.machine.prometheus-openstack-exporter is not
prometheus_openstack_exporter:
name: prometheus-openstack-exporter

enable_self_tests: true
enable_relation_tests: true
enable_post_relation_tests: true
enable_network_tests: true
enable_az_tests: true
enable_k8s_tests: true
enable_model_tests: true
enable_network_tests: true
enable_pebble_tests: true
enable_post_relation_tests: true

0 comments on commit 6dfba14

Please sign in to comment.