Skip to content

Commit

Permalink
feat: Add helper function for generating health status JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Dec 18, 2024
1 parent 42ebec4 commit ebea48c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
13 changes: 2 additions & 11 deletions lib/core/health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,10 @@ start_health_updater() {

local health_json
if [ $health_status -ne 0 ]; then
health_json=$(jq -n \
--arg status "$HEALTH_STATUS_DETAILS" \
--arg connections "${curr_connections:-0}" \
--arg uptime "${curr_uptime:-0}" \
--arg errors "$health_status" \
'{health:{status:$status,connections:($connections|tonumber),uptime:($uptime|tonumber),errors:($errors|tonumber)}}')
health_json=$(generate_health_status_json "$HEALTH_STATUS_DETAILS" "${curr_connections}" "${curr_uptime}" "$health_status")
status_json=$(generate_node_status_json "offline" "$current_role" "$health_json")
else
health_json=$(jq -n \
--arg status "$HEALTH_STATUS_DETAILS" \
--arg connections "${curr_connections:-0}" \
--arg uptime "${curr_uptime:-0}" \
'{health:{status:$status,connections:($connections|tonumber),uptime:($uptime|tonumber)}}')
health_json=$(generate_health_status_json "$HEALTH_STATUS_DETAILS" "${curr_connections}" "${curr_uptime}")
status_json=$(generate_node_status_json "online" "$current_role" "$health_json")
fi

Expand Down
15 changes: 15 additions & 0 deletions lib/etcd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ get_node_path() {
# ETCD state files
declare -gr ETCD_STATE_FILE="${STATE_DIR}/etcd_state"

# Generate health status JSON
generate_health_status_json() {
local status=$1
local connections=$2
local uptime=$3
local errors=${4:-0}

jq -n \
--arg status "$status" \
--arg connections "${connections:-0}" \
--arg uptime "${uptime:-0}" \
--arg errors "${errors:-0}" \
'{health:{status:$status,connections:($connections|tonumber),uptime:($uptime|tonumber),errors:($errors|tonumber)}}'
}

# Generate node status JSON
generate_node_status_json() {
local status=$1
Expand Down

0 comments on commit ebea48c

Please sign in to comment.