MCPcopy
hub / github.com/grafana/tempo / estimateMarshalledSizeFromTrace

Function estimateMarshalledSizeFromTrace

tempodb/encoding/vparquet5/create.go:290–315  ·  view source on GitHub ↗

estimateMarshalledSizeFromTrace estimates the size of this trace when written to parquet. This is used to determine when to cut a row group during block creation. This function is about 85% accurate.

(tr *Trace)

Source from the content-addressed store, hash-verified

288// estimateMarshalledSizeFromTrace estimates the size of this trace when written to parquet. This is used to
289// determine when to cut a row group during block creation. This function is about 85% accurate.
290func estimateMarshalledSizeFromTrace(tr *Trace) (size int) {
291 size += 7 // 7 trace lvl fields
292 size += len(tr.TraceID)
293
294 for _, rs := range tr.ResourceSpans {
295 size += estimateAttrSize(rs.Resource.Attrs)
296 size += 21 // 21 resource lvl fields including dedicated attributes
297 size += 10 // 10 dedicated columns
298
299 for _, ils := range rs.ScopeSpans {
300 size += 2 // 2 scope span lvl fields
301 size += 4 // 4 scope fields
302 size += estimateAttrSize(ils.Scope.Attrs)
303
304 for _, s := range ils.Spans {
305 size += 35 // 35 span lvl fields including dedicated attributes
306 size += 10 // 10 dedicated columns
307 size += len(s.SpanID) + len(s.ParentSpanID)
308 size += estimateAttrSize(s.Attrs)
309 size += estimateEventsSize(s.Events)
310 size += estimateLinksSize(s.Links)
311 }
312 }
313 }
314 return
315}
316
317func estimateAttrSize(attrs []Attribute) (size int) {
318 size += len(attrs) * 7 // 7 attribute lvl fields

Callers 3

estimateRowSizeFunction · 0.70
AppendTraceMethod · 0.70
AddMethod · 0.70

Calls 3

estimateLinksSizeFunction · 0.85
estimateAttrSizeFunction · 0.70
estimateEventsSizeFunction · 0.70

Tested by 1

estimateRowSizeFunction · 0.56