Skip to content

Rewrite traces using rebatching - #4690

Merged
stoewer merged 15 commits into
grafana:mainfrom
stoewer:rewrite-traces
Feb 20, 2025
Merged

Rewrite traces using rebatching#4690
stoewer merged 15 commits into
grafana:mainfrom
stoewer:rewrite-traces

Conversation

@stoewer

@stoewer stoewer commented Feb 13, 2025

Copy link
Copy Markdown
Contributor

What this PR does:
Rebatch traces in order to remove redundant ResourceSpans and ScopeSpans to reduces the number of rows on resource and scope level. This has shown to speed up queries with matching resource attributes and also reduces the overall file size.

Which issue(s) this PR fixes:
Fixes grafana/tempo-squad#548

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
joe-elliott and others added 11 commits February 17, 2025 08:25
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Will be implemented in separate branch that will not be merged
The functions test.MakeBatch and test.MakeTrace* now create
more unique ResourceSpans and ScopeSpans. This avoids unwanted
rebatching in tests
Test data now has additional attributes on resource level
that caused these tests to fail
@stoewer
stoewer marked this pull request as ready for review February 17, 2025 00:52
@stoewer stoewer changed the title [WIP] Rewrite traces using rebatching Feb 17, 2025

@mapno mapno 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.

Very nice code, LGTM

@joe-elliott joe-elliott left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice implementation. couple nits and only one "real" question.

thanks!

Comment thread tempodb/encoding/vparquet4/schema.go Outdated
}

// modify trace by rebatching spans and assigning nested set values
rebatchTrace(ot)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should we also call this after combining here-ish?

https://github.com/grafana/tempo/blob/main/tempodb/encoding/vparquet4/combiner.go#L139

we seem to have three things we do every time we build a trace:

  • rebatch
  • nested set model
  • service stats

should we create some holistic function like "finalizeTrace" that accomplishes this? that way if we add more of this kind of processing we will have an easy place to put it?

func finalizeTrace() {
  rebatch()
  assignNestedSetModel()
  ...
}
Comment thread tempodb/encoding/vparquet4/schema_test.go
Comment thread tempodb/encoding/vparquet4/rebatch_trace_test.go
}

// preallocate a map and a slice to collect the indices of unique ResourceSpans and ScopeSpans
uniqueIndexes := make([]int, 0, max(len(trace.ResourceSpans), len(trace.ResourceSpans[0].ScopeSpans)))

@joe-elliott joe-elliott Feb 19, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

took me a bit to figure out what you were using this. appreciate the effort on the in place alg. clean and well implemented.

@stoewer
stoewer merged commit 40c4351 into grafana:main Feb 20, 2025
@stoewer
stoewer deleted the rewrite-traces branch March 13, 2025 06:24
mattdurham pushed a commit to mattdurham/tempo that referenced this pull request Jun 18, 2026
* Implement span basic rebatching and 4to4 converter

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

* Generated trace data with unique scope and resource spans

The functions test.MakeBatch and test.MakeTrace* now create
more unique ResourceSpans and ScopeSpans. This avoids unwanted
rebatching in tests

* Fix tests in spanmetrics processor

Test data now has additional attributes on resource level
that caused these tests to fail

* Move rebatch code out of nested set function

* Make parquetTraceToTempopbTrace() private

* Add benchmark for testing traceToParquet()

* make check-fmt

* rebatchTrace() without allocating new slices for ResourceSpans and ScopeSpans

* Fix bug with duplicated rs ans ss in rebatchTrace()

* CHANGELOG.md

* Add finalizeTrace() function

* Call finalizeTrace() in combiner

---------

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

3 participants