-
Notifications
You must be signed in to change notification settings - Fork 727
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 APM tracing for client-go requests to the Kubernetes API #5651
Conversation
1fc2655
to
12aa428
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still doing some tests, it works well so far 👍 , just wanted to leave a few comments.
I feel a bit out of depth because I'm not familiar with the go.elastic.co/apm/v2
package, but it's a very interesting PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I'm not sure I'm the best person to review the RoundTrip
function though, but given it seems inspired from the APM http module I think it is fine (it might be an argument for having it as a new module as you suggested).
// Allows an optional default transaction to be configured for requests where context cannot be controlled | ||
// e.g. client-go's cache management |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: latinism
// Allows an optional default transaction to be configured for requests where context cannot be controlled | |
// e.g. client-go's cache management | |
// Allows an optional default transaction to be configured for requests where context cannot be controlled, | |
// for example client-go's cache management. |
numSegments := 2 | ||
// add a bit more context in the summary for PUT requests e.g. namespace | ||
if req.Method == "PUT" { | ||
numSegments = 3 | ||
} | ||
|
||
pathSegments := strings.Split(req.URL.Path, "/") | ||
path := strings.Join(pathSegments[len(pathSegments)-numSegments:], "/") | ||
// let's call out watch requests explicitly | ||
if watch := req.URL.Query().Get("watch"); watch == "true" { | ||
statement = "WATCH" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it got very long in the UI so I was looking for something shorter that still conveyed the most relevant information.
Jenkins test this please
I am confused |
…#5651) This adds a custom APM round tripper for requests to the Kubernetes API. This can potentially be contributed to elastic/apm-agent-go as a new module. But I think it would be good to try it first in the context of the eck-operator. I structured the code in such a way to allow that if we decide it is worth contributing. Why a custom round tripper? To get a meaningful span summary that is specific to k8s. The current implementation is not perfect in this regard especially sub-resource requests are represented somewhat arbitrarily by subsections of the request path. The other thing implement here is to track requests done in the background by the client-go library to maintain the local cache. As far as I know there is no way to inject a context into the library that would enable tracing. This PR implements instead a default transaction mechanism to track those requests.
Follow up to #5649
Will rebase once the first PR is merged. Relevant commits is:
15e7e87
This adds a custom APM round tripper for requests to the Kubernetes API. This can potentially be contributed to elastic/apm-agent-go as a new module. But I think it would be good to try it first in the context of the eck-operator. I structured the code in such a way to allow that if we decide it is worth contributing.
Why a custom round tripper?
To get a meaningful span summary that is specific to k8s. The current implementation is not perfect in this regard especially sub-resource requests are represented somewhat arbitrarily by subsections of the request path.
The other thing implement here is to track requests done in the background by the client-go library to maintain the local cache. As far as I know there is no way to inject a context into the library that would enable tracing. This PR implements instead a default transaction mechanism to track those requests.