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

[Ingress] Service/Upstream name in the log #1750

Closed
edouardKaiser opened this issue Sep 18, 2016 · 3 comments · Fixed by #1751
Closed

[Ingress] Service/Upstream name in the log #1750

edouardKaiser opened this issue Sep 18, 2016 · 3 comments · Fixed by #1751

Comments

@edouardKaiser
Copy link

Is there a way to get the service (or upstream) name logged in the NGINX log_format ?

We are trying to export the NGINX logs into Elasticsearch, but we are only interested by the logs of particular applications. Right now, it's all mixed, there's no way to differentiate which pod/service is targeted. Sure, the targeted upstream address gets logged, but that does not help to process the log.

@aledbf
Copy link
Contributor

aledbf commented Sep 18, 2016

@edouardKaiser no because nginx does not provide a variable with that information.
Please use a custom template with this changes:

diff --git a/ingress/controllers/nginx/nginx.tmpl b/ingress/controllers/nginx/nginx.tmpl
index f88d559..ccedb7d 100644
--- a/ingress/controllers/nginx/nginx.tmpl
+++ b/ingress/controllers/nginx/nginx.tmpl
@@ -75,7 +75,7 @@ http {

     log_format upstreaminfo '{{ if $cfg.useProxyProtocol }}$proxy_protocol_addr{{ else }}$remote_addr{{ end }} - '
         '[$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';
+        '$request_length $request_time [$proxy_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status';

     {{/* map urls that should not appear in access.log */}}
     {{/* http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log */}}
@@ -262,6 +262,7 @@ http {
             {{- end }}

             {{- buildProxyPass $location }}
+            set $proxy_upstream_name "{{ $location.Upstream.Name }}";
         }
         {{ end }}

@edouardKaiser
Copy link
Author

Works like a charm, thanks. I'm surprised no one was missing that information in the logs.

@aledbf
Copy link
Contributor

aledbf commented Sep 19, 2016

@edouardKaiser awesome. This change will be included in the next release.

k8s-github-robot pushed a commit that referenced this issue Sep 19, 2016
Automatic merge from submit-queue

[nginx-ingress-controller] Add the name of the upstream in the log

fixes #1750
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants