Skip to content

Commit

Permalink
Merge pull request #396 from jcmoraisjr/jm-syslog-length
Browse files Browse the repository at this point in the history
Add syslog-length configmap option
  • Loading branch information
jcmoraisjr authored Sep 27, 2019
2 parents 6348c11 + 1398044 commit e2c5370
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`|
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/converters/ingress/annotations/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/converters/ingress/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions pkg/converters/ingress/types/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
60 changes: 60 additions & 0 deletions pkg/haproxy/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,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
<<defaults>>
backend d1_app_8080
mode http
server s1 172.17.0.11:8080 weight 100
<<backends-default>>
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-headers>>
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)
<<https-headers>>
use_backend %[var(req.hostbackend)] unless { var(req.hostbackend) _nomatch }
default_backend _error404
<<support>>
`)
c.logger.CompareLogging(defaultLogging)
}

func TestDNS(t *testing.T) {
c := setup(t)
defer c.teardown()
Expand Down
1 change: 1 addition & 0 deletions pkg/haproxy/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type SyslogConfig struct {
Format string
HTTPLogFormat string
HTTPSLogFormat string
Length int
Tag string
TCPLogFormat string
}
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/haproxy/template/haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e2c5370

Please sign in to comment.