Skip to content

Commit

Permalink
Added change_status to health check. (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanpf authored Oct 16, 2023
1 parent b01c4b9 commit d8e8e4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions pjs/common/health-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,26 @@
),

ok: target => (
(target.alive === 0) && (
(target.alive === 0) ? (
target.alive = 1,
target.errorCount = 0,
healthCheckServices[name] && healthCheckServices[name].get(target.target) && (
healthCheckServices[name].remove(target.target)
),
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,
Expand All @@ -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] ? (
Expand All @@ -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,
Expand All @@ -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
})
),

Expand Down Expand Up @@ -168,6 +178,7 @@

) => pipy({
_idx: 0,
_changed: 0,
_service: null,
_target: null,
_resolve: null,
Expand Down
2 changes: 1 addition & 1 deletion pjs/lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down

0 comments on commit d8e8e4a

Please sign in to comment.