From 1398044179d05adca09d1d5fa861772a7ad022b5 Mon Sep 17 00:00:00 2001 From: Joao Morais Date: Mon, 23 Sep 2019 21:47:18 -0300 Subject: [PATCH] Add syslog-length configmap option --- README.md | 8 +++ pkg/converters/ingress/annotations/global.go | 1 + pkg/converters/ingress/defaults.go | 1 + pkg/converters/ingress/types/global.go | 1 + pkg/haproxy/instance_test.go | 60 ++++++++++++++++++++ pkg/haproxy/types/types.go | 1 + rootfs/etc/haproxy/template/haproxy.tmpl | 2 +- 7 files changed, 73 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 12b41fc17..7807c7597 100644 --- a/README.md +++ b/README.md @@ -481,6 +481,7 @@ The following parameters are supported: ||[`strict-host`](#strict-host)|[true\|false]|`true`| ||[`syslog-endpoint`](#syslog-endpoint)|IP:port (udp)|do not log| |`[0]`|[`syslog-format`](#syslog-format)|rfc5424\|rfc3164|rfc5424| +|`[1]`|[`syslog-length`](#syslog-length)|max length of log line|`1024`| |`[0]`|[`syslog-tag`](#syslog-tag)|syslog tag field string|`ingress`| ||[`tcp-log-format`](#log-format)|tcp log format|HAProxy default log format| ||[`timeout-client`](#timeout)|time with suffix|`50s`| @@ -961,6 +962,13 @@ Configure the UDP syslog endpoint where HAProxy should send access logs. Configure the log format to be either rfc5424 ( default ) or rfc3164 +### syslog-length + +Configure the maximum length of the log line. Defaults to `1024` if not declared. +Log lines larger than this will be truncated before sent. + +http://cbonte.github.io/haproxy-dconv/1.9/configuration.html#3.1-log + ### syslog-tag Configure the tag field in the syslog header to the supplied string. diff --git a/pkg/converters/ingress/annotations/global.go b/pkg/converters/ingress/annotations/global.go index c70bb0ec2..b265a59e7 100644 --- a/pkg/converters/ingress/annotations/global.go +++ b/pkg/converters/ingress/annotations/global.go @@ -111,6 +111,7 @@ func (c *updater) buildGlobalSyslog(d *globalData) { d.global.Syslog.Format = d.mapper.Get(ingtypes.GlobalSyslogFormat).Value d.global.Syslog.HTTPLogFormat = d.mapper.Get(ingtypes.GlobalHTTPLogFormat).Value d.global.Syslog.HTTPSLogFormat = d.mapper.Get(ingtypes.GlobalHTTPSLogFormat).Value + d.global.Syslog.Length = d.mapper.Get(ingtypes.GlobalSyslogLength).Int() d.global.Syslog.Tag = d.mapper.Get(ingtypes.GlobalSyslogTag).Value d.global.Syslog.TCPLogFormat = d.mapper.Get(ingtypes.GlobalTCPLogFormat).Value } diff --git a/pkg/converters/ingress/defaults.go b/pkg/converters/ingress/defaults.go index 4c8941bf3..e19fc51ea 100644 --- a/pkg/converters/ingress/defaults.go +++ b/pkg/converters/ingress/defaults.go @@ -79,6 +79,7 @@ func createDefaults() map[string]string { types.GlobalSSLOptions: "no-sslv3 no-tls-tickets", types.GlobalStatsPort: "1936", types.GlobalSyslogFormat: "rfc5424", + types.GlobalSyslogLength: "1024", types.GlobalSyslogTag: "ingress", types.GlobalTimeoutStop: "10m", types.GlobalTLSALPN: "h2,http/1.1", diff --git a/pkg/converters/ingress/types/global.go b/pkg/converters/ingress/types/global.go index c8496dcc9..256c8189d 100644 --- a/pkg/converters/ingress/types/global.go +++ b/pkg/converters/ingress/types/global.go @@ -65,6 +65,7 @@ const ( GlobalStrictHost = "strict-host" GlobalSyslogEndpoint = "syslog-endpoint" GlobalSyslogFormat = "syslog-format" + GlobalSyslogLength = "syslog-length" GlobalSyslogTag = "syslog-tag" GlobalTCPLogFormat = "tcp-log-format" GlobalTimeoutStop = "timeout-stop" diff --git a/pkg/haproxy/instance_test.go b/pkg/haproxy/instance_test.go index 742df5cf4..b55542590 100644 --- a/pkg/haproxy/instance_test.go +++ b/pkg/haproxy/instance_test.go @@ -1760,6 +1760,66 @@ d1.local/ 1048576 c.logger.CompareLogging(defaultLogging) } +func TestInstanceSyslog(t *testing.T) { + c := setup(t) + defer c.teardown() + + var h *hatypes.Host + var b *hatypes.Backend + + b = c.config.AcquireBackend("d1", "app", "8080") + b.Endpoints = []*hatypes.Endpoint{endpointS1} + h = c.config.AcquireHost("d1.local") + h.AddPath(b, "/") + + syslog := &c.config.Global().Syslog + syslog.Endpoint = "127.0.0.1:1514" + syslog.Format = "rfc3164" + syslog.Length = 2048 + syslog.Tag = "ingress" + + c.Update() + c.checkConfig(` +global + daemon + stats socket /var/run/haproxy.sock level admin expose-fd listeners + maxconn 2000 + hard-stop-after 15m + log 127.0.0.1:1514 len 2048 format rfc3164 local0 + log-tag ingress + lua-load /usr/local/etc/haproxy/lua/send-response.lua + lua-load /usr/local/etc/haproxy/lua/auth-request.lua + ssl-dh-param-file /var/haproxy/tls/dhparam.pem + ssl-default-bind-ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256 + ssl-default-bind-options no-sslv3 +<> +backend d1_app_8080 + mode http + server s1 172.17.0.11:8080 weight 100 +<> +frontend _front_http + mode http + bind :80 + option httplog + http-request set-var(req.base) base,regsub(:[0-9]+/,/) + http-request redirect scheme https if { var(req.base),map_beg(/etc/haproxy/maps/_global_https_redir.map,_nomatch) yes } + <> + http-request set-var(req.backend) var(req.base),map_beg(/etc/haproxy/maps/_global_http_front.map,_nomatch) + use_backend %[var(req.backend)] unless { var(req.backend) _nomatch } + default_backend _error404 +frontend _front001 + mode http + bind :443 ssl alpn h2,http/1.1 crt-list /etc/haproxy/maps/_front001_bind_crt.list ca-ignore-err all crt-ignore-err all + option httplog + http-request set-var(req.hostbackend) base,lower,regsub(:[0-9]+/,/),map_beg(/etc/haproxy/maps/_front001_host.map,_nomatch) + <> + use_backend %[var(req.hostbackend)] unless { var(req.hostbackend) _nomatch } + default_backend _error404 +<> +`) + c.logger.CompareLogging(defaultLogging) +} + func TestDNS(t *testing.T) { c := setup(t) defer c.teardown() diff --git a/pkg/haproxy/types/types.go b/pkg/haproxy/types/types.go index 5f77778db..9c0d338b2 100644 --- a/pkg/haproxy/types/types.go +++ b/pkg/haproxy/types/types.go @@ -70,6 +70,7 @@ type SyslogConfig struct { Format string HTTPLogFormat string HTTPSLogFormat string + Length int Tag string TCPLogFormat string } diff --git a/rootfs/etc/haproxy/template/haproxy.tmpl b/rootfs/etc/haproxy/template/haproxy.tmpl index 0a0d8f651..5c6c1d6f4 100644 --- a/rootfs/etc/haproxy/template/haproxy.tmpl +++ b/rootfs/etc/haproxy/template/haproxy.tmpl @@ -30,7 +30,7 @@ global hard-stop-after {{ $global.Timeout.Stop }} {{- end }} {{- if $global.Syslog.Endpoint }} - log {{ $global.Syslog.Endpoint }} format {{ $global.Syslog.Format }} local0 + log {{ $global.Syslog.Endpoint }} len {{ $global.Syslog.Length }} format {{ $global.Syslog.Format }} local0 log-tag {{ $global.Syslog.Tag }} {{- end }} lua-load /usr/local/etc/haproxy/lua/send-response.lua