Commit 89ad50ba authored by Jérome Perrin's avatar Jérome Perrin

stack/erp5: socat wrapper to get haproxy stats

haproxy can be controlled with this socket, so it might be useful
to "expose" it - it's not really expose because we only use a
UNIX socket.
parent 086280d6
......@@ -7,6 +7,7 @@ parts =
[socat]
recipe = slapos.recipe.cmmi
shared = true
url = http://www.dest-unreach.org/socat/download/socat-${:version}.tar.gz
version = 1.7.3.2
md5sum = aec3154f7854580cfab0c2d81e910519
......
......@@ -375,6 +375,25 @@ class TestBalancer(BalancerTestCase):
requests.get(self.default_balancer_url, verify=False, cookies=cookies).text,
'backend_web_server1')
def test_balancer_stats_socket(self):
# real time statistics can be obtained by using the stats socket and there
# is a wrapper which makes this a bit easier.
socat_process = subprocess.Popen(
[self.computer_partition_root_path + '/bin/haproxy-socat-stats'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
try:
output, _ = socat_process.communicate("show stat\n")
except:
socat_process.kill()
socat_process.wait()
raise
self.assertEqual(socat_process.poll(), 0)
# output is a csv
self.assertIn('family_default,FRONTEND,', output)
class TestHTTP(BalancerTestCase):
"""Check HTTP protocol with a HTTP/1.1 backend
......
......@@ -11,6 +11,7 @@ extends =
../../component/gzip/buildout.cfg
../../component/xz-utils/buildout.cfg
../../component/haproxy/buildout.cfg
../../component/socat/buildout.cfg
../../component/rsyslogd/buildout.cfg
../../component/findutils/buildout.cfg
../../component/librsvg/buildout.cfg
......@@ -179,6 +180,7 @@ context =
key gzip_location gzip:location
key xz_utils_location xz-utils:location
key haproxy_location haproxy:location
key socat_location socat:location
key rsyslogd_location rsyslogd:location
key instance_common_cfg instance-common:rendered
key jsl_location jsl:location
......
......@@ -70,7 +70,7 @@ md5sum = cc19560b9400cecbd23064d55c501eec
[template]
filename = instance.cfg.in
md5sum = 3a0b3cbee2ed83fba32410bac15914fb
md5sum = 960c7591b7744aab05a178d1489dacc3
[monitor-template-dummy]
filename = dummy.cfg
......@@ -90,7 +90,7 @@ md5sum = 2f3ddd328ac1c375e483ecb2ef5ffb57
[template-balancer]
filename = instance-balancer.cfg.in
md5sum = 05c3c35d0aadad566de992a13c9fd2d2
md5sum = d5b26109702fb6502e9b1342b4f35160
[template-haproxy-cfg]
filename = haproxy.cfg.in
......
......@@ -256,6 +256,15 @@ wrapper-path = ${directory:services-on-watch}/haproxy
command-line = "{{ parameter_dict['haproxy'] }}/sbin/haproxy" -f "${haproxy-cfg:rendered}"
hash-files = ${haproxy-cfg:rendered}
[{{ section('haproxy-socat-stats')}}]
recipe = collective.recipe.template
output = ${directory:bin}/${:_buildout_section_name_}
mode = 700
input =
inline:
#!/bin/sh
"{{ parameter_dict['socat'] }}/bin/socat" unix-connect:${haproxy-cfg-parameter-dict:stats-socket} stdio
  • Isn't slapos.cookbook:wrapper better ? In any case, let's avoid recipes for which we have forks.

  • slapos.cookbook:wrapper usually tries to be too clever and usually escape too much, so I always avoid using it, but here it would be OK to use it.

    I copied from existing section that was already collective.recipe.template, but probably we can use some slapos recipe for this and other sections. I'll review the recipes** used here, thanks.

    Edited by Jérome Perrin
  • I changed this one to slapos.cookbook:wrapper others are using collective.recipe.template because it supports inline: input and does not escape. There are ~50 cases of collective.recipe.template so I don't start changing this now.

  • I don't understand "too clever" and "escape too much". Can detail / give an example ?

  • In the past I had troubles using this recipe to generate "simple scripts" ( thinks like kill $(cat pidfile) or PATH=${something:location}/bin/:$PATH command ), but for such a case were we only generate a wrapper it's actually fine.

  • Yes, slapos.cookbook:wrapper can't be used to write (ba)sh code.

Please register or sign in to reply
[rsyslogd-cfg-parameter-dict]
log-socket = ${directory:run}/log.sock
access-log-file = ${directory:log}/apache-access.log
......
......@@ -59,6 +59,7 @@ openssl-location = {{ openssl_location }}
openssl = {{ openssl_location }}
haproxy = {{ haproxy_location }}
rsyslogd = {{ rsyslogd_location }}
socat = {{ socat_location }}
apachedex-location = {{ bin_directory }}/apachedex
run-apachedex-location = {{ bin_directory }}/runApacheDex
promise-check-apachedex-result = {{ bin_directory }}/check-apachedex-result
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment