Skip to content

Commit

Permalink
Check API errors when getting fields quota in setup job
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Mar 24, 2021
1 parent 7fc9a45 commit 19cba50
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 27 deletions.
21 changes: 18 additions & 3 deletions deploy/helm/sumologic/conf/setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,32 @@ export HTTPS_PROXY=${HTTPS_PROXY:=""}
export NO_PROXY=${NO_PROXY:=""}

function remaining_fields() {
local RESPONSE="$(curl -XGET -s \
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
Expand Down
21 changes: 18 additions & 3 deletions tests/terraform/static/all_fields.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,32 @@ data:
export NO_PROXY=${NO_PROXY:=""}
function remaining_fields() {
local RESPONSE="$(curl -XGET -s \
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
Expand Down
21 changes: 18 additions & 3 deletions tests/terraform/static/collector_fields.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,32 @@ data:
export NO_PROXY=${NO_PROXY:=""}
function remaining_fields() {
local RESPONSE="$(curl -XGET -s \
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
Expand Down
21 changes: 18 additions & 3 deletions tests/terraform/static/conditional_sources.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,32 @@ data:
export NO_PROXY=${NO_PROXY:=""}
function remaining_fields() {
local RESPONSE="$(curl -XGET -s \
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
Expand Down
21 changes: 18 additions & 3 deletions tests/terraform/static/custom.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,32 @@ data:
export NO_PROXY=${NO_PROXY:=""}
function remaining_fields() {
local RESPONSE="$(curl -XGET -s \
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
Expand Down
21 changes: 18 additions & 3 deletions tests/terraform/static/default.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,32 @@ data:
export NO_PROXY=${NO_PROXY:=""}
function remaining_fields() {
local RESPONSE="$(curl -XGET -s \
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
Expand Down
21 changes: 18 additions & 3 deletions tests/terraform/static/disable_default_metrics.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,32 @@ data:
export NO_PROXY=${NO_PROXY:=""}
function remaining_fields() {
local RESPONSE="$(curl -XGET -s \
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
Expand Down
21 changes: 18 additions & 3 deletions tests/terraform/static/strip_extrapolation.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,32 @@ data:
export NO_PROXY=${NO_PROXY:=""}
function remaining_fields() {
local RESPONSE="$(curl -XGET -s \
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
Expand Down
21 changes: 18 additions & 3 deletions tests/terraform/static/traces.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,32 @@ data:
export NO_PROXY=${NO_PROXY:=""}
function remaining_fields() {
local RESPONSE="$(curl -XGET -s \
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
Expand Down

0 comments on commit 19cba50

Please sign in to comment.