by-builder example

11 views
Skip to first unread message

Fabien Wernli

unread,
Nov 9, 2023, 3:31:20 AM11/9/23
to Riemann Users
Hi,

I'm trying to understand how to use by-builder.
Could anyone share an example please ?

Thanks

Fabien Wernli

unread,
Nov 9, 2023, 3:42:44 AM11/9/23
to Riemann Users
Adding a little context : I want to build a stateful load-balancer to send to multiple riemann servers.
Here's what I came up with:

(defn forward-balanced-stateful
  "Forwards events to a pool of riemann tcp clients.
   The client is chosen using the event's fields, hence the stateful suffix."
  [clients fields]
  (let [get-relay-idx (fn [event] (mod (hash (select-keys event fields)) (count clients)))]
    (by-builder [idx get-relay-idx] (batch 100 10 (forward (get clients idx))))))


And here's how I'm using it in a stream:

(let [forward_balanced_safe-tcp_clients [(tcp-client :host "remote-riemann-1" :port 5555)(tcp-client :host "remote-riemann-2" :port 5555)]
  (streams (forward-balanced-stateful forward_balanced_safe-tcp_clients [:host :service])))))))

Does that seem correct to you?

ap...@aphyr.com

unread,
Nov 9, 2023, 7:00:37 AM11/9/23
to rieman...@googlegroups.com
There's an example in the docstring here: https://github.com/riemann/riemann/blob/0.3.10/src/riemann/streams.clj#L1593

Basically by-builder takes a binding form of [symbol by-field] and makes that symbol available in the remaining forms which construct the fork. I agree the docstring is not particularly clear! Took me reading the source to get what was going on.

--Kyle

--
You received this message because you are subscribed to the Google Groups "Riemann Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to riemann-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/riemann-users/fb09d2e5-8e3c-494f-9955-743bfc7a93fbn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages