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

Support dynamiclly set glog.logging.verbosity #63777

Merged

Conversation

hzxuzhonghu
Copy link
Member

@hzxuzhonghu hzxuzhonghu commented May 14, 2018

Support dynamically set glog logging level, which is convenient for debug.

Release note:

Expose `/debug/flags/v` to allow dynamically set glog logging level, if want to change glog level to 3, you only have to send a PUT request with like `curl -X PUT http://127.0.0.1:8080/debug/flags/v -d "3"`.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 14, 2018
@k8s-ci-robot k8s-ci-robot requested review from enj and sttts May 14, 2018 08:26
@hzxuzhonghu
Copy link
Member Author

/assign sttts


// Install registers the APIServer's `/loglevel` handler.
func (l DefaultLogLevel) Install(c *mux.PathRecorderMux) {
c.HandleFunc("/loglevel", func(w http.ResponseWriter, req *http.Request) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this protected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,

func (l *Level) Set(value string) error {
	v, err := strconv.Atoi(value)
	if err != nil {
		return err
	}
	logging.mu.Lock()
	defer logging.mu.Unlock()
	logging.setVState(Level(v), logging.vmodule.filter, false)
	return nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean via authn/z. This also needs a test checking that authn/z is applied.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is like /debug/pprof, protected by authn/z .

This also needs a test checking that authn/z is applied.

I have to look into it, never wrote this case before. But to make sure
this really acceptable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, add a case test auth

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hzxuzhonghu Can we please query the current level using HTTP GET too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dims Sorry, we cann't. because glog do not expose a method to query, if we want to do this , I think we can cache the level after first set. But we have no way to query without firstly set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack thanks @hzxuzhonghu

@sttts
Copy link
Contributor

sttts commented May 14, 2018

There were discussion to have a limited ComponentConfig for apiservers. I wonder whether this shouldn't go into a dynamic reconfiguration mechanism based on that.

@hzxuzhonghu
Copy link
Member Author

I wonder whether this shouldn't go into a dynamic reconfiguration mechanism based on that.

I met many cases, like in production env master exception. Developers want to improve the log level, but have no way.

@sttts
Copy link
Contributor

sttts commented May 14, 2018

I met many cases, like in production env master exception. Developers want to improve the log level, but have no way.

I agree. But then we have other values operators want to change on-the-fly: max-inflight requests for example.

@hzxuzhonghu
Copy link
Member Author

But then we have other values operators want to change on-the-fly: max-inflight requests for example

Yeah, maybe max-inflight is one flag we want to change. But mostly we want to improve log level is when we meet exception(may cause fatal), it is of higher priority. Many other languages or golang logging lib support dynamically changing level.

@hzxuzhonghu
Copy link
Member Author

fixed test failure

@hzxuzhonghu
Copy link
Member Author

/test pull-kubernetes-integration

@hzxuzhonghu
Copy link
Member Author

/test pull-kubernetes-e2e-gce

@dims
Copy link
Member

dims commented May 14, 2018

/uncc @dims

@sttts
Copy link
Contributor

sttts commented May 15, 2018

Reasonable usecase. I tend to be fine with this. But would like to hear some more opinions whether we want to add those special purpose endpoints.

/assign @deads2k

Does this also apply to the controller manager (and scheduler when the options PR merges) ?

@hzxuzhonghu
Copy link
Member Author

Does this also apply to the controller manager (and scheduler when the options PR merges) ?

No, but we can install this handler later in https://github.com/kubernetes/kubernetes/blob/master/cmd/controller-manager/app/serve.go#L49 for controller-manager and https://github.com/kubernetes/kubernetes/blob/master/cmd/kube-scheduler/app/server.go#L525 for kube-scheduler.

@deads2k
Copy link
Contributor

deads2k commented May 15, 2018

I like the idea, but I think we should have a versioned endpoint for it and it should plan ahead to set other glog fields like vmodule.

Dynamically setting log levels helps when you're live troubleshooting a hard to reproduce scenario. It doesn't come up often, but when you need it there are few substitutes. It is different than "normal" config in that restarting often destroys the thing you wanted to watch and because loglevel doesn't overtly change capability (latency sensitive behavior may be affected though)

@liggitt we were just talking about this
@lavalamp we talked about this a while back.
@kubernetes/sig-api-machinery-misc

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label May 15, 2018
@lavalamp
Copy link
Member

  • Disagree about making this versioned (it's for human debugging, not for tools to use). I do not want to offer this as an api with a contract that I have to support forever.
  • Binaries in Google all offer a web page that lets you change flag values on the fly (not guaranteed to work, you need to know what you're doing and how the flag is used), so even more broadly scoped than just glog flags.

@hzxuzhonghu
Copy link
Member Author

@lavalamp Any idea about which flags should support modification on the fly? And want to know how you make this in Google?

@sttts
Copy link
Contributor

sttts commented May 16, 2018

How about putting them under /debug, e.g. /debug/flags/v. For the endpoints there we don't give any compatibility guarantee. They are what Golang provides to us. Also this style would allow to have more similar flags in the future, aligned with the flag names.

@hzxuzhonghu
Copy link
Member Author

How about putting them under /debug, e.g. /debug/flags/v. For the endpoints there we don't give any compatibility guarantee. They are what Golang provides to us. Also this style would allow to have more similar flags in the future, aligned with the flag names.

agree

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 31, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, hzxuzhonghu, lavalamp

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@lavalamp
Copy link
Member

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 31, 2018
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

1 similar comment
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@k8s-ci-robot
Copy link
Contributor

@hzxuzhonghu: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-kubemark-e2e-gce-big 73a22b2 link /test pull-kubernetes-kubemark-e2e-gce-big

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@hzxuzhonghu
Copy link
Member Author

@deads2k @lavalamp @sttts for milestone, so we can make it into v1.11.

@m1093782566
Copy link
Contributor

@hzxuzhonghu I assume you want to get this PR in.

/milestone v1.11
/status approved-for-milestone

@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request Labels Incomplete

@deads2k @hzxuzhonghu @lavalamp @sttts

Action required: This pull request requires label changes. If the required changes are not made within 3 days, the pull request will be moved out of the v1.11 milestone.

kind: Must specify exactly one of kind/bug, kind/cleanup or kind/feature.
priority: Must specify exactly one of priority/critical-urgent, priority/important-longterm or priority/important-soon.

Help

@hzxuzhonghu
Copy link
Member Author

Thanks @m1093782566

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 59938, 63777, 64577, 63999, 64431). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit b706e66 into kubernetes:master Jun 1, 2018
k8s-github-robot pushed a commit that referenced this pull request Jul 3, 2018
Automatic merge from submit-queue (batch tested with PRs 64599, 65729). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

fix go import

**What this PR does / why we need it**:

Fix go import introduced by #63777.

cc @lavalamp 

/assign @sttts 

**Release note**:

```release-note
NONE
```
@@ -575,6 +576,16 @@ func installAPI(s *GenericAPIServer, c *Config) {
if c.EnableContentionProfiling {
goruntime.SetBlockProfileRate(1)
}
// so far, only logging related endpoints are considered valid to add for these debug flags.
routes.DebugFlags{}.Install(s.Handler.NonGoRestfulMux, "v", routes.StringFlagPutHandler(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this gated on profiling being enabled?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's @lavalamp suggested: #63777 (comment)

@lavalamp
Copy link
Member

lavalamp commented Aug 14, 2018 via email

@tallclair
Copy link
Member

Makes sense to flag-gate it, I'm just questioning the choice to tie it to profiling, as they seem somewhat unrelated.

k8s-github-robot pushed a commit that referenced this pull request Aug 16, 2018
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Other components support set log level dynamically

**What this PR does / why we need it**:

#63777 introduced a way to set glog.logging.verbosity dynamically. 
We should enable this for all other components, which is specially useful in debugging. 


**Release note**:

```release-note
Expose `/debug/flags/v` to allow kubelet dynamically set glog logging level.  If want to change glog level to 3, you only have to send a PUT request like `curl -X PUT http://127.0.0.1:8080/debug/flags/v -d "3"`.
```
@hzxuzhonghu hzxuzhonghu deleted the dynamic-logging-verbosity branch September 21, 2019 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. milestone/incomplete-labels release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet