From 1ab8691f0831a04898d4b9ae59fa671e777060e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Wed, 24 Mar 2021 16:08:22 +0100 Subject: [PATCH] Check API errors when getting fields quota in setup job --- deploy/helm/sumologic/conf/setup/setup.sh | 23 +++++++++++++++---- tests/terraform/static/all_fields.output.yaml | 23 +++++++++++++++---- .../static/collector_fields.output.yaml | 23 +++++++++++++++---- .../static/conditional_sources.output.yaml | 23 +++++++++++++++---- tests/terraform/static/custom.output.yaml | 23 +++++++++++++++---- tests/terraform/static/default.output.yaml | 23 +++++++++++++++---- .../disable_default_metrics.output.yaml | 23 +++++++++++++++---- .../static/strip_extrapolation.output.yaml | 23 +++++++++++++++---- tests/terraform/static/traces.output.yaml | 23 +++++++++++++++---- 9 files changed, 171 insertions(+), 36 deletions(-) diff --git a/deploy/helm/sumologic/conf/setup/setup.sh b/deploy/helm/sumologic/conf/setup/setup.sh index de9d61e56c..17e193edcb 100755 --- a/deploy/helm/sumologic/conf/setup/setup.sh +++ b/deploy/helm/sumologic/conf/setup/setup.sh @@ -22,18 +22,33 @@ export HTTP_PROXY=${HTTP_PROXY:=""} export HTTPS_PROXY=${HTTPS_PROXY:=""} export NO_PROXY=${NO_PROXY:=""} -function remaining_fields() { - local RESPONSE="$(curl -XGET -s \ +function get_remaining_fields() { + local RESPONSE + readonly RESPONSE="$(curl -XGET -s \ -u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \ "${SUMOLOGIC_BASE_URL}"v1/fields/quota)" - echo "${RESPONSE}" | jq '.remaining' + echo "${RESPONSE}" } # Check if we'd have at least 10 fields remaining after additional fields # would be created for the collection function should_create_fields() { - local REMAINING=$(remaining_fields) + local RESPONSE + readonly RESPONSE=$(get_remaining_fields) + + if ! jq -e <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + if ! jq -e '.remaining' <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + local REMAINING + readonly REMAINING=$(jq -e '.remaining' <<< "${RESPONSE}") if [[ $(( REMAINING - {{ len .Values.sumologic.logs.fields }} )) -ge 10 ]] ; then return 0 else diff --git a/tests/terraform/static/all_fields.output.yaml b/tests/terraform/static/all_fields.output.yaml index 6dda103bc3..c3f7b5947d 100644 --- a/tests/terraform/static/all_fields.output.yaml +++ b/tests/terraform/static/all_fields.output.yaml @@ -306,18 +306,33 @@ data: export HTTPS_PROXY=${HTTPS_PROXY:=""} export NO_PROXY=${NO_PROXY:=""} - function remaining_fields() { - local RESPONSE="$(curl -XGET -s \ + function get_remaining_fields() { + local RESPONSE + readonly RESPONSE="$(curl -XGET -s \ -u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \ "${SUMOLOGIC_BASE_URL}"v1/fields/quota)" - echo "${RESPONSE}" | jq '.remaining' + echo "${RESPONSE}" } # Check if we'd have at least 10 fields remaining after additional fields # would be created for the collection function should_create_fields() { - local REMAINING=$(remaining_fields) + local RESPONSE + readonly RESPONSE=$(get_remaining_fields) + + if ! jq -e <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + if ! jq -e '.remaining' <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + local REMAINING + readonly REMAINING=$(jq -e '.remaining' <<< "${RESPONSE}") if [[ $(( REMAINING - 8 )) -ge 10 ]] ; then return 0 else diff --git a/tests/terraform/static/collector_fields.output.yaml b/tests/terraform/static/collector_fields.output.yaml index 754eecbe77..73e961fb9f 100644 --- a/tests/terraform/static/collector_fields.output.yaml +++ b/tests/terraform/static/collector_fields.output.yaml @@ -261,18 +261,33 @@ data: export HTTPS_PROXY=${HTTPS_PROXY:=""} export NO_PROXY=${NO_PROXY:=""} - function remaining_fields() { - local RESPONSE="$(curl -XGET -s \ + function get_remaining_fields() { + local RESPONSE + readonly RESPONSE="$(curl -XGET -s \ -u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \ "${SUMOLOGIC_BASE_URL}"v1/fields/quota)" - echo "${RESPONSE}" | jq '.remaining' + echo "${RESPONSE}" } # Check if we'd have at least 10 fields remaining after additional fields # would be created for the collection function should_create_fields() { - local REMAINING=$(remaining_fields) + local RESPONSE + readonly RESPONSE=$(get_remaining_fields) + + if ! jq -e <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + if ! jq -e '.remaining' <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + local REMAINING + readonly REMAINING=$(jq -e '.remaining' <<< "${RESPONSE}") if [[ $(( REMAINING - 8 )) -ge 10 ]] ; then return 0 else diff --git a/tests/terraform/static/conditional_sources.output.yaml b/tests/terraform/static/conditional_sources.output.yaml index 4b7cffc90b..30ad58ce31 100644 --- a/tests/terraform/static/conditional_sources.output.yaml +++ b/tests/terraform/static/conditional_sources.output.yaml @@ -188,18 +188,33 @@ data: export HTTPS_PROXY=${HTTPS_PROXY:=""} export NO_PROXY=${NO_PROXY:=""} - function remaining_fields() { - local RESPONSE="$(curl -XGET -s \ + function get_remaining_fields() { + local RESPONSE + readonly RESPONSE="$(curl -XGET -s \ -u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \ "${SUMOLOGIC_BASE_URL}"v1/fields/quota)" - echo "${RESPONSE}" | jq '.remaining' + echo "${RESPONSE}" } # Check if we'd have at least 10 fields remaining after additional fields # would be created for the collection function should_create_fields() { - local REMAINING=$(remaining_fields) + local RESPONSE + readonly RESPONSE=$(get_remaining_fields) + + if ! jq -e <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + if ! jq -e '.remaining' <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + local REMAINING + readonly REMAINING=$(jq -e '.remaining' <<< "${RESPONSE}") if [[ $(( REMAINING - 8 )) -ge 10 ]] ; then return 0 else diff --git a/tests/terraform/static/custom.output.yaml b/tests/terraform/static/custom.output.yaml index 4b7cffc90b..30ad58ce31 100644 --- a/tests/terraform/static/custom.output.yaml +++ b/tests/terraform/static/custom.output.yaml @@ -188,18 +188,33 @@ data: export HTTPS_PROXY=${HTTPS_PROXY:=""} export NO_PROXY=${NO_PROXY:=""} - function remaining_fields() { - local RESPONSE="$(curl -XGET -s \ + function get_remaining_fields() { + local RESPONSE + readonly RESPONSE="$(curl -XGET -s \ -u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \ "${SUMOLOGIC_BASE_URL}"v1/fields/quota)" - echo "${RESPONSE}" | jq '.remaining' + echo "${RESPONSE}" } # Check if we'd have at least 10 fields remaining after additional fields # would be created for the collection function should_create_fields() { - local REMAINING=$(remaining_fields) + local RESPONSE + readonly RESPONSE=$(get_remaining_fields) + + if ! jq -e <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + if ! jq -e '.remaining' <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + local REMAINING + readonly REMAINING=$(jq -e '.remaining' <<< "${RESPONSE}") if [[ $(( REMAINING - 8 )) -ge 10 ]] ; then return 0 else diff --git a/tests/terraform/static/default.output.yaml b/tests/terraform/static/default.output.yaml index b57351cb6c..dc28682a4d 100644 --- a/tests/terraform/static/default.output.yaml +++ b/tests/terraform/static/default.output.yaml @@ -259,18 +259,33 @@ data: export HTTPS_PROXY=${HTTPS_PROXY:=""} export NO_PROXY=${NO_PROXY:=""} - function remaining_fields() { - local RESPONSE="$(curl -XGET -s \ + function get_remaining_fields() { + local RESPONSE + readonly RESPONSE="$(curl -XGET -s \ -u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \ "${SUMOLOGIC_BASE_URL}"v1/fields/quota)" - echo "${RESPONSE}" | jq '.remaining' + echo "${RESPONSE}" } # Check if we'd have at least 10 fields remaining after additional fields # would be created for the collection function should_create_fields() { - local REMAINING=$(remaining_fields) + local RESPONSE + readonly RESPONSE=$(get_remaining_fields) + + if ! jq -e <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + if ! jq -e '.remaining' <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + local REMAINING + readonly REMAINING=$(jq -e '.remaining' <<< "${RESPONSE}") if [[ $(( REMAINING - 8 )) -ge 10 ]] ; then return 0 else diff --git a/tests/terraform/static/disable_default_metrics.output.yaml b/tests/terraform/static/disable_default_metrics.output.yaml index 133495698d..0d2657467d 100644 --- a/tests/terraform/static/disable_default_metrics.output.yaml +++ b/tests/terraform/static/disable_default_metrics.output.yaml @@ -252,18 +252,33 @@ data: export HTTPS_PROXY=${HTTPS_PROXY:=""} export NO_PROXY=${NO_PROXY:=""} - function remaining_fields() { - local RESPONSE="$(curl -XGET -s \ + function get_remaining_fields() { + local RESPONSE + readonly RESPONSE="$(curl -XGET -s \ -u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \ "${SUMOLOGIC_BASE_URL}"v1/fields/quota)" - echo "${RESPONSE}" | jq '.remaining' + echo "${RESPONSE}" } # Check if we'd have at least 10 fields remaining after additional fields # would be created for the collection function should_create_fields() { - local REMAINING=$(remaining_fields) + local RESPONSE + readonly RESPONSE=$(get_remaining_fields) + + if ! jq -e <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + if ! jq -e '.remaining' <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + local REMAINING + readonly REMAINING=$(jq -e '.remaining' <<< "${RESPONSE}") if [[ $(( REMAINING - 8 )) -ge 10 ]] ; then return 0 else diff --git a/tests/terraform/static/strip_extrapolation.output.yaml b/tests/terraform/static/strip_extrapolation.output.yaml index a729880a0c..19302316a1 100644 --- a/tests/terraform/static/strip_extrapolation.output.yaml +++ b/tests/terraform/static/strip_extrapolation.output.yaml @@ -260,18 +260,33 @@ data: export HTTPS_PROXY=${HTTPS_PROXY:=""} export NO_PROXY=${NO_PROXY:=""} - function remaining_fields() { - local RESPONSE="$(curl -XGET -s \ + function get_remaining_fields() { + local RESPONSE + readonly RESPONSE="$(curl -XGET -s \ -u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \ "${SUMOLOGIC_BASE_URL}"v1/fields/quota)" - echo "${RESPONSE}" | jq '.remaining' + echo "${RESPONSE}" } # Check if we'd have at least 10 fields remaining after additional fields # would be created for the collection function should_create_fields() { - local REMAINING=$(remaining_fields) + local RESPONSE + readonly RESPONSE=$(get_remaining_fields) + + if ! jq -e <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + if ! jq -e '.remaining' <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + local REMAINING + readonly REMAINING=$(jq -e '.remaining' <<< "${RESPONSE}") if [[ $(( REMAINING - 8 )) -ge 10 ]] ; then return 0 else diff --git a/tests/terraform/static/traces.output.yaml b/tests/terraform/static/traces.output.yaml index c961beaafc..92fcc5ee06 100644 --- a/tests/terraform/static/traces.output.yaml +++ b/tests/terraform/static/traces.output.yaml @@ -196,18 +196,33 @@ data: export HTTPS_PROXY=${HTTPS_PROXY:=""} export NO_PROXY=${NO_PROXY:=""} - function remaining_fields() { - local RESPONSE="$(curl -XGET -s \ + function get_remaining_fields() { + local RESPONSE + readonly RESPONSE="$(curl -XGET -s \ -u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \ "${SUMOLOGIC_BASE_URL}"v1/fields/quota)" - echo "${RESPONSE}" | jq '.remaining' + echo "${RESPONSE}" } # Check if we'd have at least 10 fields remaining after additional fields # would be created for the collection function should_create_fields() { - local REMAINING=$(remaining_fields) + local RESPONSE + readonly RESPONSE=$(get_remaining_fields) + + if ! jq -e <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + if ! jq -e '.remaining' <<< "${RESPONSE}" ; then + printf "Failed requesting fields API:\n%s\n" "${RESPONSE}" + return 1 + fi + + local REMAINING + readonly REMAINING=$(jq -e '.remaining' <<< "${RESPONSE}") if [[ $(( REMAINING - 8 )) -ge 10 ]] ; then return 0 else