Skip to content

network-load-balancer: add support for failover#5562

Merged
HofiOne merged 6 commits intosyslog-ng:developfrom
egglessness:feature/enhanced-lb-confgen-script
Nov 12, 2025
Merged

network-load-balancer: add support for failover#5562
HofiOne merged 6 commits intosyslog-ng:developfrom
egglessness:feature/enhanced-lb-confgen-script

Conversation

@egglessness
Copy link
Contributor

@egglessness egglessness commented Nov 8, 2025

Fixes: #1210

The confgen script for network-load-balancer now supports failover, generating the list of failover servers for each destination automatically.

Although this feature has been initially implemented in #1706, it was left commented (#1706 (comment)) since at that time failover support was available only in PE6.
Instead of just commenting it out, I decided to rewrite the script to implement the following enhancements:

  • Use the new failover(servers()) syntax, instead of the deprecated failover-servers() block
  • Use R_USEC instead of R_MSEC to distribute incoming messages more evenly
  • Enhanced code readibility and portability (POSIX-compliant)

On top of that, the script tries to be as flexible as possible:

  • The parser for the targets list is now more forgiving (it supports unquoted, quoted, and comma-separated entries)
  • Failover is enabled by default, but it can be disabled with failover(off) or failover(no)
  • Failover options can be specified as well (e.g., failback())
  • It is possible to specify a specific list of targets for failover, instead of the one generated automatically

I also added some tests to ensure this confgen script keeps up with upcoming features in the next releases. :)

Usage example

The following snippet:

@include "scl.conf"

destination d_remote {
  network-load-balancer(
    targets("node1", "node2", "node3")
    failover(failback(tcp-probe-interval(5) successful-probes-required(1)))
    transport(tcp) port(5140)
  );
};

... gets rendered as follows:

destination d_remote {
    channel {
        channel {
            filter {
                "0" == "$(% ${R_USEC} 3)"
            };
            destination {
                network("node1"
                    failover(servers("node2", "node3") failback(tcp-probe-interval(5) successful-probes-required(1)))
                    transport(tcp) port(5140)
                );
            };
            flags(final);
        };
    
        channel {
            filter {
                "1" == "$(% ${R_USEC} 3)"
            };
            destination {
                network("node2"
                    failover(servers("node1", "node3") failback(tcp-probe-interval(5) successful-probes-required(1)))
                    transport(tcp) port(5140)
                );
            };
            flags(final);
        };
    
        channel {
            filter {
                "2" == "$(% ${R_USEC} 3)"
            };
            destination {
                network("node3"
                    failover(servers("node1", "node2") failback(tcp-probe-interval(5) successful-probes-required(1)))
                    transport(tcp) port(5140)
                );
            };
            flags(final);
        };
    };
};

The confgen script for `network-load-balancer` now supports failover, generating the list of failover servers for each destination automatically.

Signed-off-by: Daniele Ferla <[email protected]>
@kira-syslogng
Copy link
Contributor

Can one of the admins verify this patch?

1 similar comment
@kira-syslogng
Copy link
Contributor

Can one of the admins verify this patch?

@egglessness egglessness force-pushed the feature/enhanced-lb-confgen-script branch from 1feb080 to 8878dce Compare November 10, 2025 14:57
@egglessness egglessness force-pushed the feature/enhanced-lb-confgen-script branch from 8878dce to 09d43bc Compare November 10, 2025 18:02
@HofiOne
Copy link
Collaborator

HofiOne commented Nov 11, 2025

@egglessness I absolutely love this, thank you! Let me ask for one more tiny improvement.
Could you please add some tests comparing the generated config against the expected one — just a simple content comparison would be perfect?

@HofiOne HofiOne merged commit a19cb83 into syslog-ng:develop Nov 12, 2025
118 checks passed
@egglessness
Copy link
Contributor Author

Hi @HofiOne, thank you!
I think I can add more thorough tests the next weekend. I will open another PR, if it’s ok. :)

@HofiOne
Copy link
Collaborator

HofiOne commented Nov 13, 2025

Hi @HofiOne, thank you! I think I can add more thorough tests the next weekend. I will open another PR, if it’s ok. :)

Perfect, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: native network load balancing

3 participants