Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

[nginx-ingress-controller]: Add support for conditional log of urls #1239

Merged
merged 1 commit into from
Jun 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ingress/controllers/nginx/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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.
Expand Down
6 changes: 6 additions & 0 deletions ingress/controllers/nginx/nginx/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion ingress/controllers/nginx/nginx/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -135,6 +142,7 @@ func (ngx *Manager) ReadConfig(conf *api.ConfigMap) config.Configuration {
}

cfgDefault.CustomHTTPErrors = ngx.filterErrors(cErrors)
cfgDefault.SkipAccessLogURLs = cSkipUrls
return cfgDefault
}

Expand Down