diff --git a/apps/nxtgauge-backend-rust/base/kustomization.yaml b/apps/nxtgauge-backend-rust/base/kustomization.yaml index a65878a..c321eb6 100644 --- a/apps/nxtgauge-backend-rust/base/kustomization.yaml +++ b/apps/nxtgauge-backend-rust/base/kustomization.yaml @@ -44,4 +44,6 @@ resources: - ugc-content-creators-deployment.yaml - ugc-content-creators-service.yaml - cron-deployment.yaml + - openobserve-endpoint-monitor-secret.yaml + - openobserve-endpoint-monitor-cronjob.yaml - k8s-migration-job.yaml diff --git a/apps/nxtgauge-backend-rust/base/openobserve-endpoint-monitor-cronjob.yaml b/apps/nxtgauge-backend-rust/base/openobserve-endpoint-monitor-cronjob.yaml new file mode 100644 index 0000000..d70d159 --- /dev/null +++ b/apps/nxtgauge-backend-rust/base/openobserve-endpoint-monitor-cronjob.yaml @@ -0,0 +1,51 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: nxtgauge-openobserve-endpoint-monitor + namespace: nxtgauge +spec: + schedule: "*/1 * * * *" + concurrencyPolicy: Forbid + successfulJobsHistoryLimit: 1 + failedJobsHistoryLimit: 3 + jobTemplate: + spec: + template: + spec: + restartPolicy: OnFailure + containers: + - name: endpoint-monitor + image: curlimages/curl:8.10.1 + imagePullPolicy: IfNotPresent + envFrom: + - secretRef: + name: nxtgauge-openobserve-endpoint-monitor-secret + command: ["/bin/sh", "-ec"] + args: + - | + post_result() { + name="$1" + url="$2" + checked_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + out="$(curl -sS -o /dev/null -w '%{http_code} %{time_total}' --max-time 15 "$url" || true)" + code="$(printf '%s' "$out" | awk '{print $1}')" + total="$(printf '%s' "$out" | awk '{print $2}')" + [ -n "$code" ] || code="0" + [ -n "$total" ] || total="0" + latency_ms="$(awk "BEGIN { printf \"%.0f\", $total * 1000 }")" + if [ "$code" -ge 200 ] && [ "$code" -lt 400 ]; then + ok="true" + else + ok="false" + fi + payload="$(printf '[{"endpoint":"%s","url":"%s","status_code":%s,"ok":%s,"latency_ms":%s,"checked_at":"%s"}]' "$name" "$url" "$code" "$ok" "$latency_ms" "$checked_at")" + curl -sS -X POST \ + "${OO_ENDPOINT}/api/${OO_ORG}/${OO_STREAM}/_json" \ + -H "Authorization: ${OO_AUTH_HEADER}" \ + -H "Content-Type: application/json" \ + -d "$payload" >/dev/null + } + + post_result "frontend" "https://test121.nxtgauge.com/" + post_result "admin" "https://admin.nxtgauge.com/" + post_result "api-health" "https://api.nxtgauge.com/health" diff --git a/apps/nxtgauge-backend-rust/base/openobserve-endpoint-monitor-secret.yaml b/apps/nxtgauge-backend-rust/base/openobserve-endpoint-monitor-secret.yaml new file mode 100644 index 0000000..57fa46b --- /dev/null +++ b/apps/nxtgauge-backend-rust/base/openobserve-endpoint-monitor-secret.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: nxtgauge-openobserve-endpoint-monitor-secret + namespace: nxtgauge +type: Opaque +stringData: + OO_ENDPOINT: "http://o2-openobserve-standalone.openobserve.svc.cluster.local:5080" + OO_ORG: "default" + OO_STREAM: "nxtgauge_endpoints" + OO_AUTH_HEADER: "Basic cm9vdEBleGFtcGxlLmNvbTpDb21wbGV4cGFzcyMxMjM="