openresty / lua-resty-upstream-healthcheck

Health Checker for Nginx Upstream Servers in Pure Lua
515 stars 134 forks source link

Add prometheus metrics format status with tests #87

Closed freggy closed 2 years ago

freggy commented 2 years ago

Hello, I followed advice left here on #77 and added tests for this functionality.

freggy commented 2 years ago

is there something missing still?

zhuizhuhaomeng commented 2 years ago

is there something missing still?

the CI failed.

Test Summary Report
-------------------
t/sanity.t (Wstat: 65280 Tests: 105 Failed: 0)
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 117 tests but ran 105.
Files=1, Tests=105, 11 wallclock secs ( 0.03 usr  0.00 sys +  0.85 cusr  0.13 csys =  1.01 CPU)
Result: FAIL
The command "prove -r t" exited with 1.
cache.2
store build cache
zhuizhuhaomeng commented 2 years ago

is there something missing still?

please move your test to another file eg: prometheus.t

zhuizhuhaomeng commented 2 years ago

merged with the following patch

diff --git a/lib/resty/upstream/healthcheck.lua b/lib/resty/upstream/healthcheck.lua
index 5fcacd2..0099a59 100644
--- a/lib/resty/upstream/healthcheck.lua
+++ b/lib/resty/upstream/healthcheck.lua
@@ -657,7 +657,7 @@ local function gen_peers_prometheus_status_info(peers, bits, idx, u, role)
     for i = 1, npeers do
         idx = idx + 1
         local peer = peers[i]
-        bits[idx] = string.format("nginx_upstream_status_info{name=\"%s\",endpoint=\"%s\",status=\"%s\",role=\
"%s\"} 1", u, peer.name, peer.down and "DOWN" or "UP", role)   
+        bits[idx] = string.format("nginx_upstream_status_info{name=\"%s\",endpoint=\"%s\",status=\"%s\",role=\
"%s\"} 1", u, peer.name, peer.down and "DOWN" or "UP", role)
     end
     return idx
 end
diff --git a/t/prometheus.t b/t/prometheus.t
new file mode 100644
index 0000000..32fdb0b
--- /dev/null
+++ b/t/prometheus.t
@@ -0,0 +1,221 @@
+# vim:set ft= ts=4 sw=4 et fdm=marker:
+use lib 'lib';
+use Test::Nginx::Socket::Lua;
+use Cwd qw(cwd);
+
...