8000 chore: integrate Instatus API for module checks · coder/modules@33e4ba8 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 33e4ba8

Browse files
committed
chore: integrate Instatus API for module checks
- Improve monitoring by implementing Instatus API to update component status based on module check results. - Automate incident reports for module failures to enable efficient troubleshooting.
1 parent 90bfbfd commit 33e4ba8

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed

.github/scripts/check.sh

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,70 @@
11
#!/usr/bin/env bash
22
set -o pipefail
3-
REGISTRY_BASE_URL="${REGISTRY_BASE_URL:-https://registry.coder.com}"
43
set -u
54

6-
if [[ -n "${VERBOSE:-}" ]]; then
7-
set -x
8-
fi
5+
REGISTRY_BASE_URL="${REGISTRY_BASE_URL:-https://registry.coder.com}"
96

107
status=0
118
declare -a modules=()
129
declare -a failures=()
10+
11+
# Collect all module directories containing a main.tf file
1312
for path in $(find . -not -path '*/.*' -type f -name main.tf -maxdepth 2 | cut -d '/' -f 2 | sort -u); do
1413
modules+=("${path}")
1514
done
15+
1616
echo "Checking modules: ${modules[*]}"
17+
18+
# Function to update the component status on Instatus
19+
update_component_status() {
20+
local component_status=$1
21+
# see https://instatus.com/help/api/components
22+
(curl -X PUT "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/components/$INSTATUS_COMPONENT_ID" \
23+
-H "Authorization: Bearer $INSTATUS_API_KEY" \
24+
-H "Content-Type: application/json" \
25+
-d "{\"status\": \"$component_status\"}")
26+
}
27+
28+
# Function to create an incident
29+
create_incident() {
30+
local incident_name="Testing Instatus"
31+
local message="The following modules are experiencing issues:\n"
32+
for i in "${!failures[@]}"; do
33+
message+="$(($i + 1)). ${failures[$i]}\n"
34+
done
35+
36+
component_status="PARTIALOUTAGE"
37+
if (( ${#failures[@]} == ${#modules[@]} )); then
38+
component_status="MAJOROUTAGE"
39+
fi
40+
# see https://instatus.com/help/api/incidents
41+
response=$(curl -s -X POST "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/incidents" \
42+
-H "Authorization: Bearer $INSTATUS_API_KEY" \
43+
-H "Content-Type: application/json" \
44+
-d "{
45+
\"name\": \"$incident_name\",
46+
\"message\": \"$message\",
47+
\"components\": [\"$INSTATUS_COMPONENT_ID\"],
48+
\"status\": \"INVESTIGATING\",
49+
\"notify\": true,
50+
\"statuses\": [
51+
{
52+
\"id\": \"$INSTATUS_COMPONENT_ID\",
53+
\"status\": \"PARTIALOUTAGE\"
54+
}
55+
]
56+
}")
57+
58+
incident_id=$(echo "$response" | jq -r '.id')
59+
echo "$incident_id"
60+
}
61+
62+
# Check each module's accessibility
1763
for module in "${modules[@]}"; do
1864
# Trim leading/trailing whitespace from module name
1965
module=$(echo "${module}" | xargs)
2066
url="${REGISTRY_BASE_URL}/modules/${module}"
21-
printf "=== Check module %s at %s\n" "${module}" "${url}"
67+
printf "=== Checking module %s at %s\n" "${module}" "${url}"
2268
status_code=$(curl --output /dev/null --head --silent --fail --location "${url}" --retry 3 --write-out "%{http_code}")
2369
# shellcheck disable=SC2181
2470
if (( status_code != 200 )); then
@@ -30,7 +76,23 @@ for module in "${modules[@]}"; do
3076
fi
3177
done
3278

33-
if (( status != 0 )); then
34-
echo "The following modules appear to have issues: ${failures[*]}"
79+
# Determine overall status and update Instatus component
80+
if (( status == 0 )); then
81+
echo "All modules are operational."
82+
# set to
83+
update_component_status "OPERATIONAL"
84+
else
85+
echo "The following modules have issues: ${failures[*]}"
86+
# check if all modules are down
87+
if (( ${#failures[@]} == ${#modules[@]} )); then
88+
update_component_status "MAJOROUTAGE"
89+
else
90+
update_component_status "PARTIALOUTAGE"
91+
fi
92+
93+
# Create a new incident
94+
incident_id=$(create_incident)
95+
echo "Created incident with ID: $incident_id"
3596
fi
97+
3698
exit "${status}"

.github/workflows/check.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ jobs:
1616
- name: Run check.sh
1717
run: |
1818
./.github/scripts/check.sh
19+
env:
20+
INSTATUS_API_KEY: ${{ secrets.INSTATUS_API_KEY }}
21+
INSTATUS_PAGE_ID: ${{ secrets.INSTATUS_PAGE_ID }}
22+
INSTATUS_COMPONENT_ID: ${{ secrets.INSTATUS_COMPONENT_ID }}

0 commit comments

Comments
 (0)
0