|
| 1 | +name: Validate monitoring contracts |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - "kubernetes/monitoring/**" |
| 7 | + - "kubernetes/base/hub-auth/**" |
| 8 | + - "kubernetes/base/backend/**" |
| 9 | + - "kubernetes/base/celery-beat/**" |
| 10 | + - "kubernetes/base/celery-worker/**" |
| 11 | + - "kubernetes/overlays/dev/**" |
| 12 | + - "kubernetes/overlays/prod/**" |
| 13 | + - "hub/auth_server/**" |
| 14 | + - "backend/account/middleware.py" |
| 15 | + - "backend/account/tests.py" |
| 16 | + - "backend/judge/tasks.py" |
| 17 | + - "backend/judge/tests.py" |
| 18 | + - "backend/oj/celery.py" |
| 19 | + - "backend/problem/llm_hint.py" |
| 20 | + - "backend/problem/views/oj.py" |
| 21 | + - "backend/problem/tests.py" |
| 22 | + - "backend/submission/views/oj.py" |
| 23 | + - "backend/submission/tests.py" |
| 24 | + - "backend/utils/observability_metrics.py" |
| 25 | + - "backend/utils/observability_tracing.py" |
| 26 | + - "backend/utils/tests.py" |
| 27 | + - "backend/utils/test_observability_tracing.py" |
| 28 | + - ".github/workflows/monitoring-validate.yml" |
| 29 | + push: |
| 30 | + branches: [develop, main] |
| 31 | + paths: |
| 32 | + - "kubernetes/monitoring/**" |
| 33 | + - "kubernetes/base/hub-auth/**" |
| 34 | + - "kubernetes/base/backend/**" |
| 35 | + - "kubernetes/base/celery-beat/**" |
| 36 | + - "kubernetes/base/celery-worker/**" |
| 37 | + - "kubernetes/overlays/dev/**" |
| 38 | + - "kubernetes/overlays/prod/**" |
| 39 | + - "hub/auth_server/**" |
| 40 | + - "backend/account/middleware.py" |
| 41 | + - "backend/account/tests.py" |
| 42 | + - "backend/judge/tasks.py" |
| 43 | + - "backend/judge/tests.py" |
| 44 | + - "backend/oj/celery.py" |
| 45 | + - "backend/problem/llm_hint.py" |
| 46 | + - "backend/problem/views/oj.py" |
| 47 | + - "backend/problem/tests.py" |
| 48 | + - "backend/submission/views/oj.py" |
| 49 | + - "backend/submission/tests.py" |
| 50 | + - "backend/utils/observability_metrics.py" |
| 51 | + - "backend/utils/observability_tracing.py" |
| 52 | + - "backend/utils/tests.py" |
| 53 | + - "backend/utils/test_observability_tracing.py" |
| 54 | + - ".github/workflows/monitoring-validate.yml" |
| 55 | + |
| 56 | +permissions: |
| 57 | + contents: read |
| 58 | + |
| 59 | +jobs: |
| 60 | + validate: |
| 61 | + runs-on: ubuntu-latest |
| 62 | + env: |
| 63 | + POSTGRES_HOST: 127.0.0.1 |
| 64 | + POSTGRES_PORT: "5435" |
| 65 | + POSTGRES_DB: onlinejudge |
| 66 | + POSTGRES_USER: onlinejudge |
| 67 | + POSTGRES_PASSWORD: onlinejudge |
| 68 | + REDIS_HOST: 127.0.0.1 |
| 69 | + REDIS_PORT: "6380" |
| 70 | + services: |
| 71 | + postgres: |
| 72 | + image: postgres:14 |
| 73 | + env: |
| 74 | + POSTGRES_DB: onlinejudge |
| 75 | + POSTGRES_USER: onlinejudge |
| 76 | + POSTGRES_PASSWORD: onlinejudge |
| 77 | + ports: |
| 78 | + - 5435:5432 |
| 79 | + options: >- |
| 80 | + --health-cmd "pg_isready -U onlinejudge -d onlinejudge" |
| 81 | + --health-interval 10s |
| 82 | + --health-timeout 5s |
| 83 | + --health-retries 5 |
| 84 | + redis: |
| 85 | + image: redis:7-alpine |
| 86 | + ports: |
| 87 | + - 6380:6379 |
| 88 | + options: >- |
| 89 | + --health-cmd "redis-cli ping" |
| 90 | + --health-interval 10s |
| 91 | + --health-timeout 5s |
| 92 | + --health-retries 5 |
| 93 | + steps: |
| 94 | + - name: Checkout repository |
| 95 | + uses: actions/checkout@v6 |
| 96 | + |
| 97 | + - name: Set up Python |
| 98 | + uses: actions/setup-python@v6 |
| 99 | + with: |
| 100 | + python-version: "3.11" |
| 101 | + |
| 102 | + - name: Set up kubectl |
| 103 | + uses: azure/setup-kubectl@v4 |
| 104 | + with: |
| 105 | + version: "v1.33.6" |
| 106 | + |
| 107 | + - name: Set up Helm |
| 108 | + uses: azure/setup-helm@v4 |
| 109 | + with: |
| 110 | + version: "v3.18.6" |
| 111 | + |
| 112 | + - name: Install validation dependencies |
| 113 | + run: python -m pip install --disable-pip-version-check -r backend/deploy/requirements.txt -r hub/auth_server/requirements.txt pytest PyYAML |
| 114 | + |
| 115 | + - name: Test hub-auth health contract |
| 116 | + working-directory: hub/auth_server |
| 117 | + env: |
| 118 | + GITHUB_OAUTH_APP_ID: test-client |
| 119 | + GITHUB_OAUTH_APP_SECRET: test-secret |
| 120 | + run: python -m pytest app/test_main.py |
| 121 | + |
| 122 | + - name: Test trace resource contract |
| 123 | + env: |
| 124 | + PYTHONPATH: backend |
| 125 | + run: python -m unittest utils.test_observability_tracing |
| 126 | + |
| 127 | + - name: Test backend observability contracts |
| 128 | + working-directory: backend |
| 129 | + run: | |
| 130 | + printf 'monitoring-validation-secret\n' >data/config/secret.key |
| 131 | + python manage.py test \ |
| 132 | + utils.tests.CodePlaceCollectorTest \ |
| 133 | + utils.tests.CeleryRequestIDContextTest \ |
| 134 | + utils.tests.ObservabilityTracingTest \ |
| 135 | + utils.tests.CodePlaceMetricsEndpointTest \ |
| 136 | + judge.tests.JudgeTaskObservabilityTest \ |
| 137 | + account.tests.RequestLogMiddlewareTest \ |
| 138 | + problem.tests.ProblemLLMHintAPITest.test_stream_llm_hint_records_api_success_outcome \ |
| 139 | + problem.tests.ProblemLLMHintAPITest.test_stream_llm_hint_records_success_metric \ |
| 140 | + problem.tests.ProblemLLMHintAPITest.test_stream_llm_hint_records_request_error_metric \ |
| 141 | + problem.tests.ProblemLLMHintAPITest.test_stream_llm_hint_records_problem_limit_outcome \ |
| 142 | + submission.tests.SubmissionAPITest.test_create_submission_records_success_outcome \ |
| 143 | + submission.tests.SubmissionAPITest.test_create_submission_records_problem_not_found_outcome |
| 144 | +
|
| 145 | + - name: Validate dashboard contracts |
| 146 | + run: python kubernetes/monitoring/validate_dashboards.py --prometheus-rules-output /tmp/codeplace-dashboard-rules.json |
| 147 | + |
| 148 | + - name: Validate alert contracts |
| 149 | + run: python kubernetes/monitoring/validate_alerts.py |
| 150 | + |
| 151 | + - name: Render Kubernetes manifests |
| 152 | + run: | |
| 153 | + kubectl kustomize kubernetes/overlays/dev >/dev/null |
| 154 | + kubectl kustomize kubernetes/overlays/prod >/dev/null |
| 155 | + kubectl kustomize kubernetes/monitoring >/tmp/codeplace-monitoring.yaml |
| 156 | + python -c 'import pathlib, yaml; docs=[doc for doc in yaml.safe_load_all(pathlib.Path("/tmp/codeplace-monitoring.yaml").read_text()) if doc]; assert any(doc.get("kind") == "PodMonitor" and doc.get("metadata", {}).get("name") == "traefik" for doc in docs), "Traefik PodMonitor is missing"; assert not any(doc.get("kind") == "ServiceMonitor" and doc.get("metadata", {}).get("name") == "traefik" for doc in docs), "legacy Traefik ServiceMonitor remains"' |
| 157 | + test ! -e kubernetes/monitoring/traefik-service-monitor.yaml |
| 158 | +
|
| 159 | + - name: Render pinned monitoring charts |
| 160 | + run: | |
| 161 | + helm template kube-prometheus-stack kube-prometheus-stack \ |
| 162 | + --repo https://prometheus-community.github.io/helm-charts \ |
| 163 | + --version 86.3.1 \ |
| 164 | + --namespace monitoring \ |
| 165 | + --kube-version 1.33.6 \ |
| 166 | + --values kubernetes/monitoring/kube-prometheus-stack-values.yaml >/tmp/kube-prometheus-stack.yaml |
| 167 | + python -c 'import pathlib, yaml; docs=[doc for doc in yaml.safe_load_all(pathlib.Path("/tmp/kube-prometheus-stack.yaml").read_text()) if doc]; assert any(doc.get("kind") == "Job" and doc.get("metadata", {}).get("name") == "kube-prometheus-stack-crds-upgrade" for doc in docs), "CRD upgrade Job is missing"; grafana=next(doc for doc in docs if doc.get("kind") == "Deployment" and doc.get("metadata", {}).get("name") == "kube-prometheus-stack-grafana"); assert grafana.get("spec", {}).get("strategy", {}).get("type") == "Recreate", "Grafana must use Recreate with its RWO PVC"' |
| 168 | + helm template loki loki \ |
| 169 | + --repo https://grafana.github.io/helm-charts \ |
| 170 | + --version 6.55.0 \ |
| 171 | + --namespace monitoring \ |
| 172 | + --kube-version 1.33.6 \ |
| 173 | + --api-versions monitoring.coreos.com/v1/ServiceMonitor \ |
| 174 | + --values kubernetes/monitoring/logs/loki-values.yaml >/dev/null |
| 175 | + helm template alloy alloy \ |
| 176 | + --repo https://grafana.github.io/helm-charts \ |
| 177 | + --version 1.10.0 \ |
| 178 | + --namespace monitoring \ |
| 179 | + --kube-version 1.33.6 \ |
| 180 | + --api-versions monitoring.coreos.com/v1/ServiceMonitor \ |
| 181 | + --values kubernetes/monitoring/logs/alloy-values.yaml >/dev/null |
| 182 | +
|
| 183 | + - name: Validate Prometheus rules |
| 184 | + run: | |
| 185 | + python -c 'import pathlib, yaml; source=yaml.safe_load(pathlib.Path("kubernetes/monitoring/prometheus-rules.yaml").read_text()); pathlib.Path("/tmp/codeplace-rules.yaml").write_text(yaml.safe_dump({"groups": source["spec"]["groups"]}))' |
| 186 | + docker run --rm --entrypoint /bin/promtool -v /tmp/codeplace-rules.yaml:/rules.yaml:ro prom/prometheus:v3.7.3 check rules /rules.yaml |
| 187 | + docker run --rm --entrypoint /bin/promtool -v /tmp/codeplace-dashboard-rules.json:/rules.json:ro prom/prometheus:v3.7.3 check rules /rules.json |
| 188 | + docker run --rm --entrypoint /bin/promtool -v /tmp/codeplace-rules.yaml:/rules.yaml:ro -v "$PWD/kubernetes/monitoring/prometheus-rules.test.yaml:/rules.test.yaml:ro" prom/prometheus:v3.7.3 test rules /rules.test.yaml |
0 commit comments