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

[query] Use OTEL's helpers for http server #6121

Merged
merged 23 commits into from
Oct 30, 2024

Conversation

mahadzaryab1
Copy link
Collaborator

@mahadzaryab1 mahadzaryab1 commented Oct 25, 2024

Which problem is this PR solving?

Description of the changes

  • Migrates the query http server to create the server using OTEL rather than using a custom implementation

How was this change tested?

  • CI

Checklist

cmd/query/app/server.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 25, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.

Project coverage is 96.42%. Comparing base (0af8d35) to head (f8c5d5c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/query/app/server.go 82.35% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6121      +/-   ##
==========================================
- Coverage   96.43%   96.42%   -0.02%     
==========================================
  Files         353      353              
  Lines       20128    20141      +13     
==========================================
+ Hits        19410    19420      +10     
- Misses        532      534       +2     
- Partials      186      187       +1     
Flag Coverage Δ
badger_v1 8.32% <ø> (ø)
badger_v2 1.68% <ø> (ø)
cassandra-4.x-v1 14.40% <ø> (ø)
cassandra-4.x-v2 1.62% <ø> (ø)
cassandra-5.x-v1 14.40% <ø> (ø)
cassandra-5.x-v2 1.62% <ø> (ø)
elasticsearch-6.x-v1 18.53% <ø> (ø)
elasticsearch-7.x-v1 18.60% <ø> (ø)
elasticsearch-8.x-v1 18.78% <ø> (ø)
elasticsearch-8.x-v2 1.68% <ø> (?)
grpc_v1 9.49% <ø> (-0.01%) ⬇️
grpc_v2 7.00% <ø> (ø)
kafka-v1 8.89% <ø> (ø)
kafka-v2 1.68% <ø> (ø)
memory_v2 1.68% <ø> (ø)
opensearch-1.x-v1 18.66% <ø> (ø)
opensearch-2.x-v1 18.66% <ø> (ø)
opensearch-2.x-v2 1.68% <ø> (ø)
tailsampling-processor 0.47% <ø> (ø)
unittests 95.33% <91.66%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

cmd/query/app/server.go Outdated Show resolved Hide resolved
cmd/query/app/server.go Outdated Show resolved Hide resolved
@yurishkuro
Copy link
Member

what was the problem with http in the first diff? Did you find a workaround?

@mahadzaryab1 mahadzaryab1 changed the title [query] Use OTEL's helpers for http server [WIP] [query] Use OTEL's helpers for http server Oct 25, 2024
Comment on lines 74 to 77
// traceMiddleware := otelhttp.NewHandler(
// otelhttp.WithRouteTag(route, handler),
// route,
// otelhttp.WithTracerProvider(h.Tracer))
Copy link
Collaborator Author

@mahadzaryab1 mahadzaryab1 Oct 25, 2024

Choose a reason for hiding this comment

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

@yurishkuro I tried commenting out this middleware to see if the GRPC tests would pass but it looks like the grpc v2 tests are running into the same issue of getting stuck in a loop of WriteSpan. Any idea why that's happening and if there's a way around it?

Copy link
Member

Choose a reason for hiding this comment

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

why are grpc tests affected by http changes? We already merged grpc PR on green CI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cmd/query/app/apiv3/http_gateway.go Outdated Show resolved Hide resolved
cmd/query/app/http_handler.go Outdated Show resolved Hide resolved
cmd/query/app/http_handler_test.go Show resolved Hide resolved
cmd/query/app/server.go Outdated Show resolved Hide resolved
cmd/query/app/server.go Outdated Show resolved Hide resolved
@mahadzaryab1 mahadzaryab1 changed the title [WIP] [query] Use OTEL's helpers for http server [query] Use OTEL's helpers for http server Oct 26, 2024
@mahadzaryab1 mahadzaryab1 marked this pull request as ready for review October 26, 2024 23:42
@mahadzaryab1 mahadzaryab1 requested a review from a team as a code owner October 26, 2024 23:42
@dosubot dosubot bot added the area/otel label Oct 26, 2024
cmd/query/app/server.go Outdated Show resolved Hide resolved
@mahadzaryab1
Copy link
Collaborator Author

mahadzaryab1 commented Oct 27, 2024

@yurishkuro looks like my latest commit performs a lot of the same changes as in #6128. How do you want to proceed? Should I revert my last commit?

This reverts commit a1beee7.

Signed-off-by: Mahad Zaryab <[email protected]>
yurishkuro added a commit that referenced this pull request Oct 27, 2024
## Which problem is this PR solving?
- Prequel for #6121

## Description of the changes
- Consolidate business logic handlers into a single function
`initRouter`
- Move tenancy handling to the same function, remove it from API and
APIv3 handlers

## How was this change tested?
- `go test ./cmd/query/app/...`

---------

Signed-off-by: Yuri Shkuro <[email protected]>
yurishkuro and others added 2 commits October 27, 2024 12:25
Signed-off-by: Yuri Shkuro <[email protected]>
route,
otelhttp.WithTracerProvider(aH.tracer))
return router.HandleFunc(route, traceMiddleware.ServeHTTP)
handler = traceResponseHandler(handler)
Copy link
Member

Choose a reason for hiding this comment

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

TODO traceResponseHandler should be moved to initRouter, it can apply to the whole server, not just API handler

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@yurishkuro do we want to do that in this PR or a different one?

Copy link
Member

Choose a reason for hiding this comment

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

probably another, already too many changes here to keep track of

Copy link
Member

Choose a reason for hiding this comment

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

server.TLSConfig = tlsCfg
}
return server, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

misleading diff display by GH - this part above did not actually change

Signed-off-by: Mahad Zaryab <[email protected]>
Signed-off-by: Mahad Zaryab <[email protected]>
Signed-off-by: Mahad Zaryab <[email protected]>
Signed-off-by: Mahad Zaryab <[email protected]>
Signed-off-by: Mahad Zaryab <[email protected]>
@@ -855,3 +859,104 @@ func TestServerHTTPTenancy(t *testing.T) {
})
}
}

func TestServerHTTP_TracesRequest(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

This is a great test, but it highlights a problem. I recommend creating a separate PR with just this test, and it will fail on main, which means we are changing something about the behavior.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@yurishkuro this is rebased now

mahadzaryab1 and others added 2 commits October 27, 2024 18:27
Signed-off-by: Mahad Zaryab <[email protected]>
httpEndpoint: ":8080",
grpcEndpoint: ":8080",
queryString: "/api/traces/123456aBC",
expectedTrace: "/api/traces/{traceID}",
Copy link
Member

Choose a reason for hiding this comment

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

why are we loosing this trace? That was my point of adding the test to main first - it should not change in this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@yurishkuro We're losing this trace at the moment because removed the call to otelhttp.NewHandler which was taking a tracer. If we don't remove that call then we run into the issue of double instrumentation that we were seeing earlier.

Copy link
Member

Choose a reason for hiding this comment

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

so how do we explain that? The OTEL helper is supposed to add tracing middleware, why is it not working?

Copy link
Collaborator Author

@mahadzaryab1 mahadzaryab1 Oct 28, 2024

Choose a reason for hiding this comment

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

@yurishkuro The OTEL helper does add tracing. However, when the ports are the same, we're not using the OTEL helper to initialize the server and are our falling back to our custom implementation. We were previously using otelhttp.NewHandler in http_handler.go and http_gateway.go which was previously rendering this trace. We removed it from there because then we were running into the case of double instrumentation when the ports were different and we were using the OTEL helpers.

Copy link
Collaborator Author

@mahadzaryab1 mahadzaryab1 Oct 28, 2024

Choose a reason for hiding this comment

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

Thinking more about this - is there a reason why we can't just use OTEL's helper to create the server even if the ports are the same? We can still use a different flow when we start the listener.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@yurishkuro I was actually wondering why we can't just use the server created by ToServer for the legacy flow as well?

Copy link
Member

Choose a reason for hiding this comment

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

How would we co-locate http and grpc servers on the same port in that case? We could if the listener is still done separately by our code.

Copy link
Collaborator Author

@mahadzaryab1 mahadzaryab1 Oct 29, 2024

Choose a reason for hiding this comment

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

@yurishkuro The listener is initialized separately and it already has a check for separate ports (see https://github.com/jaegertracing/jaeger/blob/main/cmd/query/app/server.go#L289). So can we just simplify the logic of creating the server to always create it using ToServer and then we can handle the legacy behaviour inside ToListener.

Copy link
Member

Choose a reason for hiding this comment

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

give it a try. Or just add tracing handler to Legacy function and we can merge this PR, then try the listener separately.

Copy link
Collaborator Author

@mahadzaryab1 mahadzaryab1 Oct 30, 2024

Choose a reason for hiding this comment

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

@yurishkuro I removed the bifurcation for the creation of the server and it looks to be working as expected which makes sense. We can simply rely on OTEL's helpers to create the server. We only need special handling if the ports are the same (and that handling exists already in initListener). I'll do the same for the GRPC server in a follow-up PR.

@yurishkuro yurishkuro merged commit c5f34d9 into jaegertracing:main Oct 30, 2024
48 of 49 checks passed
yurishkuro added a commit to yurishkuro/jaeger that referenced this pull request Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants