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 tracing for incoming requests #101

Merged
merged 12 commits into from
Jan 10, 2024
Merged

Add tracing for incoming requests #101

merged 12 commits into from
Jan 10, 2024

Conversation

charleskorn
Copy link
Contributor

@charleskorn charleskorn commented Dec 14, 2023

This PR adds support for tracing incoming HTTP requests for the two webhooks.

It produces traces like the following, with nested spans for each of the HTTP calls:

Screenshot 2024-01-09 at 3 44 52 pm

I've used OpenTracing here over OpenTelemetry in the interests of consistency with Mimir.

I don't love how invasive these changes were - the default OpenTracing instrumentation for net/http requires calling nethttp.TraceRequest() for each outgoing HTTP call, but any other option would require either creating our own OpenTracing instrumentation for net/http, or using OpenTelemetry, which would break with the existing pattern of Mimir. I'm very open to other ideas or suggestions.

I don't believe we can't add tracing for Kubernetes API calls made by the informers used in the reconciliation loop, as these run outside the context of a parent span, so I haven't added tracing to the reconciliation loop beyond a single span.

Base automatically changed from charleskorn/http-metrics to main December 14, 2023 08:16
@charleskorn charleskorn force-pushed the charleskorn/tracing branch 4 times, most recently from bd40382 to 3243a6b Compare December 15, 2023 06:43
@charleskorn charleskorn marked this pull request as ready for review January 9, 2024 04:50
@charleskorn charleskorn requested a review from a team as a code owner January 9, 2024 04:50
Copy link
Member

@jhalterman jhalterman left a comment

Choose a reason for hiding this comment

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

LGTM. I assume we can migrate to OpenTelemetry in the future, when our libraries are ready.

Copy link
Collaborator

@andyasp andyasp left a comment

Choose a reason for hiding this comment

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

Thanks!

@andyasp andyasp merged commit e026294 into main Jan 10, 2024
6 checks passed
@andyasp andyasp deleted the charleskorn/tracing branch January 10, 2024 14:37
andyasp added a commit that referenced this pull request Jan 10, 2024
Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

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

LGTM, nothing major just some stylistic stuff.

cmd/rollout-operator/main.go Show resolved Hide resolved
pkg/admission/no_downscale.go Show resolved Hide resolved
pkg/admission/no_downscale.go Show resolved Hide resolved
pkg/admission/prep_downscale.go Show resolved Hide resolved

spanLogger.SetTag("object.name", ar.Request.Name)
spanLogger.SetTag("object.resource", ar.Request.Resource.Resource)
spanLogger.SetTag("object.namespace", ar.Request.Namespace)

oldObj, oldGVK, err := codecs.UniversalDeserializer().Decode(ar.Request.OldObject.Raw, nil, nil)
if err != nil {
return allowErr(logger, "can't decode old object, allowing the change", err)
}
logger = log.With(logger, "request_gvk", oldGVK)
Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate trying to minimize changes but it seems weird to use both logger and spanLogger. Can we use just the spanLogger and not keep logger around in these methods?

pkg/admission/prep_downscale.go Show resolved Hide resolved
pkg/admission/prep_downscale.go Show resolved Hide resolved
pkg/admission/prep_downscale.go Show resolved Hide resolved
pkg/admission/prep_downscale.go Show resolved Hide resolved
pkg/admission/prep_downscale.go Show resolved Hide resolved
andyasp added a commit that referenced this pull request Jan 10, 2024
@andyasp andyasp restored the charleskorn/tracing branch January 10, 2024 14:46
@andyasp
Copy link
Collaborator

andyasp commented Jan 10, 2024

Apologies @charleskorn, I merged too early. I reverted the commit and restored the branch so you could respond to the above in a reopened PR.

@charleskorn
Copy link
Contributor Author

Apologies @charleskorn, I merged too early. I reverted the commit and restored the branch so you could respond to the above in a reopened PR.

No worries, I'll continue in #114.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants