#!/bin/bash # Health check utilities for fetch_ml deployments set -e REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd) # Colors GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' print_success() { echo -e "${GREEN}[OK]${NC} $1"; } print_error() { echo -e "${RED}[FAIL]${NC} $1"; } print_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } # Check health for a specific environment check_environment() { local env=$1 local port case $env in dev) port=9101 ;; staging) port=9102 ;; prod) port=9101 ;; *) port=9101 ;; esac echo "=== ${env} Environment (port ${port}) ===" if curl -fsS "http://localhost:${port}/health" > /dev/null 2>&1; then print_success "API is responding" # Get detailed health info local health health=$(curl -fsS "http://localhost:${port}/health" 2>/dev/null || echo "{}") # Check compliance mode local compliance compliance=$(echo "$health" | grep -o '"compliance_mode":"[^"]*"' | cut -d'"' -f4 || echo "unknown") echo " Compliance mode: $compliance" # Check native libs status if echo "$health" | grep -q '"native_libs":true'; then print_success "Native libraries enabled" else print_warn "Native libraries not enabled" fi else print_error "API health check failed" return 1 fi echo "" } # Main main() { local env=${1:-all} echo "=== FetchML Health Check ===" echo "" if [ "$env" = "all" ]; then check_environment dev || true check_environment staging || true check_environment prod || true else check_environment "$env" fi } main "$@"