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 authored and pmalek-sumo committed Mar 24, 2021
1 parent 7fc9a45 commit 1ab8691
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 36 deletions.
23 changes: 19 additions & 4 deletions deploy/helm/sumologic/conf/setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions tests/terraform/static/all_fields.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions tests/terraform/static/collector_fields.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions tests/terraform/static/conditional_sources.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions tests/terraform/static/custom.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions tests/terraform/static/default.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions tests/terraform/static/disable_default_metrics.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions tests/terraform/static/strip_extrapolation.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions tests/terraform/static/traces.output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1ab8691

Please sign in to comment.