summaryrefslogtreecommitdiffstats
path: root/reg-tests/contrib/prometheus.vtc
blob: 89d65d7b74c25ec1c120d1b2f89aedbf35274159 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
varnishtest "prometheus exporter test"

feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(3.0-dev0)'"
#REQUIRE_SERVICES=prometheus-exporter

feature ignore_unknown_macro

server s1 {
	rxreq
	txresp
} -start

server s2 {
	rxreq
	txresp
}  -start

haproxy h1 -conf {
    defaults
	mode http
	timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
	timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
	timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"
	option socket-stats

    listen stats
	bind "fd@${stats}"
        http-request use-service prometheus-exporter if { path /metrics }

    frontend fe
	bind "fd@${fe}"
	default_backend be

    backend be
	stick-table type ip size 1m expire 10s store http_req_rate(10s)
	option httpchk
	server s1 ${s1_addr}:${s1_port}
	server s2 ${s2_addr}:${s2_port} check inter 5s maxqueue 10 maxconn 12 pool-max-conn 42
} -start

client c1 -connect ${h1_stats_sock} {
	# test general metrics
	txreq -url "/metrics"
	rxresp
	expect resp.status == 200
	expect resp.body ~ ".*haproxy_process.*"
	expect resp.body ~ ".*haproxy_frontend.*"
	expect resp.body ~ ".*haproxy_listener.*"
	expect resp.body ~ ".*haproxy_backend.*"
	expect resp.body ~ ".*haproxy_server.*"
	expect resp.body ~ ".*haproxy_sticktable.*"
	expect resp.body ~ ".*haproxy_resolver.*"

	# test well known labels presence
	expect resp.body ~ ".*haproxy_process_build_info{version=\".*\"} 1.*"
	expect resp.body ~ ".*haproxy_frontend_http_responses_total{proxy=\"stats\",code=\"4xx\"} 0.*"
	expect resp.body ~ ".*haproxy_frontend_status{proxy=\"fe\",state=\"UP\"} 1.*"
	expect resp.body ~ ".*haproxy_listener_status{proxy=\"stats\",listener=\"sock-1\",state=\"WAITING\"} 0.*"
	expect resp.body ~ ".*haproxy_backend_status{proxy=\"be\",state=\"UP\"} 1.*"
	expect resp.body ~ ".*haproxy_server_status{proxy=\"be\",server=\"s1\",state=\"DOWN\"} 0.*"
	expect resp.body ~ ".*haproxy_server_check_status{proxy=\"be\",server=\"s2\",state=\"HANA\"} 0.*"

	# test expected NaN values
	txreq -url "/metrics?scope=backend&scope=server"
	rxresp
	expect resp.body ~ ".*haproxy_server_check_failures_total{proxy=\"be\",server=\"s1\"} NaN.*"
	expect resp.body ~ ".*haproxy_server_check_up_down_total{proxy=\"be\",server=\"s1\"} NaN.*"
	expect resp.body ~ ".*haproxy_server_check_failures_total{proxy=\"be\",server=\"s2\"} 0.*"
	expect resp.body ~ ".*haproxy_server_check_up_down_total{proxy=\"be\",server=\"s2\"} 0.*"

	expect resp.body ~ ".*haproxy_server_queue_limit{proxy=\"be\",server=\"s1\"} NaN.*"
	expect resp.body ~ ".*haproxy_server_queue_limit{proxy=\"be\",server=\"s2\"} 10.*"

	expect resp.body ~ ".*haproxy_server_limit_sessions{proxy=\"be\",server=\"s1\"} NaN.*"
	expect resp.body ~ ".*haproxy_server_limit_sessions{proxy=\"be\",server=\"s2\"} 12.*"

	expect resp.body ~ ".*haproxy_backend_downtime_seconds_total{proxy=\"stats\"} NaN.*"
	expect resp.body ~ ".*haproxy_backend_downtime_seconds_total{proxy=\"be\"} 0.*"
	expect resp.body ~ ".*haproxy_server_downtime_seconds_total{proxy=\"be\",server=\"s1\"} NaN.*"
	expect resp.body ~ ".*haproxy_server_downtime_seconds_total{proxy=\"be\",server=\"s2\"} 0.*"

	expect resp.body ~ ".*haproxy_server_current_throttle{proxy=\"be\",server=\"s1\"} NaN.*"

	expect resp.body ~ ".*haproxy_server_idle_connections_limit{proxy=\"be\",server=\"s1\"} NaN.*"
	expect resp.body ~ ".*haproxy_server_idle_connections_limit{proxy=\"be\",server=\"s2\"} 42.*"

	# test scope
	txreq -url "/metrics?scope="
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 0

	txreq -url "/metrics?scope=server"
	rxresp
	expect resp.status == 200
	expect resp.body !~ ".*haproxy_process.*"
	expect resp.body !~ ".*haproxy_frontend.*"
	expect resp.body !~ ".*haproxy_listener.*"
	expect resp.body !~ ".*haproxy_backend.*"
	expect resp.body ~ ".*haproxy_server.*"
	expect resp.body !~ ".*haproxy_sticktable.*"
	expect resp.body !~ ".*haproxy_resolver.*"

	txreq -url "/metrics?scope=frontend&scope=backend"
	rxresp
	expect resp.status == 200
	expect resp.body !~ ".*haproxy_process.*"
	expect resp.body ~ ".*haproxy_frontend.*"
	expect resp.body !~ ".*haproxy_listener.*"
	expect resp.body ~ ".*haproxy_backend.*"
	expect resp.body !~ ".*haproxy_server.*"
	expect resp.body !~ ".*haproxy_sticktable.*"
	expect resp.body !~ ".*haproxy_resolver.*"

	txreq -url "/metrics?scope"
	rxresp
	expect resp.status == 400
} -run