Skip to content

Commit

Permalink
Merge pull request #5656 from agile6v/dev
Browse files Browse the repository at this point in the history
feat: add http-access-log-path and stream-access-log-path options in configMap
  • Loading branch information
k8s-ci-robot authored Jun 8, 2020
2 parents 4e4f447 + fc1c043 commit 99aad29
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 4 deletions.
18 changes: 17 additions & 1 deletion docs/user-guide/nginx-configuration/configmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The following table shows a configuration option's name, type, and the default v
|[hide-headers](#hide-headers)|string array|empty|
|[access-log-params](#access-log-params)|string|""|
|[access-log-path](#access-log-path)|string|"/var/log/nginx/access.log"|
|[http-access-log-path](#http-access-log-path)|string|""|
|[stream-access-log-path](#stream-access-log-path)|string|""|
|[enable-access-log-for-default-backend](#enable-access-log-for-default-backend)|bool|"false"|
|[error-log-path](#error-log-path)|string|"/var/log/nginx/error.log"|
|[enable-modsecurity](#enable-modsecurity)|bool|"false"|
Expand Down Expand Up @@ -207,10 +209,24 @@ _References:_

## access-log-path

Access log path. Goes to `/var/log/nginx/access.log` by default.
Access log path for both http and stream context. Goes to `/var/log/nginx/access.log` by default.

__Note:__ the file `/var/log/nginx/access.log` is a symlink to `/dev/stdout`

## http-access-log-path

Access log path for http context globally.
_**default:**_ ""

__Note:__ If not specified, the `access-log-path` will be used.

## stream-access-log-path

Access log path for stream context globally.
_**default:**_ ""

__Note:__ If not specified, the `access-log-path` will be used.

## enable-access-log-for-default-backend

Enables logging access to default backend. _**default:**_ is disabled.
Expand Down
11 changes: 10 additions & 1 deletion internal/ingress/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,20 @@ type Configuration struct {
// By default this is disabled
EnableAccessLogForDefaultBackend bool `json:"enable-access-log-for-default-backend"`

// AccessLogPath sets the path of the access logs if enabled
// AccessLogPath sets the path of the access logs for both http and stream contexts if enabled
// http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log
// http://nginx.org/en/docs/stream/ngx_stream_log_module.html#access_log
// By default access logs go to /var/log/nginx/access.log
AccessLogPath string `json:"access-log-path,omitempty"`

// HttpAccessLogPath sets the path of the access logs for http context globally if enabled
// http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log
HttpAccessLogPath string `json:"http-access-log-path,omitempty"`

// StreamAccessLogPath sets the path of the access logs for stream context globally if enabled
// http://nginx.org/en/docs/stream/ngx_stream_log_module.html#access_log
StreamAccessLogPath string `json:"stream-access-log-path,omitempty"`

// WorkerCPUAffinity bind nginx worker processes to CPUs this will improve response latency
// http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity
// By default this is disabled
Expand Down
4 changes: 2 additions & 2 deletions rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ http {
{{ if $cfg.EnableSyslog }}
access_log syslog:server={{ $cfg.SyslogHost }}:{{ $cfg.SyslogPort }} upstreaminfo if=$loggable;
{{ else }}
access_log {{ $cfg.AccessLogPath }} upstreaminfo {{ $cfg.AccessLogParams }} if=$loggable;
access_log {{ or $cfg.HttpAccessLogPath $cfg.AccessLogPath }} upstreaminfo {{ $cfg.AccessLogParams }} if=$loggable;
{{ end }}
{{ end }}

Expand Down Expand Up @@ -697,7 +697,7 @@ stream {
{{ if $cfg.DisableAccessLog }}
access_log off;
{{ else }}
access_log {{ $cfg.AccessLogPath }} log_stream {{ $cfg.AccessLogParams }};
access_log {{ or $cfg.StreamAccessLogPath $cfg.AccessLogPath }} log_stream {{ $cfg.AccessLogParams }};
{{ end }}

error_log {{ $cfg.ErrorLogPath }};
Expand Down
87 changes: 87 additions & 0 deletions test/e2e/settings/access_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package settings

import (
"strings"

"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)

var _ = framework.DescribeSetting("access-log", func() {
f := framework.NewDefaultFramework("access-log")

ginkgo.Context("access-log-path", func() {

ginkgo.It("use the default configuration", func() {
f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, "access_log /var/log/nginx/access.log upstreaminfo") &&
strings.Contains(cfg, "access_log /var/log/nginx/access.log log_stream")
})
})

ginkgo.It("use the specified configuration", func() {
f.UpdateNginxConfigMapData("access-log-path", "/tmp/access.log")
f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, "access_log /tmp/access.log upstreaminfo") &&
strings.Contains(cfg, "access_log /tmp/access.log log_stream")
})
})
})

ginkgo.Context("http-access-log-path", func() {

ginkgo.It("use the specified configuration", func() {
f.UpdateNginxConfigMapData("http-access-log-path", "/tmp/http-access.log")
f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, "access_log /tmp/http-access.log upstreaminfo") &&
strings.Contains(cfg, "access_log /var/log/nginx/access.log log_stream")
})
})
})

ginkgo.Context("stream-access-log-path", func() {

ginkgo.It("use the specified configuration", func() {
f.UpdateNginxConfigMapData("stream-access-log-path", "/tmp/stream-access.log")
f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, "access_log /tmp/stream-access.log log_stream") &&
strings.Contains(cfg, "access_log /var/log/nginx/access.log upstreaminfo")
})
})
})

ginkgo.Context("http-access-log-path & stream-access-log-path", func() {

ginkgo.It("use the specified configuration", func() {
f.SetNginxConfigMapData(map[string]string{
"http-access-log-path": "/tmp/http-access.log",
"stream-access-log-path": "/tmp/stream-access.log",
})
f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, "access_log /tmp/http-access.log upstreaminfo") &&
strings.Contains(cfg, "access_log /tmp/stream-access.log log_stream")
})
})
})
})

0 comments on commit 99aad29

Please sign in to comment.