ai-news-writer-ci / test (pull_request) Successful in 31s
The /metrics endpoint returns JSON, not Prometheus exposition format. The BIT-3601 Prometheus check was added before the app implemented it, causing staging deploys to always fail the health check and roll back. Remove the exposition-format check; JSON schema validation remains. Paperclip-Issue: BIT-22325 Paperclip-Agent: tiago-neves
125 lines
3.6 KiB
Bash
Executable File
125 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Verify ai-news-writer listen mode is reachable (NPM / LXC smoke test).
|
|
# Usage: ./tools/verify-deploy.sh http://10.10.50.23:3200
|
|
# or: VERIFY_URL=http://10.10.50.23:3200 ./tools/verify-deploy.sh
|
|
set -euo pipefail
|
|
|
|
BASE="${1:-${VERIFY_URL:-}}"
|
|
if [[ -z "${BASE}" ]]; then
|
|
echo "Usage: VERIFY_URL=http://<lxc-ip>:3200 $0" >&2
|
|
echo " or: $0 http://<lxc-ip>:3200" >&2
|
|
exit 2
|
|
fi
|
|
|
|
BASE="${BASE%/}"
|
|
HEALTH_URL="${BASE}/health"
|
|
METRICS_URL="${BASE}/metrics"
|
|
|
|
if ! command -v curl >/dev/null 2>&1; then
|
|
echo "error: curl is required" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v node >/dev/null 2>&1; then
|
|
echo "error: node is required to parse /health JSON" >&2
|
|
exit 1
|
|
fi
|
|
|
|
_JSON="$(curl -sfS --max-time 15 "${HEALTH_URL}")" || {
|
|
echo "error: GET ${HEALTH_URL} failed (is the CT up and pm2 running ecosystem.config.cjs?)" >&2
|
|
exit 1
|
|
}
|
|
|
|
echo "${_JSON}" | node -e "
|
|
const fs = require('fs');
|
|
const input = fs.readFileSync(0, 'utf8');
|
|
let d;
|
|
try {
|
|
d = JSON.parse(input);
|
|
} catch (e) {
|
|
console.error('error: invalid JSON from /health');
|
|
process.exit(1);
|
|
}
|
|
if (d.ok !== true || d.mode !== 'listen') {
|
|
console.error('error: unexpected payload:', JSON.stringify(d, null, 2));
|
|
process.exit(1);
|
|
}
|
|
console.log(
|
|
'OK',
|
|
d.service,
|
|
'version=' + (d.version || '?'),
|
|
'pid=' + (d.pid ?? '?'),
|
|
'node=' + (d.node_version || '?'),
|
|
'uptime_sec=' + (d.uptime_sec ?? '?')
|
|
);
|
|
if (d.deploy_revision) {
|
|
console.log('deploy_revision=' + d.deploy_revision);
|
|
}
|
|
if (d.http_request_timeout_ms != null) {
|
|
console.log('http_request_timeout_ms=' + d.http_request_timeout_ms, 'http_headers_timeout_ms=' + d.http_headers_timeout_ms);
|
|
}
|
|
if (d.http_body_read_timeout_ms != null) {
|
|
console.log('http_body_read_timeout_ms=' + d.http_body_read_timeout_ms);
|
|
}
|
|
if (d.rss_listener_last_tick_at != null) {
|
|
console.log(
|
|
'rss_listener_last_tick_at=' + d.rss_listener_last_tick_at,
|
|
'ok=' + d.rss_listener_last_tick_ok,
|
|
d.rss_listener_last_tick_error != null ? 'error=' + d.rss_listener_last_tick_error : ''
|
|
);
|
|
} else if (d.rss_listener_active === true) {
|
|
console.log('rss_listener_active=true (no tick yet — wait for first cron run)');
|
|
}
|
|
if ((d.rss_listener_overlap_skips || 0) > 0) {
|
|
console.log('rss_listener_overlap_skips=' + d.rss_listener_overlap_skips);
|
|
}
|
|
if (d.listen_auto_cron) {
|
|
console.log('listen_auto_cron=' + d.listen_auto_cron);
|
|
}
|
|
if (d.rss_cron_timezone) {
|
|
console.log('rss_cron_timezone=' + d.rss_cron_timezone);
|
|
}
|
|
if (d.article_log_bytes != null) {
|
|
console.log('article_log_bytes=' + d.article_log_bytes);
|
|
}
|
|
if (d.metrics_summary && typeof d.metrics_summary === 'object') {
|
|
const m = d.metrics_summary;
|
|
console.log(
|
|
'metrics_summary',
|
|
'articles_generated=' + (m.articles_generated ?? '?'),
|
|
'articles_published=' + (m.articles_published ?? '?'),
|
|
'uptime_seconds=' + (m.uptime_seconds ?? '?')
|
|
);
|
|
}
|
|
"
|
|
|
|
_METRICS_JSON="$(curl -sfS --max-time 15 "${METRICS_URL}")" || {
|
|
echo "error: GET ${METRICS_URL} failed" >&2
|
|
exit 1
|
|
}
|
|
|
|
echo "${_METRICS_JSON}" | node -e "
|
|
const fs = require('fs');
|
|
const input = fs.readFileSync(0, 'utf8');
|
|
let d;
|
|
try {
|
|
d = JSON.parse(input);
|
|
} catch (e) {
|
|
console.error('error: invalid JSON from /metrics');
|
|
process.exit(1);
|
|
}
|
|
if (typeof d.timestamp !== 'string' || !d.timestamp) {
|
|
console.error('error: /metrics missing timestamp');
|
|
process.exit(1);
|
|
}
|
|
if (typeof d.counters !== 'object' || d.counters === null) {
|
|
console.error('error: /metrics missing counters object');
|
|
process.exit(1);
|
|
}
|
|
if (typeof d.gauges !== 'object' || d.gauges === null) {
|
|
console.error('error: /metrics missing gauges object');
|
|
process.exit(1);
|
|
}
|
|
console.log('OK metrics JSON timestamp=' + d.timestamp);
|
|
"
|