-
Notifications
You must be signed in to change notification settings - Fork 18k
pprof: add support for profiler labels #17280
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
Comments
CL https://golang.org/cl/30015 mentions this issue. |
Updates golang/go#17280 Change-Id: I6dcad5c98f6b19635bfce61d75e7052c05985131 Reviewed-on: https://go-review.googlesource.com/30015 Reviewed-by: Austin Clements <[email protected]>
The proposal document has been submitted to the proposal repo. Please take a look. https://github.com/golang/proposal/blob/master/design/17280-profile-labels.md |
At first glance, I find the high-level API confusing. You're proposing taking the Context type, which already encapsulates a key-value store, and adding a second separate key-value store to it. I especially find the name "DoWithLabels" confusing - I naively expect it to behave similarly to WithValue, but it doesn't. To my mind, this would be resolved by moving this outside the context package. I think this can just be a regular consumer of the Context type. i.e. we could move this to It feels unfortunate to me that this has to be The fact that the argument is Finally, don't you need a way to read out the current labels to pass them along with an RPC? It is my understanding that this is one of the underlying goals of the proposal. |
I don't see how it makes sense to store all the Personally I think it's fine to use For an RPC I think the expectation is that the specific appropriate labels would be applied by the RPC server. There is no necessary or appropriate correspondence between the complete set of labels used by the client and those used by the server. |
I don't have a strong opinion about the package I have a slight preference for |
Here's a change with a prototype of the interface (but not actually applying the labels to profiles): https://go-review.googlesource.com/c/31145/ |
CL https://golang.org/cl/31145 mentions this issue. |
@ianlancetaylor Not sure if that was directed at me, but I did not propose storing all the
This can be done in any package, and does not require any change to the |
@quentinmit I think we're all in agreement then... That's exactly how we want DoWithLabels to work. See the prototype here: https://go-review.googlesource.com/c/31145/6/src/context/context.go I think the only question here is where DoWithLabels belongs. It coulb be in package context or package pprof. I don't have a strong preference. |
Yep, I think we're all in agreement about how As for reading labels, your proposal currently says:
From talking to @ianlancetaylor, the thing we are trying to prevent is goroutine-local storage. I missed the fact that Either way, we need to add a way to get at the labels in a context. This could be a |
@quentinmit That comment is obsolete. I've sent a cl to update it. The "compromise" solution is to allow reading labels, but not on ProfileLabels returned by the runtime. So that allows us to read labels we keep in the context (because they're never set from a ProfileLabels returned by the runtime), while disallowing GLS. It would be nice to have LabelsFromContext, but I don't think it's strictly necessary (at least for now). You can get all the nice pprof benefits of adding labels without needing to read the labels on a context. It would be really easy to add LabelsFromContext later. -- I'm not saying that we shouldn't add it, but we can (if we want) wait until later to do so. Another option is to have LabelsFromContext return a runtime.ProfileLabels. Any ProfileLabels set on a context using DoWithLabels should be readable. |
@quentinmit Here's an example of why we'd want to restore the previous ProfileLabels set on the goroutine rather than the parent context's ProfileLabels: Let's say a user wants to do some work that they don't want to have accounted to the current context. They might have code that looks like this:
When the DoWithLabels returns, they probably want to revert to the context already set on the goroutine rather than the background context. |
Yeah, makes sense. (But really, don't call it "the context already set on the goroutine"! The runtime is not in fact tracking a Context object. :) This is a great example of the kind of confusion I think putting it in package |
Eek! That's pretty bad... I wouldn't mind moving |
So the only point of discussion now is which package |
I've been stressing all along that I believe that since we already have a request-specific type, namely |
@ianlancetaylor Is that an argument for adding |
@matloob I have no opinion about |
@ianlancetaylor Okay. I think I misunderstood your previous comment. Please ignore the stuff about But I don't see why |
I think we should keep |
Discussed offline with @ianlancetaylor and @quentinmit. It seems like there's general agreement for naming the function |
Can we wait until we have more experience with it inside Google before adding it to the standard library? Or maybe we do. I haven't been paying attention. Or could we add it to I'd prefer not to add runtime API now. In particular, |
I think we have a fair amount of experience with this, but I would also prefer an experimental API if it's possible. What would a short term hack look like? Would we have a flag that switched on part of the API? I don't have a strong preference between [2]string and struct {key string; value string}. |
As one strawman, you could add some undocumented behavior to runtime/pprof and sneak in some undocumented private interface to any of the interface methods. Like on, Or add a global variable in the package (new API in Go 1.8), like: // Experiment is an internal hook for pprof experiments.
// This is not a documented or stable API.
var Experiment = experiment{} And the lowercase |
Put it behind a build tag?
This was not done without reason. If we use a type, |
I think a named type in the stdlib is okay. |
I spoke to @matloob, @aclements, and @ianlancetaylor about this last week. I believe we agreed that:
I suggest:
and then code would look like
|
s/SetLabels/SetGoroutineLabels/ (to discourage accidental use) body of Do should be
otherwise this proposal looks good to me. |
Okay. With @rsc's changes we end up with:
|
LGTM. Possible we should change type Label and []Label to type LabelList and LabelList (not slice). As written there's nothing particularly useful you can do with the slice, so maybe the sliceness should be opaque. |
It seems like the right next steps are: CL #1: Implementation of and tests for type labels, the functional label set that we'll store in contexts. (Labels, WithLabels, HasLabel, ForLabels) CL #2: Implementation of and tests for SetLabels and Do, including what happens with new goroutines and goroutines that die. CL #3: Adding labels to runtime-generated profiles. This is the part that I said I'd help with, if I remember correctly. It's OK to send those CLs during the Go 1.8 freeze. I will make some time to review them so that they can be ready at the start of Go 1.9. |
When you say that It's not obvious to me why |
@ianlancetaylor. I think HasLabel could be useful because in some instances we might need the following behavior: "If set we do nothing. If not set then set with some value." |
@acetechnologist Well, I guess, but do you have an answer for the second part of the question--why not return the value? |
Discussed with @acetechnologist offline. I don't think there's any reason not to return the value. So HasLabels is renamed to Label and returns the value and an 'ok' bool. I'm also clarifying below that setting a (k, v) where the key already exists will overwrite the previous value for the key (map semantics).
|
In terms of documentation, I think we all put quite a bit of effort into wording the documentation on the previous version of this at https://go-review.googlesource.com/c/31145/. Obviously most of that can't be copied verbatim, but rather than starting from scratch, we should at least start from there. For example, the current doc for
|
Let's move forward with the CLs I outlined above and then we can fine-tune the doc comments in the actual code review. |
CL https://golang.org/cl/34198 mentions this issue. |
This change defines WithLabels, Labels, Label, and ForLabels. This is the first step of the profile labels implemention for go 1.9. Updates #17280 Change-Id: I2dfc9aae90f7a4aa1ff7080d5747f0a1f0728e75 Reviewed-on: https://go-review.googlesource.com/34198 Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
CL https://golang.org/cl/36538 mentions this issue. |
@matloob, could you update https://github.com/golang/proposal/blob/master/design/17280-profile-labels.md with the new API? It is impossible to link to the final proposal at this point. |
CL https://golang.org/cl/43530 mentions this issue. |
Hi, I've sent out a CL to update the proposal document with the actual changes: golang.org/cl/43530 |
The name LabelList was changed to LabelSet during the development of the proposal [1], except in one function comment. This commit fixes that. Fixes #20905. [1] #17280 Change-Id: Id4f48d59d7d513fa24b2e42795c2baa5ceb78f36 Reviewed-on: https://go-review.googlesource.com/47470 Reviewed-by: Brad Fitzpatrick <[email protected]>
I propose adding a mechanism to the runtime and profiling code to allow for annotating profile samples with key-value labels. These labels are an already-existing feature of pprof that we do not support yet.
The user interface would look something like this:
More details in the proposal document
The text was updated successfully, but these errors were encountered: