kubernetes-ingress icon indicating copy to clipboard operation
kubernetes-ingress copied to clipboard

Make access_log in http context configurable

Open hafe opened this issue 1 year ago • 3 comments
trafficstars

Closes #5625

Proposed changes

See https://github.com/nginxinc/kubernetes-ingress/issues/5625

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • [X] I have read the CONTRIBUTING doc
  • [X] I have added tests that prove my fix is effective or that my feature works
  • [X] I have checked that all unit tests pass after adding my changes
  • [X] I have updated necessary documentation
  • [X] I have rebased my branch onto main
  • [X] I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

hafe avatar May 29 '24 15:05 hafe

Deploy request for nginx-kubernetes-ingress pending review.

Visit the deploys page to approve it

Name Link
Latest commit 8de4bf3022281a4354ccb2688b2053b9f340d441

netlify[bot] avatar May 29 '24 15:05 netlify[bot]

Hi @hafe , could you please update the conflicting files?

jjngx avatar Jun 17 '24 15:06 jjngx

@hafe , could you please gofumpt files that are failing validation

jjngx avatar Jun 21 '24 12:06 jjngx

Thanks for the pr @hafe, @vepatel is looking at this pr now.

j1m-ryan avatar Jul 29 '24 15:07 j1m-ryan

@hafe could you please update the branch? I am reviewing changes atm.

jjngx avatar Aug 08 '24 08:08 jjngx

@hafe could you please update the branch? I am reviewing changes atm.

You mean just rebase it from main?

hafe avatar Aug 08 '24 09:08 hafe

@hafe could you please update the branch? I am reviewing changes atm.

You mean just rebase it from main?

Yes, please rebase.

jjngx avatar Aug 08 '24 10:08 jjngx

@hafe thank you again for contributing. I've tested the feature and confirm it works as expected.

input data:

kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
  namespace: nginx-ingress
data:
  access-log: "yslog:server=localhost:514"
  access-log-off: "false"

will results with: access_log /dev/stdout main;

kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
  namespace: nginx-ingress
data:
  access-log: "syslog:server=localhost:514"
  access-log-off: "false"

will results with: access_log syslog:server=localhost:514;

kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
  namespace: nginx-ingress
data:
  access-log: "syslog:server=localhost:514"
  access-log-off: "true"

will result with: access_log off;

If a user tries to set a value that is not valid, the log will be set to default one. NIC logs will show the error:

E20240809 10:59:06.679467       1 configmaps.go:212] Configmap nginx-ingress/nginx-config: Invalid value for key access-log: "ssyslog:server=localhost:514"

@hafe since the NIC does not handle warnings in case of invalid access_log value, could you please add information to the error log to inform user that the access_log value will be set to default (/dev/stdout main)?

Handling the error event will likely be a separate PR.

cc / @vepatel @shaun-nx

jjngx avatar Aug 09 '24 11:08 jjngx

I can do that. It should really be a warning log also

hafe avatar Aug 09 '24 11:08 hafe

@jjngx @hafe lets add it to the docs as well for clarity and since we can't report it through configmap event:

access_log value will be set to /dev/stdout main in-case user tries to configure it with location other than a syslog.

vepatel avatar Aug 09 '24 11:08 vepatel

@hafe could you please also update template tests?

jjngx avatar Aug 09 '24 12:08 jjngx

Not sure what you mean by that

hafe avatar Aug 09 '24 12:08 hafe

Not sure what you mean by that

could you run make test from the root dir of the project and check if the internal/configs/version1/__snapshots__/template_test.snap changes? When you look in the file there are new lines: access_log ; that indicates invalid (from NGINX perspective) lines.

jjngx avatar Aug 09 '24 12:08 jjngx

No nothing changes.

hafe avatar Aug 09 '24 13:08 hafe

No nothing changes.

Ok, I will check what is going on with the templates and snapshots, and get back to you ASAP.

jjngx avatar Aug 09 '24 14:08 jjngx

No nothing changes.

Ok, I will check what is going on with the templates and snapshots, and get back to you ASAP.

@hafe there is a missing filed AccessLog in multiple input data (config structs) in the template_test.go file in pkg internal/configs/version1. Please note that after the access_log change the MainConfig struct requires the AccessLog value to be defined, for example: AccessLog: "/dev/stdout main", as you added on line 2041. You need to update all structs (MainConfig) that are used as input test data for all template tests. After that please run make test and check if the test template is updated.

After that please update the branch. Once again thank you for contributing! I am hoping to get your PR merged next week.

jjngx avatar Aug 09 '24 15:08 jjngx

Seems to be OK now after latest updates. Thanks for the help!

hafe avatar Aug 09 '24 15:08 hafe