Skip to content

Commit

Permalink
Fix log format after kubernetes#4557
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Sep 18, 2019
1 parent c481296 commit 4b4176c
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 70 deletions.
2 changes: 1 addition & 1 deletion docs/user-guide/nginx-configuration/configmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The following table shows a configuration option's name, type, and the default v
|[keep-alive-requests](#keep-alive-requests)|int|100|
|[large-client-header-buffers](#large-client-header-buffers)|string|"4 8k"|
|[log-format-escape-json](#log-format-escape-json)|bool|"false"|
|[log-format-upstream](#log-format-upstream)|string|`$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$proxy_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id`|
|[log-format-upstream](#log-format-upstream)|string|`$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$proxy_upstream_name] [$proxy_alternative_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id`|
|[log-format-stream](#log-format-stream)|string|`[$time_local] $protocol $status $bytes_sent $bytes_received $session_time`|
|[enable-multi-accept](#enable-multi-accept)|bool|"true"|
|[max-worker-connections](#max-worker-connections)|int|16384|
Expand Down
3 changes: 1 addition & 2 deletions docs/user-guide/nginx-configuration/custom-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The NGINX template is located in the file `/etc/nginx/template/nginx.tmpl`.

Using a [Volume](https://kubernetes.io/docs/concepts/storage/volumes/) it is possible to use a custom template.
Using a [Volume](https://kubernetes.io/docs/concepts/storage/volumes/) it is possible to use a custom template.
This includes using a [Configmap](https://kubernetes.io/docs/concepts/storage/volumes/#example-pod-with-a-secret-a-downward-api-and-a-configmap) as source of the template

```yaml
Expand Down Expand Up @@ -40,7 +40,6 @@ TODO:
- buildAuthLocation:
- buildAuthResponseHeaders:
- buildResolvers:
- buildLogFormatUpstream:
- buildDenyVariable:
- buildUpstreamName:
- buildForwardedFor:
Expand Down
12 changes: 0 additions & 12 deletions internal/ingress/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package config

import (
"fmt"
"strconv"
"time"

Expand Down Expand Up @@ -779,17 +778,6 @@ func NewDefault() Configuration {
return cfg
}

// BuildLogFormatUpstream format the log_format upstream using
// proxy_protocol_addr as remote client address if UseProxyProtocol
// is enabled.
func (cfg Configuration) BuildLogFormatUpstream() string {
if cfg.LogFormatUpstream == logFormatUpstream {
return fmt.Sprintf(cfg.LogFormatUpstream, "$remote_addr")
}

return cfg.LogFormatUpstream
}

// TemplateConfig contains the nginx configuration to render the file nginx.conf
type TemplateConfig struct {
ProxySetHeaders map[string]string
Expand Down
43 changes: 0 additions & 43 deletions internal/ingress/controller/config/config_test.go

This file was deleted.

11 changes: 0 additions & 11 deletions internal/ingress/controller/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ var (
"buildUpstreamName": buildUpstreamName,
"isLocationInLocationList": isLocationInLocationList,
"isLocationAllowed": isLocationAllowed,
"buildLogFormatUpstream": buildLogFormatUpstream,
"buildDenyVariable": buildDenyVariable,
"getenv": os.Getenv,
"contains": strings.Contains,
Expand Down Expand Up @@ -462,16 +461,6 @@ func buildAuthResponseHeaders(headers []string) []string {
return res
}

func buildLogFormatUpstream(input interface{}) string {
cfg, ok := input.(config.Configuration)
if !ok {
klog.Errorf("expected a 'config.Configuration' type but %T was returned", input)
return ""
}

return cfg.BuildLogFormatUpstream()
}

// buildProxyPass produces the proxy pass string, if the ingress has redirects
// (specified through the nginx.ingress.kubernetes.io/rewrite-target annotation)
// If the annotation nginx.ingress.kubernetes.io/add-base-url:"true" is specified it will
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ http {
# $ingress_name
# $service_name
# $service_port
log_format upstreaminfo {{ if $cfg.LogFormatEscapeJSON }}escape=json {{ end }}'{{ buildLogFormatUpstream $cfg }}';
log_format upstreaminfo {{ if $cfg.LogFormatEscapeJSON }}escape=json {{ end }}'{{ $cfg.LogFormatUpstream }}';

{{/* map urls that should not appear in access.log */}}
{{/* http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log */}}
Expand Down

0 comments on commit 4b4176c

Please sign in to comment.