Hi all, Tim and I started to discuss a few functions worth supporting in the config for use with the new ".if" preprocessing macro. We need to think them well enough so that we don't need to change their meaning over time and that they allow more portable configs across versions.
I'm sure we'll be limited to something simple for 2.4 (we will probably not support expressions, just simple boolean functions). Among the things I started to think about, I had the following in mind: - defined(name) : true if this environment variable is set .if defined(HAP_NBTHREAD) nbthread HAP_NBTHREAD .elif defined(HAP_NBPROC) nbproc HAP_NBPROC .endif - keyword(name) : true if this config keyword is registered .if keyword(chroot) chroot /path/to .endif - service(name) : true if this service is registered .if service(prometheus-exporter) use-service prometheus-exporter if { path_beg /promex } .endif - action(name) : true if this action is registered .if action(silent-drop) tcp-request silent-drop if { src -f banned.acl } .endif - option(name) : true if this proxy option exists .if option(http-use-htx) option http-use-htx .endif - configured(name): true if this feature was configured at build time .if configured(LUA) lua-load hello.lua .endif - supported(name): true if this feature is supported at run time .if supported(SPLICE) tune.bufsize 16384 .else tune.bufsize 65536 .endif - version_atleast(): true if the haproxy version is at least this one .if version_atleast(2.4) tune.sched.low-latency on .endif - version_before(): the opposite of the above: .if version_before(2.0) option http-use-htx .endif - streq(a,b): compare two strings (should be careful, maybe it would be better to rethink about this for expressions later): .if streq(HAP_ENVIRONMENT,prod) chroot /path/to .else set-dumpable .endif or even for other tests: .if streq(HOSTNAME,node1) peer node1 1.1.1.1 local peer node2 1.1.1.2 .else peer node1 1.1.1.1 peer node2 1.1.1.2 local .endif I'm still not completely sold to these, because I'm suspecting that we need to differentiate what's supported in global/listen/bind/server parts for the "keyword" part. Maybe even other ones. I also thought that being able to check for some components' types and versions could be helpful (e.g. enable/disable certain features between openssl and boringssl). I also thought it could be useful to have a few special environment variable names like ${LINE} and ${FILE} to indicate where we're parsing. This could serve in .warning/.error as well as in logs sometimes. I'm purposely dumping this here as-is because I don't want to think too much about it without consulting those supposed to use them :-) So all ideas and criticisms welcome. Willy