summaryrefslogtreecommitdiffstats
path: root/reg-tests/log/log_backend.vtc
blob: a9223ee01a7ebdf739ab27aed24ad9af9766d690 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
varnishtest "Test the log backend target"
feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.9-dev0)'"
feature ignore_unknown_macro

server s1 {
    rxreq
	txresp
} -repeat 500 -start

syslog Slg1 -level info {
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: .* \"GET /0 HTTP/1.1\""
} -repeat 100 -start

syslog Slg2 -level info {
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: .* \"GET /1 HTTP/1.1\""
} -repeat 100 -start

syslog Slg21 -level info {
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: .* \"GET /srv1 HTTP/1.1\""
} -repeat 1 -start

syslog Slg22 -level info {
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: .* \"GET /srv2 HTTP/1.1\""
} -repeat 1 -start

syslog Slg23 -level info {
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: .* \"GET /srv3 HTTP/1.1\""
} -repeat 2 -start

syslog Slg24 -level info {
    recv
    expect ~ "[^:\\[ ]\\[${h1_pid}\\]: .* \"GET /backup HTTP/1.1\""
} -repeat 1 -start

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

	frontend fe1
		bind "fd@${fe_1}"
		log backend@mylog-tcp local0
		log backend@mylog-udp local0
		default_backend be

	frontend fe2
		bind "fd@${fe_2}"
		log backend@mylog-failover local0
		default_backend be

	backend be
		server app1 ${s1_addr}:${s1_port}

        backend mylog-tcp
                mode log
                server s1 tcp@127.0.0.1:1514 #TCP: to log-forward

        backend mylog-udp
                mode log

                # extract id (integer) from URL in the form "GET /id" and use it as hash key
                balance log-hash 'field(-2,\"),field(2,/),field(1, )'
                hash-type map-based none

                server s1 udp@${Slg1_addr}:${Slg1_port} # syslog 1 only receives "GET /0" requests
                server s2 udp@${Slg2_addr}:${Slg2_port} # syslog 2 only receives "GET /1" requests

	log-forward syslog2udp
		bind 127.0.0.1:1514
		log backend@mylog-udp local0 # Back to UDP log backend

        backend mylog-failover
                mode log
                balance sticky

                server s1 udp@${Slg21_addr}:${Slg21_port}        # only receives "GET /srv1" request
                server s2 udp@${Slg22_addr}:${Slg22_port}        # only receives "GET /srv2" request
                server s3 udp@${Slg23_addr}:${Slg23_port}        # only receives "GET /srv3" request

                server s4 udp@${Slg24_addr}:${Slg24_port} backup # only receives "GET /backup" request
} -start

# Test log distribution reliability

# all logs should go to s1
client c1 -connect ${h1_fe_1_sock} {
    txreq -url "/0"
    rxresp
    expect resp.status == 200
} -repeat 50 -start

# all logs should go to s2
client c2 -connect ${h1_fe_1_sock} {
    txreq -url "/1"
    rxresp
    expect resp.status == 200
} -repeat 50 -start

syslog Slg1 -wait
syslog Slg2 -wait

# Test server queue/dequeue/failover mechanism

# s1 should handle this
client c21 -connect ${h1_fe_2_sock} {
    txreq -url "/srv1"
    rxresp
    expect resp.status == 200
} -run

haproxy h1 -cli {
        send "disable server mylog-failover/s1"
        expect ~ ".*"
}

# s2 should handle this
client c22 -connect ${h1_fe_2_sock} {
    txreq -url "/srv2"
    rxresp
    expect resp.status == 200
} -run

haproxy h1 -cli {
        send "disable server mylog-failover/s2"
        expect ~ ".*"
}

haproxy h1 -cli {
        send "enable server mylog-failover/s1"
        expect ~ ".*"
}

# s3 should handle this
client c23 -connect ${h1_fe_2_sock} {
    txreq -url "/srv3"
    rxresp
    expect resp.status == 200
} -run

haproxy h1 -cli {
        send "disable server mylog-failover/s1"
        expect ~ ".*"
}

haproxy h1 -cli {
        send "disable server mylog-failover/s3"
        expect ~ ".*"
}

# backup should handle this
client c24 -connect ${h1_fe_2_sock} {
    txreq -url "/backup"
    rxresp
    expect resp.status == 200
} -run

haproxy h1 -cli {
        send "enable server mylog-failover/s3"
        expect ~ ".*"
}

haproxy h1 -cli {
        send "enable server mylog-failover/s2"
        expect ~ ".*"
}

# s3 should handle this
client c25 -connect ${h1_fe_2_sock} {
    txreq -url "/srv3"
    rxresp
    expect resp.status == 200
} -run

syslog Slg21 -wait
syslog Slg22 -wait
syslog Slg23 -wait
syslog Slg24 -wait