# ERP5: id-store-interval must be big enough to avoid conflicts (e.g. 1000)

# XXX: Because supervisord can't handle too many processes
#      ("too many open files to spawn" errors), these SR
#      should instantiate the source processes differently.

[buildout]
extends = test-fluentd-common.cfg

[template-erp5-patched]
extra =
  [request-balancer]
  config-inituser-login = {{ dumps(inituser_login) }}
  config-inituser-password = $${publish-early:inituser-password}

[template-balancer]
recipe =
target = ${template-balancer-patched:location}

[template-balancer-base]
<= template-balancer
recipe = slapos.recipe.build:download

[template-balancer-patched]
<= template-fluentd
base = ${template-balancer-base:target}
tags =
  {%- set port, backend_list = haproxy_dict['fluentd'] %}
  {%- for i in range(100*len(backend_list)) %}
  {%-   do tags.__setitem__('wendelin_tag_' ~ i, ipv4 ~ ':' ~ port) %}
  {%- endfor %}

[feeder]
feeder =
  #
    import collections, random, struct
    pack = struct.Struct('!d').pack
    data = collections.deque(
      ''.join(chr(int(random.gauss(0, .68)) % 256) for _ in xrange(2500))
      # With a period greater than 64kiB (zlib dictionary size),
      # we avoid extra compression due to repetition.
      for _ in xrange(30))
    interval = 60 # XXX: same as fluentd flush internal
    time.sleep(interval * random.random())
    while True:
      emit('', pack(time.time()) + data[0])
      data.rotate()
      time.sleep(interval)
