Skip to content

Commit

Permalink
feat: sumo dashboards installation as a part of the setup job (#2268)
Browse files Browse the repository at this point in the history
* feat: k8s dashboards installation - chart values

* feat: k8s dashboards installation - scripts

* feat: k8s dashboards installation - tests

* feat: k8s dashboards installation - changelog

* feat: k8s dashboards installation - notes

* feat: k8s dashboards installation - disabled dashboards test

* feat: k8s dashboards - remove unused variable

* feat: k8s dashboards - install the dashboards inside "Sumo Logic Integrations"

* feat: k8s dashboards - shellcheck fixes

* feat: k8s dashboards - shellcheck fixes (tests adjustment)

* feat: k8s dashboards - include dashboards.sh in shellcheck.sh

* feat: shellcheck - more info in logs

* feat: k8s dashboards - adjust tests after merge
  • Loading branch information
starzu-sumo committed May 6, 2022
1 parent 41181bd commit 3829d57
Show file tree
Hide file tree
Showing 21 changed files with 2,752 additions and 371 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- feat(fluentd): expose extra configuration for fluentd output plugin [#2244][#2244]
- feat(monitors): the Sumo Logic monitors installation as part of the setup job [#2250][#2250], [#2274][#2274]
- feat(dashboards): the Sumo Logic dashboards installation as part of the setup job [#2268][#2268]

### Changed

Expand All @@ -35,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2246]: https://github.com/SumoLogic/sumologic-kubernetes-collection/pull/2246
[#2250]: https://github.com/SumoLogic/sumologic-kubernetes-collection/pull/2250
[#2251]: https://github.com/SumoLogic/sumologic-kubernetes-collection/pull/2251
[#2268]: https://github.com/SumoLogic/sumologic-kubernetes-collection/pull/2268
[#2272]: https://github.com/SumoLogic/sumologic-kubernetes-collection/pull/2272
[#2274]: https://github.com/SumoLogic/sumologic-kubernetes-collection/pull/2274
[Unreleased]: https://github.com/SumoLogic/sumologic-kubernetes-collection/compare/v2.7.1...main
Expand Down
13 changes: 10 additions & 3 deletions ci/shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ find . ! -path '*deploy/helm/sumologic/conf/setup/setup.sh' ! -path '*deploy/hel
find . -path '*tests/helm/terraform/static/*.output.yaml' -type 'f' -print |
while read -r file; do
# Run tests in their own context
echo "Checking ${file} with shellcheck"
echo "Checking ${file} (setup.sh) with shellcheck"
yq r "${file}" "data[setup.sh]" | shellcheck --enable all --external-sources --exclude SC2155 -
done

find . -path '*tests/helm/terraform/static/*.output.yaml' -type 'f' -print |
while read -r file; do
# Run tests in their own context
echo "Checking ${file} with shellcheck"
echo "Checking ${file} (monitors.sh) with shellcheck"
yq r "${file}" "data[monitors.sh]" | shellcheck --enable all --external-sources --exclude SC2155 -
done

find . -path '*tests/helm/terraform/static/*.output.yaml' -type 'f' -print |
while read -r file; do
# Run tests in their own context
echo "Checking ${file} (dashboards.sh) with shellcheck"
yq r "${file}" "data[dashboards.sh]" | shellcheck --enable all --external-sources --exclude SC2155 -
done

find . -path '*tests/helm/terraform_custom/static/*.output.yaml' ! -path "./tests/helm/terraform_custom/static/empty.output.yaml" -type 'f' -print |
while read -r file; do
# Run tests in their own context
echo "Checking ${file} with shellcheck"
echo "Checking ${file} (custom_setup.sh) with shellcheck"
yq r "${file}" "data[custom_setup.sh]" | shellcheck --enable all --external-sources --exclude SC2155 -
done
707 changes: 354 additions & 353 deletions deploy/helm/sumologic/README.md

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions deploy/helm/sumologic/conf/setup/dashboards.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash

SUMOLOGIC_ACCESSID=${SUMOLOGIC_ACCESSID:=""}
readonly SUMOLOGIC_ACCESSID
SUMOLOGIC_ACCESSKEY=${SUMOLOGIC_ACCESSKEY:=""}
readonly SUMOLOGIC_ACCESSKEY
SUMOLOGIC_BASE_URL=${SUMOLOGIC_BASE_URL:=""}
readonly SUMOLOGIC_BASE_URL

INTEGRATIONS_FOLDER_NAME="Sumo Logic Integrations"
K8S_FOLDER_NAME="Kubernetes"
K8S_APP_UUID="162ceac7-166a-4475-8427-65e170ae9837"

function load_dashboards_folder_id() {
local ADMIN_FOLDER_JOB_ID
ADMIN_FOLDER_JOB_ID="$(curl -XGET -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
-H "isAdminMode: true" \
"${SUMOLOGIC_BASE_URL}"v2/content/folders/adminRecommended | jq '.id' | tr -d '"' )"
readonly ADMIN_FOLDER_JOB_ID

local ADMIN_FOLDER_JOB_STATUS
ADMIN_FOLDER_JOB_STATUS="InProgress"
while [ "${ADMIN_FOLDER_JOB_STATUS}" = "InProgress" ]; do
ADMIN_FOLDER_JOB_STATUS="$(curl -XGET -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
"${SUMOLOGIC_BASE_URL}"v2/content/folders/adminRecommended/"${ADMIN_FOLDER_JOB_ID}"/status | jq '.status' | tr -d '"' )"

sleep 1
done

if [ "${ADMIN_FOLDER_JOB_STATUS}" != "Success" ]; then
echo "Could not fetch data from the \"Admin Recommended\" content folder. The K8s Dashboards won't be installed."
echo "You can still install them manually:"
echo "https://help.sumologic.com/07Sumo-Logic-Apps/10Containers_and_Orchestration/Kubernetes/Install_the_Kubernetes_App%2C_Alerts%2C_and_view_the_Dashboards#install-the-app"
exit 1
fi

local ADMIN_FOLDER
ADMIN_FOLDER="$(curl -XGET -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
-H "isAdminMode: true" \
"${SUMOLOGIC_BASE_URL}"v2/content/folders/adminRecommended/"${ADMIN_FOLDER_JOB_ID}"/result )"
readonly ADMIN_FOLDER

local ADMIN_FOLDER_CHILDREN
ADMIN_FOLDER_CHILDREN="$( echo "${ADMIN_FOLDER}" | jq '.children[]')"
readonly ADMIN_FOLDER_CHILDREN

local ADMIN_FOLDER_ID
ADMIN_FOLDER_ID="$( echo "${ADMIN_FOLDER}" | jq '.id' | tr -d '"')"
readonly ADMIN_FOLDER_ID

INTEGRATIONS_FOLDER_ID="$( echo "${ADMIN_FOLDER_CHILDREN}" | \
jq -r "select(.name == \"${INTEGRATIONS_FOLDER_NAME}\") | .id" )"

if [[ -z "${INTEGRATIONS_FOLDER_ID}" ]]; then
INTEGRATIONS_FOLDER_ID="$(curl -XPOST -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
-H "isAdminMode: true" \
-H "Content-Type: application/json" \
-d "{\"name\":\"${INTEGRATIONS_FOLDER_NAME}\",\"parentId\":\"${ADMIN_FOLDER_ID}\",\"description\":\"Content provided by the Sumo Logic integrations.\"}" \
"${SUMOLOGIC_BASE_URL}"v2/content/folders | \
jq -r " .id" )"
fi

local INTEGRATIONS_FOLDER_CHILDREN
INTEGRATIONS_FOLDER_CHILDREN="$(curl -XGET -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
-H "isAdminMode: true" \
"${SUMOLOGIC_BASE_URL}"v2/content/folders/"${INTEGRATIONS_FOLDER_ID}" | \
jq '.children[]')"
readonly INTEGRATIONS_FOLDER_CHILDREN

K8S_FOLDER_ID="$( echo "${INTEGRATIONS_FOLDER_CHILDREN}" | \
jq -r "select(.name == \"${K8S_FOLDER_NAME}\") | .id" )"
}

load_dashboards_folder_id

if [[ -z "${K8S_FOLDER_ID}" ]]; then
APP_INSTALL_JOB_RESPONSE="$(curl -XPOST -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
-H "isAdminMode: true" \
-H "Content-Type: application/json" \
-d "{\"name\":\"${K8S_FOLDER_NAME}\",\"destinationFolderId\":\"${INTEGRATIONS_FOLDER_ID}\",\"description\":\"Kubernetes dashboards provided by Sumo Logic.\"}" \
"${SUMOLOGIC_BASE_URL}"v1/apps/"${K8S_APP_UUID}"/install )"
readonly APP_INSTALL_JOB_RESPONSE

APP_INSTALL_JOB_ID="$(echo "${APP_INSTALL_JOB_RESPONSE}" | jq '.id' | tr -d '"' )"
readonly APP_INSTALL_JOB_ID

APP_INSTALL_JOB_STATUS="InProgress"
while [ "${APP_INSTALL_JOB_STATUS}" = "InProgress" ]; do
APP_INSTALL_JOB_STATUS="$(curl -XGET -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
"${SUMOLOGIC_BASE_URL}"v1/apps/install/"${APP_INSTALL_JOB_ID}"/status | jq '.status' | tr -d '"' )"

sleep 1
done

if [ "${APP_INSTALL_JOB_STATUS}" != "Success" ]; then
ERROR_MSG="$(curl -XGET -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
"${SUMOLOGIC_BASE_URL}"v1/apps/install/"${APP_INSTALL_JOB_ID}"/status )"
echo "${ERROR_MSG}"

echo "Installation of the K8s Dashboards failed."
echo "You can still install them manually:"
echo "https://help.sumologic.com/07Sumo-Logic-Apps/10Containers_and_Orchestration/Kubernetes/Install_the_Kubernetes_App%2C_Alerts%2C_and_view_the_Dashboards#install-the-app"
exit 2
else
load_dashboards_folder_id

ORG_ID="$(curl -XGET -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
"${SUMOLOGIC_BASE_URL}"v1/account/contract | jq '.orgId' | tr -d '"' )"
readonly ORG_ID

PERMS_ERRORS=$( curl -XPUT -s \
-u "${SUMOLOGIC_ACCESSID}:${SUMOLOGIC_ACCESSKEY}" \
-H "isAdminMode: true" \
-H "Content-Type: application/json" \
-d "{\"contentPermissionAssignments\": [{\"permissionName\": \"View\",\"sourceType\": \"org\",\"sourceId\": \"${ORG_ID}\",\"contentId\": \"${K8S_FOLDER_ID}\"}],\"notifyRecipients\":false,\"notificationMessage\":\"\"}" \
"${SUMOLOGIC_BASE_URL}"v2/content/"${K8S_FOLDER_ID}"/permissions/add | jq '.errors' )
readonly PERMS_ERRORS

if [ "${PERMS_ERRORS}" != "null" ]; then
echo "Setting permissions for the installed content failed."
echo "${PERMS_ERRORS}"
fi

echo "Installation of the K8s Dashboards succeeded."
fi
else
echo "The K8s Dashboards have been already installed."
echo "You can (re)install them manually with:"
echo "https://help.sumologic.com/07Sumo-Logic-Apps/10Containers_and_Orchestration/Kubernetes/Install_the_Kubernetes_App%2C_Alerts%2C_and_view_the_Dashboards#install-the-app"
fi
2 changes: 1 addition & 1 deletion deploy/helm/sumologic/conf/setup/monitors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ if [[ -z "${MONITORS_FOLDER_ID}" ]]; then
{{- end }}
|| { echo "Error during applying Terraform monitors."; exit 1; }
else
echo "The monitors were already installed in ${MONITORS_FOLDER_NAME}."
echo "The monitors have been already installed in ${MONITORS_FOLDER_NAME}."
echo "You can (re)install them manually with:"
echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes"
fi
9 changes: 9 additions & 0 deletions deploy/helm/sumologic/conf/setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ echo "You can install them manually later with:"
echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes"
{{- end }}

# Setup Sumo Logic dashboards if enabled
{{- if .Values.sumologic.setup.dashboards.enabled }}
bash /etc/terraform/dashboards.sh
{{- else }}
echo "Installation of the Sumo Logic dashboards is disabled."
echo "You can install them manually later with:"
echo "https://help.sumologic.com/07Sumo-Logic-Apps/10Containers_and_Orchestration/Kubernetes/Install_the_Kubernetes_App%2C_Alerts%2C_and_view_the_Dashboards#install-the-app"
{{- end }}

# Cleanup env variables
export SUMOLOGIC_BASE_URL=
export SUMOLOGIC_ACCESSKEY=
Expand Down
12 changes: 9 additions & 3 deletions deploy/helm/sumologic/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ fails please refer to the following to create them manually:
https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/2b3ca63/deploy/docs/Installation_with_Helm.md#prerequisite

{{- if not (.Values.sumologic.setup.monitors.enabled) }}
echo "Installation of the Sumo Logic monitors is disabled."
echo "You can install them with:"
echo "https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes"
Installation of the Sumo Logic monitors is disabled.
You can install them with:
https://github.com/SumoLogic/terraform-sumologic-sumo-logic-monitor/tree/main/monitor_packages/kubernetes
{{- end }}

{{- if not (.Values.sumologic.setup.dashboards.enabled) }}
Installation of the Sumo Logic dashboards is disabled.
You can install them manually later with:
https://help.sumologic.com/07Sumo-Logic-Apps/10Containers_and_Orchestration/Kubernetes/Install_the_Kubernetes_App%2C_Alerts%2C_and_view_the_Dashboards#install-the-app
{{- end }}
4 changes: 4 additions & 0 deletions deploy/helm/sumologic/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ sumologic:
## A list of emails to send notifications from monitors
notificationEmails: []

dashboards:
## If enabled, a pre-install hook will install k8s dashboards in Sumo Logic
enabled: true

collector:
## Configuration of additional collector fields
## https://help.sumologic.com/Manage/Fields#http-source-fields
Expand Down

0 comments on commit 3829d57

Please sign in to comment.