Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 1 | varnishtest "Health-checks: PostgreSQL health-check" |
| 2 | #REQUIRE_VERSION=2.2 |
| 3 | #REGTEST_TYPE=slow |
| 4 | feature ignore_unknown_macro |
| 5 | |
| 6 | # This scripts tests health-checks for PostgreSQL application, enabled using |
| 7 | # "option pgsql-check" line. A intermediate listener is used to validate |
| 8 | # the request because it is impossible with VTEST to read and match raw |
| 9 | # text. |
| 10 | |
| 11 | server s1 { |
| 12 | recv 23 |
| 13 | sendhex "520000000800000000" |
| 14 | } -start |
| 15 | |
| 16 | server s2 { |
| 17 | recv 23 |
| 18 | sendhex "450000000B53464154414C00" |
| 19 | } -start |
| 20 | |
| 21 | server s3 { |
| 22 | recv 23 |
| 23 | send "Not a PostgreSQL response" |
| 24 | } -start |
| 25 | |
Fatih Acar | 80cff2f | 2022-09-26 17:27:11 +0200 | [diff] [blame] | 26 | server s4 { |
| 27 | recv 23 |
| 28 | sendhex "52000000170000000A534352414D2D5348412D3235360000" |
| 29 | } -start |
| 30 | |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 31 | syslog S1 -level notice { |
| 32 | recv |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 33 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv succeeded, reason: Layer7 check passed.+info: \"PostgreSQL server is ok\".+check duration: [[:digit:]]+ms, status: 1/1 UP." |
| 34 | } -start |
| 35 | |
| 36 | syslog S2 -level notice { |
| 37 | recv |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 38 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be2/srv failed, reason: Layer7 invalid response.+info: \"FATAL\".+check duration: [[:digit:]]+ms, status: 0/1 DOWN." |
| 39 | } -start |
| 40 | |
| 41 | syslog S3 -level notice { |
| 42 | recv |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 43 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be3/srv failed, reason: Layer7 wrong status.+info: \"PostgreSQL unknown error\".+check duration: [[:digit:]]+ms, status: 0/1 DOWN." |
| 44 | } -start |
| 45 | |
Fatih Acar | 80cff2f | 2022-09-26 17:27:11 +0200 | [diff] [blame] | 46 | syslog S4 -level notice { |
| 47 | recv |
| 48 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be4/srv succeeded, reason: Layer7 check passed.+info: \"PostgreSQL server is ok\".+check duration: [[:digit:]]+ms, status: 1/1 UP." |
| 49 | } -start |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 50 | |
| 51 | haproxy h1 -conf { |
| 52 | defaults |
| 53 | mode tcp |
| 54 | timeout client 1s |
| 55 | timeout server 1s |
| 56 | timeout connect 100ms |
| 57 | |
| 58 | backend be1 |
| 59 | log ${S1_addr}:${S1_port} daemon |
| 60 | option log-health-checks |
| 61 | option pgsql-check user postgres |
| 62 | server srv ${h1_pgsql_addr}:${h1_pgsql_port} check inter 1s rise 1 fall 1 |
| 63 | |
| 64 | backend be2 |
| 65 | log ${S2_addr}:${S2_port} daemon |
| 66 | option log-health-checks |
| 67 | option pgsql-check user postgres |
| 68 | server srv ${s2_addr}:${s2_port} check inter 1s rise 1 fall 1 |
| 69 | |
| 70 | backend be3 |
| 71 | log ${S3_addr}:${S3_port} daemon |
| 72 | option log-health-checks |
| 73 | option pgsql-check user postgres |
| 74 | server srv ${s3_addr}:${s3_port} check inter 1s rise 1 fall 1 |
| 75 | |
Fatih Acar | 80cff2f | 2022-09-26 17:27:11 +0200 | [diff] [blame] | 76 | backend be4 |
| 77 | log ${S4_addr}:${S4_port} daemon |
| 78 | option log-health-checks |
| 79 | option pgsql-check user postgres |
| 80 | server srv ${s4_addr}:${s4_port} check inter 1s rise 1 fall 1 |
| 81 | |
Christopher Faulet | aec7f76 | 2020-04-22 15:16:58 +0200 | [diff] [blame] | 82 | listen pgsql1 |
| 83 | bind "fd@${pgsql}" |
| 84 | tcp-request inspect-delay 100ms |
| 85 | tcp-request content accept if { req.len eq 23 } { req.payload(0,23) -m bin "00000017000300007573657200706f7374677265730000" } |
| 86 | tcp-request content reject |
| 87 | server srv ${s1_addr}:${s1_port} |
| 88 | } -start |
| 89 | |
| 90 | syslog S1 -wait |
| 91 | syslog S2 -wait |
| 92 | syslog S3 -wait |
Fatih Acar | 80cff2f | 2022-09-26 17:27:11 +0200 | [diff] [blame] | 93 | syslog S4 -wait |