fix: cost-audit.sh — Artifact Registry sizeBytes float-safe via awk

This commit is contained in:
chrischristiansen-glitch 2026-05-23 07:57:49 +02:00
parent 36195a2135
commit 79bb7c8625

View File

@ -46,7 +46,6 @@ if [[ -z "$CR" ]]; then
printf " ${OK} No services deployed\n" printf " ${OK} No services deployed\n"
else else
while IFS=$'\t' read -r NAME URL; do while IFS=$'\t' read -r NAME URL; do
# Check min-instances annotation
MIN=$(gcloud run services describe "$NAME" \ MIN=$(gcloud run services describe "$NAME" \
--project="${PROJECT_ID}" --region="${REGION}" \ --project="${PROJECT_ID}" --region="${REGION}" \
--format="value(spec.template.metadata.annotations.'autoscaling.knative.dev/minScale')" \ --format="value(spec.template.metadata.annotations.'autoscaling.knative.dev/minScale')" \
@ -176,8 +175,9 @@ if [[ -z "$REPOS" ]]; then
printf " ${OK} No Artifact Registry repos\n" printf " ${OK} No Artifact Registry repos\n"
else else
while IFS=$'\t' read -r NAME FMT SIZE; do while IFS=$'\t' read -r NAME FMT SIZE; do
SIZE_MB=$(( ${SIZE:-0} / 1048576 )) # sizeBytes kan være float (f.eks. 345900.5) — bruk awk for sikker MB-konvertering
printf " ${OK} %-28s fmt:%-8s size:${SIZE_MB}MB\n" "$NAME" "$FMT" SIZE_MB=$(awk -v s="${SIZE:-0}" 'BEGIN { printf "%.1f", s / 1048576 }')
printf " ${OK} %-28s fmt:%-8s size:${SIZE_MB} MB\n" "$NAME" "$FMT"
done <<< "$REPOS" done <<< "$REPOS"
fi fi
echo "" echo ""