Skip to content
Merged
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
18 changes: 17 additions & 1 deletion scripts/read-cilium-api-limiter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ inconclusive() { printf 'INCONCLUSIVE: %s\n' "$1"; exit 3; }
# Bound JSON responses and requests. Neither failed kubectl output nor parser diagnostics are public.
read_json() {
local destination="$1"
local json_shape
local -a read_status
shift
read_failure=COMMAND_FAILED
Expand Down Expand Up @@ -52,10 +53,25 @@ read_json() {
fi
return 1
fi
if ! jq -e -s 'length==1 and .[0]!=null' "${destination}" >/dev/null 2>&1; then
# Slurping distinguishes valid JSON null and an empty stream from parse errors.
# None is a measurement; only the fixed classification leaves the private file.
if ! json_shape="$(jq -r -s '
if length==0 then "EMPTY_OUTPUT"
elif length>1 then "MULTIPLE_JSON_VALUES"
elif .[0]==null then "JSON_NULL"
else "OK" end
' "${destination}" 2>/dev/null)"; then
read_failure=INVALID_JSON
return 1
fi
case "${json_shape}" in
OK) ;;
EMPTY_OUTPUT | MULTIPLE_JSON_VALUES | JSON_NULL)
read_failure="${json_shape}"
return 1
;;
*) read_failure=INVALID_JSON; return 1 ;;
esac
}
roster() {
local prefix="$1"
Expand Down
19 changes: 19 additions & 0 deletions scripts/tests/test-read-cilium-api-limiter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ require_inconclusive
[[ "${output}" == 'INCONCLUSIVE: an agent metric read failed (INVALID_JSON).' ]] || {
printf 'FAIL: malformed JSON was not classified: %s\n' "${output}" >&2; exit 1;
}
# Successful CLI exits can still carry no measurement. Keep those distinct from
# malformed JSON, but refuse all of them before publishing any samples.
while IFS='|' read -r expected response; do
reset_fixture
printf '%b' "${response}" >"${fixture}/metrics.json"
require_inconclusive
[[ "${output}" == "INCONCLUSIVE: an agent metric read failed (${expected})." ]] || {
printf 'FAIL: expected %s response classification: %s\n' "${expected}" "${output}" >&2; exit 1;
}
done <<'RESPONSES'
EMPTY_OUTPUT|
EMPTY_OUTPUT|\n \t\n
JSON_NULL|null
JSON_NULL| \n null \t\n
MULTIPLE_JSON_VALUES|[]\n[]
MULTIPLE_JSON_VALUES|null\n[]
MULTIPLE_JSON_VALUES|[]\nnull
INVALID_JSON|[]\nPRIVATE_MALFORMED
RESPONSES
while IFS='|' read -r expected exit_code message; do
reset_fixture
printf 'PRIVATE_ERROR https://198.51.100.9:6443 %s\n' "${message}" >"${fixture}/stderr"
Expand Down
Loading