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

feat: Trace web hook calls #2154

Merged
merged 5 commits into from
Jan 31, 2022
Merged

Conversation

martinei
Copy link
Contributor

@martinei martinei commented Jan 17, 2022

This Pull request attempt to improve tracing in two places:

  • Tracing Middleware was not register in the correct order in daemon/serve.go. That led to many DB calls being orphaned because their parent span did not exist. Now most DB calls are under a correct parent span. (I noticed further orphaned DB call spans, but the other root cause is in pop: "Create" does not pass Context properly gobuffalo/pop#685)
  • The http client for webhooks is now instrumented as well, so that webhooks are traced

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security. vulnerability, I
    confirm that I got green light (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

This PR still creates the Http client in webhooks. I am not sure if it would be a good Idea to move it to the registry.
Further the client has no timeouts configured. Making the configurable could be a task for further improvements.

I had some trouble because the the config and thus the tracer are "contextualized" - at least that is what the function signatures say. In reality I believe the context param is never used and I think it makes the overall thingh to complex.

@martinei martinei changed the title Add http client tracing. feature: Trace web hook calls Jan 18, 2022
@martinei martinei changed the title feature: Trace web hook calls feat: Trace web hook calls Jan 18, 2022
@martinei
Copy link
Contributor Author

I am not sure about the failing tests. As far as I can see those tests are also red on master

@aeneasr
Copy link
Member

aeneasr commented Jan 18, 2022

Those are flaky :) Should be fine!

Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

Great stuff! Just a minor remark regarding tests :)

return rt(r)
}

func createHttpClient(tracer *tracing.Tracer) *http.Client {
Copy link
Member

Choose a reason for hiding this comment

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

Is there some way to write a test for this functionality? It looks fine but we need to ensure:

  1. It works
  2. It doesn't break when someone changes something


delegateClient := http.DefaultTransport

var roundTripper RoundTripperFunc = func(req *http.Request) (*http.Response, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you move this to ory/x/httpx? It could be an option like

https://github.com/ory/x/blob/e38bb388d3f8982c170d256247a3b4f42a8ce589/httpx/resilient_client.go#L40

so for example:

httpx.ResilientClientWithTracer()

that would allow this to be used across the ecosystem :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will have a look, also at the test

@martinei martinei mentioned this pull request Jan 21, 2022
6 tasks
@aeneasr
Copy link
Member

aeneasr commented Jan 22, 2022

ory/x is merged :)

Probably makes sense to redo this PR completely from master and just add tracing here:

func (m *RegistryDefault) HTTPClient(ctx context.Context) *retryablehttp.Client {
opts := []httpx.ResilientOptions{
httpx.ResilientClientWithLogger(m.Logger()),
httpx.ResilientClientWithMaxRetry(2),
httpx.ResilientClientWithConnectionTimeout(30 * time.Second),
}
if m.Config(ctx).ClientHTTPNoPrivateIPRanges() {
opts = append(opts, httpx.ResilientClientDisallowInternalIPs())
}
return httpx.NewResilientClient(opts...)
}

@martinei martinei force-pushed the feature/trace-web-hooks branch from 01cd201 to 04170c0 Compare January 24, 2022 06:57
@martinei
Copy link
Contributor Author

Ups. Updating ory/x did not go well. There appear to be breaking changes in the upgraded jsonschema/v3

@aeneasr
Copy link
Member

aeneasr commented Jan 24, 2022

Oh yeah, if you make your changes against #2166 then you won't have any problems upgrading ory/x :)

@martinei martinei changed the base branch from master to v0.8 January 24, 2022 15:22
Copy link
Contributor

@Benehiko Benehiko left a comment

Choose a reason for hiding this comment

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

Looks good! I just think it is missing some tests to verify that the changes do fix the problem. Other than that it's good :)

@aeneasr
Copy link
Member

aeneasr commented Jan 31, 2022

Thank you for the review @Benehiko :) @martinei added tests in the PR in ory/x. Given that we only do some bootstrapping here it will be difficult to test this e2e with Jaeger, so I think we can take a leap of faith on this one!

There are however some CI failures, I'm not sure if they're flakes or not (rerunning CI now) but could you (@martinei ) please take a look if they fail?

@martinei
Copy link
Contributor Author

Thanks @aeneasr This is based on the v0.8 branch which also has failing tests. I was hopping to first see green test there, so I can sort out if this PR brakes anything new.

@aeneasr
Copy link
Member

aeneasr commented Jan 31, 2022

Ah, got it, fair point! Thank you :)

@aeneasr aeneasr merged commit 52341d0 into ory:v0.8 Jan 31, 2022
aeneasr pushed a commit that referenced this pull request Feb 11, 2022
aeneasr pushed a commit that referenced this pull request Feb 14, 2022
@vinckr vinckr mentioned this pull request Mar 18, 2022
peturgeorgievv pushed a commit to senteca/kratos-fork that referenced this pull request Jun 30, 2023
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.

3 participants