Skip to content

Commit

Permalink
ci: correct e2e namespace issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mallardduck committed Oct 7, 2024
1 parent 8149cf2 commit 1944bbb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ cleanup() {
}

if [[ -z "${RANCHER_TOKEN}" ]]; then
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-m-alertmanager:9093/proxy/api/v2/alerts | yq -P - > ${tmp_alerts_yaml}
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-m-alertmanager:9093/proxy/api/v2/alerts | yq -P - > ${tmp_alerts_yaml}
else
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-m-alertmanager:9093/proxy/api/v2/alerts -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq -P - > ${tmp_alerts_yaml}
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-m-alertmanager:9093/proxy/api/v2/alerts -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq -P - > ${tmp_alerts_yaml}
fi

if [[ $(yq '. | length' "${tmp_alerts_yaml}") != "1" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ cleanup() {
}

if [[ -z "${RANCHER_TOKEN}" ]]; then
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/search | yq -P - > ${tmp_dashboards_yaml}
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/search | yq -P - > ${tmp_dashboards_yaml}
else
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/search -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq -P - > ${tmp_dashboards_yaml}
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/search -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq -P - > ${tmp_dashboards_yaml}
fi

dashboards=$(yq '.[].uri' ${tmp_dashboards_yaml})
Expand All @@ -27,9 +27,9 @@ dashboards=$(yq '.[].uri' ${tmp_dashboards_yaml})
for dashboard in ${dashboards[@]}; do
dashboard_uid=$(yq ".[] | select(.uri==\"${dashboard}\") | .uid" ${tmp_dashboards_yaml});
if [[ -z "${RANCHER_TOKEN}" ]]; then
dashboard_json=$(curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/dashboards/uid/${dashboard_uid} | yq '.dashboard' -)
dashboard_json=$(curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/dashboards/uid/${dashboard_uid} | yq '.dashboard' -)
else
dashboard_json=$(curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/dashboards/uid/${dashboard_uid} -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq '.dashboard' -)
dashboard_json=$(curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/dashboards/uid/${dashboard_uid} -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq '.dashboard' -)
fi
# TODO: Fix this to actually recursively utilize Grafana dashboard's yaml structure
# Today, it just looks for .expr entries in .panels[], .panels[].panels[], and .rows[].panels[], which should cover all dashboards in Monitoring today
Expand Down Expand Up @@ -147,9 +147,9 @@ for query_key in $(yq "keys" ${tmp_queries_yaml} | cut -d' ' -f2-); do
EOF
)"
if [[ -z "${RANCHER_TOKEN}" ]]; then
query_response=$(curl -s "${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/ds/query" -H 'content-type: application/json' --data-raw "${query_body}")
query_response=$(curl -s "${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/ds/query" -H 'content-type: application/json' --data-raw "${query_body}")
else
query_response=$(curl -s "${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/ds/query" -H 'content-type: application/json' --data-raw "${query_body}" -k -H "Authorization: Bearer ${RANCHER_TOKEN}")
query_response=$(curl -s "${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/ds/query" -H 'content-type: application/json' --data-raw "${query_body}" -k -H "Authorization: Bearer ${RANCHER_TOKEN}")
fi
if [[ "$(echo ${query_response} | yq '.message == "bad request data"')" == "true" ]]; then
# echo "QUERY: ${query}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ cleanup() {
}

if [[ -z "${RANCHER_TOKEN}" ]]; then
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/search | yq -P - > ${tmp_dashboards_yaml}
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/search | yq -P - > ${tmp_dashboards_yaml}
else
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/search -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq -P - > ${tmp_dashboards_yaml}
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/search -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq -P - > ${tmp_dashboards_yaml}
fi

expected_dashboards=(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ cleanup() {
}

if [[ -z "${RANCHER_TOKEN}" ]]; then
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/datasources | yq -P - > ${tmp_datasources_yaml}
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/datasources | yq -P - > ${tmp_datasources_yaml}
else
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/datasources -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq -P - > ${tmp_datasources_yaml}
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-monitoring-grafana:80/proxy/api/datasources -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq -P - > ${tmp_datasources_yaml}
fi

if [[ $(yq '. | length' ${tmp_datasources_yaml}) != "1" ]]; then
Expand All @@ -25,8 +25,8 @@ if [[ $(yq '. | length' ${tmp_datasources_yaml}) != "1" ]]; then
exit 1
fi

if [[ $(yq '.[0].url' ${tmp_datasources_yaml}) != "http://cattle-project-p-example-m-prometheus.cattle-project-p-example-monitoring:9090/" ]]; then
echo "ERROR: Expected the only datasource to be configured to point to Project Prometheus at Kubernetes DNS http://cattle-project-p-example-m-prometheus.cattle-project-p-example-monitoring:9090/"
if [[ $(yq '.[0].url' ${tmp_datasources_yaml}) != "http://cattle-project-p-example-m-prometheus.cattle-project-p-example:9090/" ]]; then
echo "ERROR: Expected the only datasource to be configured to point to Project Prometheus at Kubernetes DNS http://cattle-project-p-example-m-prometheus.cattle-project-p-example:9090/"
cat ${tmp_datasources_yaml}
exit 1
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ cleanup() {
}

if [[ -z "${RANCHER_TOKEN}" ]]; then
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-m-prometheus:9090/proxy/api/v1/alerts | yq -P - > ${tmp_rules_yaml}
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-m-prometheus:9090/proxy/api/v1/alerts | yq -P - > ${tmp_rules_yaml}
else
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example-monitoring/services/http:cattle-project-p-example-m-prometheus:9090/proxy/api/v1/alerts -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq -P - > ${tmp_rules_yaml}
curl -s ${API_SERVER_URL}/api/v1/namespaces/cattle-project-p-example/services/http:cattle-project-p-example-m-prometheus:9090/proxy/api/v1/alerts -k -H "Authorization: Bearer ${RANCHER_TOKEN}" | yq -P - > ${tmp_rules_yaml}
fi

yq '.data.alerts' ${tmp_rules_yaml} > ${tmp_alert_rules_yaml}
Expand Down

0 comments on commit 1944bbb

Please sign in to comment.