From 6dfba140fdcf3e1129028e703260960406f9b404 Mon Sep 17 00:00:00 2001 From: Michael Thamm Date: Wed, 25 Sep 2024 10:36:47 -0400 Subject: [PATCH] Cleanup: gjson checks --- goss/goss.yaml | 5 +++-- goss/goss_az_checks.yaml | 14 ++++++++++++ goss/goss_k8s_checks.yaml | 21 +++++++++++------- goss/goss_model_checks.yaml | 21 ++++++++++++++++++ goss/goss_network_checks.yaml | 4 ++-- goss/goss_pebble_checks.yaml | 5 ++--- goss/goss_relation_checks.yaml | 11 ---------- goss/vars.yaml | 39 ++++++++++++++++++++-------------- 8 files changed, 78 insertions(+), 42 deletions(-) create mode 100644 goss/goss_az_checks.yaml create mode 100644 goss/goss_model_checks.yaml delete mode 100644 goss/goss_relation_checks.yaml diff --git a/goss/goss.yaml b/goss/goss.yaml index e168b38..14b676f 100644 --- a/goss/goss.yaml +++ b/goss/goss.yaml @@ -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: diff --git a/goss/goss_az_checks.yaml b/goss/goss_az_checks.yaml new file mode 100644 index 0000000..ac6efa1 --- /dev/null +++ b/goss/goss_az_checks.yaml @@ -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 }} \ No newline at end of file diff --git a/goss/goss_k8s_checks.yaml b/goss/goss_k8s_checks.yaml index 2102914..970f9f2 100644 --- a/goss/goss_k8s_checks.yaml +++ b/goss/goss_k8s_checks.yaml @@ -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 }} diff --git a/goss/goss_model_checks.yaml b/goss/goss_model_checks.yaml new file mode 100644 index 0000000..9e933eb --- /dev/null +++ b/goss/goss_model_checks.yaml @@ -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 }} diff --git a/goss/goss_network_checks.yaml b/goss/goss_network_checks.yaml index dc35cc2..dae14fd 100644 --- a/goss/goss_network_checks.yaml +++ b/goss/goss_network_checks.yaml @@ -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: diff --git a/goss/goss_pebble_checks.yaml b/goss/goss_pebble_checks.yaml index d33e269..5b46ef6 100644 --- a/goss/goss_pebble_checks.yaml +++ b/goss/goss_pebble_checks.yaml @@ -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 diff --git a/goss/goss_relation_checks.yaml b/goss/goss_relation_checks.yaml deleted file mode 100644 index d69f360..0000000 --- a/goss/goss_relation_checks.yaml +++ /dev/null @@ -1,11 +0,0 @@ -# Deployment relation checks -command: - {{ if .Vars.enable_relation_tests }} - relation-grafana-loki: - exec: juju status --format json -m {{ .Vars.model_name }} | jq -r '.applications.{{ .Vars.apps.loki.name }}.relations["grafana-source"][]["related-application"]' - exit-status: 0 - stdout: - have-patterns: - - '{{ .Vars.apps.grafana.name }}' - stderr: "" - {{ end }} diff --git a/goss/vars.yaml b/goss/vars.yaml index 7ac12f8..b555371 100644 --- a/goss/vars.yaml +++ b/goss/vars.yaml @@ -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