Skip to content

Frontend Refactor - #3400

Merged
joe-elliott merged 28 commits into
grafana:mainfrom
joe-elliott:frontend-o7-beta
Mar 1, 2024
Merged

Frontend Refactor#3400
joe-elliott merged 28 commits into
grafana:mainfrom
joe-elliott:frontend-o7-beta

Conversation

@joe-elliott

@joe-elliott joe-elliott commented Feb 15, 2024

Copy link
Copy Markdown
Collaborator

What this PR does:
Refactors the frontend pipeline to accomplish a number of goals detailed below. Currently only the search pipelines have been moved over to the new structure. There will be follow up PRs for other endpoints.

Goals:

  • Provide streaming on all query endpoints
  • Consolidate recombination logic in the frontend/combiner package
  • Consolidate all pipeline building logic in the frontend/pipeline package

See the readme in the pipeline package for details.

Which issue(s) this PR fixes:
Fixes #1392

This PR is progress toward #3366 with an eventual goal to close it.

Changes

  • removes tempo_query_frontend_multitenant... metrics b/c they don't quite fit into the current pattern. this can be improved later.

todo:

  • Flesh out readme.md in /pipeline to describe how to build new pipeline elements

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
@knylander-grafana

Copy link
Copy Markdown
Contributor

@joe-elliott Was there doc added? I didn't see any in the file list to review.

@joe-elliott

Copy link
Copy Markdown
Collaborator Author

@joe-elliott Was there doc added? I didn't see any in the file list to review.

There was not. This change is invisible to the user. Unchecking the docs item!

Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
@joe-elliott joe-elliott mentioned this pull request Feb 20, 2024
9 tasks
Signed-off-by: Joe Elliott <number101010@gmail.com>
Comment thread modules/frontend/pipeline/pipeline.go Outdated
Comment thread modules/frontend/pipeline/async_sharding.go
Comment thread modules/frontend/pipeline/async_sharding.go Outdated
Comment thread modules/frontend/search_handlers.go

go func() {
if resps != nil {
asyncResp.Send(resps)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you help me understand more about what resps is? My understanding is that asyncResp.Send(resp) above is the core data flow, sending things up the chain as they come in. This looks like a final send that's already known by the caller?

@joe-elliott joe-elliott Feb 26, 2024

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this was added to allow the sharder to craft responses unrelated to a request and send them back up the chain. in this case it's used to communicate search job size data up to the combiner.

created here:
https://github.com/grafana/tempo/pull/3400/files#diff-80f55bc33c867c54319fcdfef902b821f96f15e3ec594167bd4c9ab266b7b6eaR120

processed here:
https://github.com/grafana/tempo/pull/3400/files#diff-96cf01ab28f4274fe65e4501fbf82cd479266202d7bc766d3a7c720475568cdaR38-R41

this highlights the largest complication with this PR. code that used to do the recombining was highly context aware:
https://github.com/grafana/tempo/blob/main/modules/frontend/searchsharding.go#L245-L318

b/c it was just executed after all jobs had completed in the same function. Now we are pushing all jobs up to the collector level to stream results. As a result some of that context is lost and it creates "message passing" code like this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it, thanks. Caching is another instance, where the cacheKey is passed through the context.

Comment thread modules/frontend/pipeline/collector_grpc.go Outdated
Comment thread modules/frontend/combiner/common.go Outdated
Comment thread modules/frontend/frontend.go
Comment thread modules/frontend/frontend.go Outdated
Comment thread modules/frontend/frontend.go
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
@joe-elliott
joe-elliott requested a review from mdisibio February 28, 2024 14:21

go func() {
if resps != nil {
asyncResp.Send(resps)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it, thanks. Caching is another instance, where the cacheKey is passed through the context.

}

// fetch fetches the response body from the cache. the caller assumes the responsibility of closing the response body.
func (c *frontendCache) fetch(key string, pb proto.Message) bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method looks unused except for the test, and wasn't sure about json+proto.Message. Since we know it's a proto.Message we could store the binary representation in cache instead.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yup. i do think there's an opportunity to make the sync part of the pipeline type aware with generics which would allow this, but we're not quite there yet

@mdisibio mdisibio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I really like this, the async parts seem clearer and streaming everywhere will be awesome. Definitely think we can make the sync parts (cache, etc) also async in the future.

@joe-elliott
joe-elliott merged commit c889e63 into grafana:main Mar 1, 2024
mattdurham pushed a commit to mattdurham/tempo that referenced this pull request Jun 18, 2026
* async handlers

Signed-off-by: Joe Elliott <number101010@gmail.com>

* search pipeline

Signed-off-by: Joe Elliott <number101010@gmail.com>

* cleanup

Signed-off-by: Joe Elliott <number101010@gmail.com>

* lint

Signed-off-by: Joe Elliott <number101010@gmail.com>

* fixed api tests

Signed-off-by: Joe Elliott <number101010@gmail.com>

* make err last param - lint

Signed-off-by: Joe Elliott <number101010@gmail.com>

* lint

Signed-off-by: Joe Elliott <number101010@gmail.com>

* remove test for dropped metrics

Signed-off-by: Joe Elliott <number101010@gmail.com>

* pipeline readme

Signed-off-by: Joe Elliott <number101010@gmail.com>

* cleanup

Signed-off-by: Joe Elliott <number101010@gmail.com>

* responses cleanup

Signed-off-by: Joe Elliott <number101010@gmail.com>

* review comments

Signed-off-by: Joe Elliott <number101010@gmail.com>

* remove unnecessary goroutine

Signed-off-by: Joe Elliott <number101010@gmail.com>

* async sharder takes len

Signed-off-by: Joe Elliott <number101010@gmail.com>

* nolint

Signed-off-by: Joe Elliott <number101010@gmail.com>

* AsyncSharder rename/cleanup

Signed-off-by: Joe Elliott <number101010@gmail.com>

* lint

Signed-off-by: Joe Elliott <number101010@gmail.com>

* fix integration tests

Signed-off-by: Joe Elliott <number101010@gmail.com>

* lint >.<

Signed-off-by: Joe Elliott <number101010@gmail.com>

* remove special context handling in the grpc collector

Signed-off-by: Joe Elliott <number101010@gmail.com>

* prevent goroutine leak when sending to a full channel

Signed-off-by: Joe Elliott <number101010@gmail.com>

* buffer error to guarantee at least one makes it

Signed-off-by: Joe Elliott <number101010@gmail.com>

* responses in error should stay in error

Signed-off-by: Joe Elliott <number101010@gmail.com>

* test for returning the same error

Signed-off-by: Joe Elliott <number101010@gmail.com>

* don't pass requests in error forward

Signed-off-by: Joe Elliott <number101010@gmail.com>

* log http results even on err

Signed-off-by: Joe Elliott <number101010@gmail.com>

---------

Signed-off-by: Joe Elliott <number101010@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants