Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application-level Goss checks #349

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions goss/fetch-subdir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

uri="$1"
repo="$2"
branch="$3"
dir="$4"

git clone -b $branch -n --depth=1 --filter=tree:0 "$uri/$repo.git"
cd $repo
git sparse-checkout set --no-cone $dir
git checkout
cd ..
26 changes: 26 additions & 0 deletions goss/goss-grafana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Import other goss.yaml files
command:
grafana-application-configuration:
exec: juju status -m cos-model grafana --format=json
exit-status: 0
stdout:
gjson:
applications.grafana.scale: 1
applications.grafana.application-status.current: active
applications.grafana.units.*.juju-status.current: idle
applications.grafana.units.*.workload-status.current: active
applications.grafana.relations.@keys:
- catalogue
- grafana
- grafana-dashboard
- grafana-source
- ingress
- metrics-endpoint
- replicas
stderr: ""

grafana-related-dashboards:
exec: bash {{ .Vars.goss_dir }}/scripts/compare-dashboard-uids.sh cos-model grafana alertmanager
exit-status: 0
stdout: "Match found."
stderr: ""
2 changes: 2 additions & 0 deletions goss/goss.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gossfile:
goss-*.yaml: {}
29 changes: 29 additions & 0 deletions goss/scripts/compare-dashboard-uids.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Collect the UID from the charm dashboard and check if it is a subset of Grafana dashboard UIDs

model_name="$1"
grafana_app="$2"
other_app="$3"
grafana_dashboard_dir="/etc/${grafana_app}/provisioning/dashboards/"
other_app_dashboard_dir="agents/unit-${other_app}-0/charm/src/grafana_dashboards/"
target_uid=$(juju ssh ${other_app}/0 "cat ${other_app_dashboard_dir}/${other_app}*.json.tmpl" | jq -r '.uid')

# Get the list of JSON files in the Grafana dashboard directory inside the workload container
files=$(juju ssh --container grafana grafana/0 "find $grafana_dashboard_dir -type f -name '*.json'")
match_found=false

# Iterate over each dashboard file
for file_path in ${files}; do
uid=$(juju ssh --container grafana grafana/0 "cat ${file_path}" | jq -r '.uid')
if [ "$uid" == "$target_uid" ]; then
match_found=true
break # Exit the loop early since a match was found
fi
done

if [ "$match_found" = true ]; then
echo -n "Match found."
else
echo -n "The ${other_app} dashboard UID is not a subset of the Grafana dashboard UIDs."
fi
Loading