Skip to content

Conversation

navinms711
Copy link
Contributor

@navinms711 navinms711 commented Jun 20, 2025

Summary

[1] Briefly explain why this PR is necessary

Gorouter uses slog with zap handler as backend for current logging levels. The Gorouter runs a debugserver (a http server) which listens to a few API endpoints. The /log-level -d <debug/info/error/fatal> was introduced to make changes to the log level on demand at runtime. However, a POST request to the log-level endpoint has no effect in the current code. This PR proposes changes needed to make log level change work through a POST request.

[2] Provide details of where this request is coming from including links, GitHub Issues, etc..

This is a request from Broadcom Engineering team to fix it and recorded in TNZ-23119.

[3] Provide details of prior work (if applicable) including links to commits, github issues, etc...

cloudfoundry/gorouter#452

[4] Backward Compatibility

Breaking Change? NO

[5] If this is a breaking change, or modifies currently expected behaviors of core functionality.

[6] Are there any other dependent PRs?

Yes, this PR needs the latest changes to debugserver code in cloudfoundry/debugserver#73

@navinms711 navinms711 requested a review from a team as a code owner June 20, 2025 08:15
Copy link

linux-foundation-easycla bot commented Jun 20, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@navinms711
Copy link
Contributor Author

Following log entries are seen in the /var/vcap/sys/log/gorouter/gorouter.stdout.log for various inputs on the Router VM.

$ curl http://127.0.0.1:17002/log-level -d info
✅ /log-level was invoked with Level: info

time=2025-06-20T07:46:21.091Z level=INFO msg="Gorouter logger -> zapcore log level updated." new-level=info

$ curl http://127.0.0.1:17002/log-level -d debug
✅ /log-level was invoked with Level: debug

time=2025-06-20T07:46:21.091Z level=INFO msg="Gorouter logger -> zapcore log level updated." new-level=debug

$ curl -X GET http://127.0.0.1:17002/log-level -d info
method not allowed, use POST

$ curl -X PUT http://127.0.0.1:17002/log-level -d info
method not allowed, use POST

$ curl -X POST https://127.0.0.1:17002/log-level -d info
curl: (35) error:0A00010B:SSL routines::wrong version number

$ curl -X POST http://127.0.0.1:17002/log-level -d {}
Invalid log level provided: {}

$ curl -X POST http://127.0.0.1:17002/log-level
log level cannot be empty

@hoffmaen
Copy link
Contributor

Hello @navinms711 ,
Please do not pollute main.go with code to setup the sink for debugserver.
With cloudfoundry/gorouter#435, we have put a lot of effort to the code base to have a clean and simple abstraction of the zap handler, and we use slog throughout the code as the logging frontend. We have functions to dynamically set the WriteSyncer, which allows to setup a custom sink and to dynamically set the log level (used e.g. in the tests).
Please use the provided library and, if missing, put the code required to run the debugserver into a separate go file.

@hoffmaen
Copy link
Contributor

One more thought: Instead of adding all that code to routing-release, couldn't you make the debugserver handle an slog logger instead of a lager logger?

@navinms711 navinms711 force-pushed the bugfix/debugserver-loglevel branch from ceef6d7 to d66a05d Compare July 3, 2025 09:51
@navinms711
Copy link
Contributor Author

navinms711 commented Jul 3, 2025

One more thought: Instead of adding all that code to routing-release, couldn't you make the debugserver handle an slog logger instead of a lager logger?

I looked into this. To change the debugserver support slog instead of lager requires changing the SetMinLevel(level lager.LogLevel) signature and this breaks existing code in tcp-router, loggregator, etc. and the corresponding acceptance/integration tests needs re-written. All of this means much more changes in multiple repos. Hence decided to keep debugserver use lager logger and introduce adapter code (adapter.go) to handle log-level changes.

@navinms711
Copy link
Contributor Author

Hello @navinms711 , Please do not pollute main.go with code to setup the sink for debugserver. With cloudfoundry/gorouter#435, we have put a lot of effort to the code base to have a clean and simple abstraction of the zap handler, and we use slog throughout the code as the logging frontend. We have functions to dynamically set the WriteSyncer, which allows to setup a custom sink and to dynamically set the log level (used e.g. in the tests). Please use the provided library and, if missing, put the code required to run the debugserver into a separate go file.

I have moved most changes from main.go to adapter.go in the same main package, to keep changes to main.go to a minimum. The necessary integration tests are in main_test.go and it tests the full path from debugserver lager sink to zapcore config level. The following note will help understand the flow.

	// http://<>:<>/log-level -d {0, debug, DEBUG, d}
	// 		calls zapCtrl.SetMinLevel(lagerLogLevel) -> 0
	//		calls conf.level.SetLevel(zapcore.DebugLevel)
	// http://<>:<>/log-level -d {1, info, INFO, I}
	// 		calls zapCtrl.SetMinLevel(lagerLogLevel) -> 1
	//		calls conf.level.SetLevel(zapcore.InfoLevel)
	// http://<>:<>/log-level -d {2, warn, WARN, w}
	//		calls conf.level.SetLevel(zapcore.WarnLevel)
	// http://<>:<>/log-level -d {3, error, ERROR, e}
	// 		calls zapCtrl.SetMinLevel(lagerLogLevel) -> 2
	//		calls conf.level.SetLevel(zapcore.ErrorLevel)
	// http://<>:<>/log-level -d {4, fatal, FATAL, f}
	// 		calls zapCtrl.SetMinLevel(lagerLogLevel) -> 3
	//		calls conf.level.SetLevel(zapcore.FatalLevel)

All tests have passed.

Ran 189 of 189 Specs in 2100.664 seconds
SUCCESS! -- 189 Passed | 0 Failed | 1 Flaked | 0 Pending | 0 Skipped
PASS

@navinms711 navinms711 force-pushed the bugfix/debugserver-loglevel branch 2 times, most recently from bb0cbd0 to 07a996b Compare July 11, 2025 22:34
g	modified:   src/code.cloudfoundry.org/gorouter/test_util/helpers.go
@navinms711 navinms711 force-pushed the bugfix/debugserver-loglevel branch from 07a996b to 08feac8 Compare July 11, 2025 22:39
@navinms711 navinms711 requested a review from ameowlia July 14, 2025 18:00
@navinms711 navinms711 force-pushed the bugfix/debugserver-loglevel branch from 377f8e7 to 98d111a Compare July 15, 2025 02:15
@navinms711 navinms711 force-pushed the bugfix/debugserver-loglevel branch from 41b2d4c to 1813b8b Compare July 15, 2025 02:20
@github-project-automation github-project-automation bot moved this from Inbox to Pending Merge | Prioritized in Application Runtime Platform Working Group Jul 16, 2025
@ameowlia ameowlia merged commit 6249fba into cloudfoundry:develop Jul 16, 2025
17 of 25 checks passed
@github-project-automation github-project-automation bot moved this from Pending Merge | Prioritized to Done in Application Runtime Platform Working Group Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

4 participants