Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto logging of goroutine pid label #19212

Merged
merged 6 commits into from
Mar 26, 2022

Conversation

zeripath
Copy link
Contributor

This PR uses unsafe to export the hidden runtime_getProfLabel function from the
runtime package and then casts the result to a map[string]string.

We can then interrogate this map to get the pid label from the goroutine allowing
us to log it with any logging request.

Reference #19202

Signed-off-by: Andrew Thornton art27@cantab.net

@zeripath zeripath added the type/enhancement An improvement of existing functionality label Mar 25, 2022
This PR uses unsafe to export the hidden runtime_getProfLabel function from the
runtime package and then casts the result to a map[string]string.

We can then interrogate this map to get the pid label from the goroutine allowing
us to log it with any logging request.

Reference go-gitea#19202

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath force-pushed the logging-goroutine-pid-label branch from e1fed29 to b819116 Compare March 25, 2022 19:32
Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

This one may be quite controversial and I've put it up as an example of something that we might want to consider doing.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 25, 2022
modules/log/groutinelabel.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 26, 2022
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 26, 2022
zeripath and others added 4 commits March 26, 2022 10:06
@lunny
Copy link
Member

lunny commented Mar 26, 2022

make L-G-T-M work.

@zeripath zeripath merged commit 70628bd into go-gitea:main Mar 26, 2022
@zeripath zeripath deleted the logging-goroutine-pid-label branch March 26, 2022 20:04
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
* Add auto logging of goroutine pid label

This PR uses unsafe to export the hidden runtime_getProfLabel function from the
runtime package and then casts the result to a map[string]string.

We can then interrogate this map to get the pid label from the goroutine allowing
us to log it with any logging request.

Reference go-gitea#19202

Signed-off-by: Andrew Thornton <art27@cantab.net>
@wxiaoguang wxiaoguang added this to the 1.17.0 milestone Mar 29, 2022
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants