blob: 1ac61335686aa5ac9839700068ee9cf84935c54b [file] [log] [blame]
William Dauchy76603f22021-01-10 21:13:06 +01001varnishtest "prometheus exporter test"
2
William Dauchy69164222021-02-07 20:42:38 +01003#REQUIRE_VERSION=2.4
William Dauchy76603f22021-01-10 21:13:06 +01004#REQUIRE_SERVICES=prometheus-exporter
5
6feature ignore_unknown_macro
7
8server s1 {
9 rxreq
10 txresp
11} -repeat 2 -start
12
William Dauchyb4567442021-02-18 23:05:33 +010013server s2 {
14 rxreq
15 txresp
16} -repeat 2 -start
17
William Dauchy76603f22021-01-10 21:13:06 +010018haproxy h1 -conf {
19 defaults
20 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +010021 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
22 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
23 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
William Dauchye3f7bd52021-02-14 23:22:56 +010024 option socket-stats
William Dauchy76603f22021-01-10 21:13:06 +010025
26 listen stats
27 bind "fd@${stats}"
28 http-request use-service prometheus-exporter if { path /metrics }
29
30 frontend fe
31 bind "fd@${fe}"
32 default_backend be
33
34 backend be
William Dauchy69164222021-02-07 20:42:38 +010035 stick-table type ip size 1m expire 10s store http_req_rate(10s)
William Dauchy76603f22021-01-10 21:13:06 +010036 server s1 ${s1_addr}:${s1_port}
William Dauchyb4567442021-02-18 23:05:33 +010037 server s2 ${s2_addr}:${s2_port} check maxqueue 10 maxconn 12 pool-max-conn 42
William Dauchy76603f22021-01-10 21:13:06 +010038} -start
39
40client c1 -connect ${h1_stats_sock} {
41 txreq -url "/metrics"
42 rxresp
William Dauchyb4567442021-02-18 23:05:33 +010043 # test general metrics
William Dauchy76603f22021-01-10 21:13:06 +010044 expect resp.status == 200
45 expect resp.body ~ ".*haproxy_process.*"
46 expect resp.body ~ ".*haproxy_frontend.*"
William Dauchye3f7bd52021-02-14 23:22:56 +010047 expect resp.body ~ ".*haproxy_listener.*"
William Dauchy76603f22021-01-10 21:13:06 +010048 expect resp.body ~ ".*haproxy_backend.*"
49 expect resp.body ~ ".*haproxy_server.*"
William Dauchy69164222021-02-07 20:42:38 +010050 expect resp.body ~ ".*haproxy_sticktable.*"
William Dauchy76603f22021-01-10 21:13:06 +010051
William Dauchyb4567442021-02-18 23:05:33 +010052 # test expected NaN values
53 expect resp.body ~ ".*haproxy_server_check_failures_total{proxy=\"be\",server=\"s1\"} NaN.*"
54 expect resp.body ~ ".*haproxy_server_check_up_down_total{proxy=\"be\",server=\"s1\"} NaN.*"
55 expect resp.body ~ ".*haproxy_server_check_failures_total{proxy=\"be\",server=\"s2\"} 0.*"
56 expect resp.body ~ ".*haproxy_server_check_up_down_total{proxy=\"be\",server=\"s2\"} 0.*"
57
58 expect resp.body ~ ".*haproxy_server_queue_limit{proxy=\"be\",server=\"s1\"} NaN.*"
59 expect resp.body ~ ".*haproxy_server_queue_limit{proxy=\"be\",server=\"s2\"} 10.*"
60
61 expect resp.body ~ ".*haproxy_server_limit_sessions{proxy=\"be\",server=\"s1\"} NaN.*"
62 expect resp.body ~ ".*haproxy_server_limit_sessions{proxy=\"be\",server=\"s2\"} 12.*"
63
64 expect resp.body ~ ".*haproxy_backend_downtime_seconds_total{proxy=\"stats\"} NaN.*"
65 expect resp.body ~ ".*haproxy_backend_downtime_seconds_total{proxy=\"be\"} 0.*"
66 expect resp.body ~ ".*haproxy_server_downtime_seconds_total{proxy=\"be\",server=\"s1\"} NaN.*"
67 expect resp.body ~ ".*haproxy_server_downtime_seconds_total{proxy=\"be\",server=\"s2\"} 0.*"
68
69 expect resp.body ~ ".*haproxy_server_current_throttle{proxy=\"be\",server=\"s1\"} NaN.*"
70
71 expect resp.body ~ ".*haproxy_server_idle_connections_limit{proxy=\"be\",server=\"s1\"} NaN.*"
72 expect resp.body ~ ".*haproxy_server_idle_connections_limit{proxy=\"be\",server=\"s2\"} 42.*"
73
William Dauchy98ad35f2021-02-18 23:05:34 +010074 # test well known labels presence
75 expect resp.body ~ ".*haproxy_process_build_info{version=\".*\"} 1.*"
76 expect resp.body ~ ".*haproxy_frontend_http_responses_total{proxy=\"stats\",code=\"4xx\"} 0.*"
77 expect resp.body ~ ".*haproxy_frontend_status{proxy=\"fe\",state=\"UP\"} 1.*"
78 expect resp.body ~ ".*haproxy_listener_status{proxy=\"stats\",listener=\"sock-1\",state=\"WAITING\"} 0.*"
79 expect resp.body ~ ".*haproxy_backend_status{proxy=\"be\",state=\"UP\"} 1.*"
80 expect resp.body ~ ".*haproxy_server_status{proxy=\"be\",server=\"s1\",state=\"DOWN\"} 0.*"
81 expect resp.body ~ ".*haproxy_server_check_status{proxy=\"be\",server=\"s2\",state=\"HANA\"} 0.*"
82
William Dauchyb4567442021-02-18 23:05:33 +010083 # test scope
William Dauchy76603f22021-01-10 21:13:06 +010084 txreq -url "/metrics?scope="
85 rxresp
86 expect resp.status == 200
87 expect resp.bodylen == 0
William Dauchy76603f22021-01-10 21:13:06 +010088
William Dauchy76603f22021-01-10 21:13:06 +010089 txreq -url "/metrics?scope=server"
90 rxresp
91 expect resp.status == 200
92 expect resp.body !~ ".*haproxy_process.*"
93 expect resp.body !~ ".*haproxy_frontend.*"
William Dauchye3f7bd52021-02-14 23:22:56 +010094 expect resp.body !~ ".*haproxy_listener.*"
William Dauchy76603f22021-01-10 21:13:06 +010095 expect resp.body !~ ".*haproxy_backend.*"
96 expect resp.body ~ ".*haproxy_server.*"
William Dauchy69164222021-02-07 20:42:38 +010097 expect resp.body !~ ".*haproxy_sticktable.*"
William Dauchy76603f22021-01-10 21:13:06 +010098
William Dauchy76603f22021-01-10 21:13:06 +010099 txreq -url "/metrics?scope=frontend&scope=backend"
100 rxresp
101 expect resp.status == 200
102 expect resp.body !~ ".*haproxy_process.*"
103 expect resp.body ~ ".*haproxy_frontend.*"
William Dauchye3f7bd52021-02-14 23:22:56 +0100104 expect resp.body !~ ".*haproxy_listener.*"
William Dauchy76603f22021-01-10 21:13:06 +0100105 expect resp.body ~ ".*haproxy_backend.*"
106 expect resp.body !~ ".*haproxy_server.*"
William Dauchy69164222021-02-07 20:42:38 +0100107 expect resp.body !~ ".*haproxy_sticktable.*"
William Dauchy1704efe2021-01-11 20:07:48 +0100108
109 txreq -url "/metrics?scope"
110 rxresp
111 expect resp.status == 400
William Dauchy76603f22021-01-10 21:13:06 +0100112} -run