From d8e8e4a53235ac2efa4d220dfa2e2627dfc2bf85 Mon Sep 17 00:00:00 2001 From: pfans Date: Sun, 15 Oct 2023 23:06:45 -0500 Subject: [PATCH] Added change_status to health check. (#73) --- pjs/common/health-check.js | 27 +++++++++++++++++++-------- pjs/lib/metrics.js | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pjs/common/health-check.js b/pjs/common/health-check.js index f5a56cd..c23e39c 100644 --- a/pjs/common/health-check.js +++ b/pjs/common/health-check.js @@ -49,7 +49,7 @@ ), ok: target => ( - (target.alive === 0) && ( + (target.alive === 0) ? ( target.alive = 1, target.errorCount = 0, healthCheckServices[name] && healthCheckServices[name].get(target.target) && ( @@ -57,14 +57,18 @@ ), isDebugEnabled && ( console.log('[health-check] ok - service, type, target:', name, type, target) - ) + ), + _changed = 1 + ) : ( + _changed = 0 ), metrics.fgwUpstreamStatus.withLabels( name, target.ip, target.port, target.reason = 'ok', - target.http_status || '' + target.http_status || '', + _changed ).increase(), hcLogging?.({ k8s_cluster, @@ -73,12 +77,13 @@ upstream_ip: target.ip, upstream_port: target.port, type: 'ok', - http_status: target.http_status || '' + http_status: target.http_status || '', + change_status: _changed }) ), fail: target => ( - (++target.errorCount >= maxFails && target.alive) && ( + (++target.errorCount >= maxFails && target.alive) ? ( target.alive = 0, target.failTick = 0, !healthCheckServices[name] ? ( @@ -91,14 +96,18 @@ ), isDebugEnabled && ( console.log('[health-check] fail - service, type, target:', name, type, target) - ) + ), + _changed = -1 + ) : ( + _changed = 0 ), metrics.fgwUpstreamStatus.withLabels( name, target.ip, target.port, target.reason || 'fail', - target.http_status || '' + target.http_status || '', + _changed ).decrease(), hcLogging?.({ k8s_cluster, @@ -107,7 +116,8 @@ upstream_ip: target.ip, upstream_port: target.port, type: target.reason || 'fail', - http_status: target.http_status || '' + http_status: target.http_status || '', + change_status: _changed }) ), @@ -168,6 +178,7 @@ ) => pipy({ _idx: 0, + _changed: 0, _service: null, _target: null, _resolve: null, diff --git a/pjs/lib/metrics.js b/pjs/lib/metrics.js index 0dfc4d4..8e4ba54 100644 --- a/pjs/lib/metrics.js +++ b/pjs/lib/metrics.js @@ -32,7 +32,7 @@ ]), fgwUpstreamStatus = new stats.Gauge('fgw_upstream_status', [ - 'name', 'ip', 'port', 'type', 'http_status' + 'name', 'ip', 'port', 'type', 'http_status', 'changed' ]), fgwHttpLatency = new stats.Histogram('fgw_http_latency', [