Merge pull request #1239 from aledbf/conditional-log
[nginx-ingress-controller]: Add support for conditional log of urls
This commit is contained in:
commit
b728a0cbd5
3 changed files with 24 additions and 2 deletions
|
@ -76,7 +76,15 @@ http {
|
|||
'[$proxy_add_x_forwarded_for] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" '
|
||||
'$request_length $request_time $upstream_addr $upstream_response_length $upstream_response_time $upstream_status';
|
||||
|
||||
access_log /var/log/nginx/access.log upstreaminfo;
|
||||
{{/* map urls that should not appear in access.log */}}
|
||||
{{/* http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log */}}
|
||||
map $request $loggable {
|
||||
{{- range $reqUri := $cfg.skipAccessLogUrls }}
|
||||
{{ $reqUri }} 0;{{ end }}
|
||||
default 1;
|
||||
}
|
||||
|
||||
access_log /var/log/nginx/access.log upstreaminfo if=$loggable;
|
||||
error_log /var/log/nginx/error.log {{ $cfg.errorLogLevel }};
|
||||
|
||||
{{ if not (empty .defResolver) }}# Custom dns resolver.
|
||||
|
|
|
@ -162,6 +162,11 @@ type Configuration struct {
|
|||
// http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_bucket_size
|
||||
ServerNameHashBucketSize int `structs:"server-name-hash-bucket-size,omitempty"`
|
||||
|
||||
// SkipAccessLogURLs sets a list of URLs that should not appear in the NGINX access log
|
||||
// This is useful with urls like `/health` or `health-check` that make "complex" reading the logs
|
||||
// By default this list is empty
|
||||
SkipAccessLogURLs []string `structs:"skip-access-log-urls,-"`
|
||||
|
||||
// Enables or disables the redirect (301) to the HTTPS port
|
||||
SSLRedirect bool `structs:"ssl-redirect,omitempty"`
|
||||
|
||||
|
@ -275,6 +280,7 @@ func NewDefault() Configuration {
|
|||
UseHTTP2: true,
|
||||
CustomHTTPErrors: make([]int, 0),
|
||||
WhitelistSourceRange: make([]string, 0),
|
||||
SkipAccessLogURLs: make([]string, 0),
|
||||
}
|
||||
|
||||
if glog.V(5) {
|
||||
|
|
|
@ -33,7 +33,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
customHTTPErrors = "custom-http-errors"
|
||||
customHTTPErrors = "custom-http-errors"
|
||||
skipAccessLogUrls = "skip-access-log-urls"
|
||||
)
|
||||
|
||||
// getDNSServers returns the list of nameservers located in the file /etc/resolv.conf
|
||||
|
@ -110,6 +111,12 @@ func (ngx *Manager) ReadConfig(conf *api.ConfigMap) config.Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
cSkipUrls := make([]string, 0)
|
||||
if val, ok := conf.Data[skipAccessLogUrls]; ok {
|
||||
delete(conf.Data, skipAccessLogUrls)
|
||||
cSkipUrls = strings.Split(val, ",")
|
||||
}
|
||||
|
||||
err = decoder.Decode(conf.Data)
|
||||
if err != nil {
|
||||
glog.Infof("%v", err)
|
||||
|
@ -135,6 +142,7 @@ func (ngx *Manager) ReadConfig(conf *api.ConfigMap) config.Configuration {
|
|||
}
|
||||
|
||||
cfgDefault.CustomHTTPErrors = ngx.filterErrors(cErrors)
|
||||
cfgDefault.SkipAccessLogURLs = cSkipUrls
|
||||
return cfgDefault
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue