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

Function traceToParquet

tempodb/encoding/vparquet3/schema.go:269–496  ·  view source on GitHub ↗

traceToParquet converts a tempopb.Trace to this schema's object model. Returns the new object and a bool indicating if it's a connected trace or not

(meta *backend.BlockMeta, id common.ID, tr *tempopb.Trace, ot *Trace)

Source from the content-addressed store, hash-verified

267// traceToParquet converts a tempopb.Trace to this schema's object model. Returns the new object and
268// a bool indicating if it's a connected trace or not
269func traceToParquet(meta *backend.BlockMeta, id common.ID, tr *tempopb.Trace, ot *Trace) (*Trace, bool) {
270 if ot == nil {
271 ot = &Trace{}
272 }
273
274 ot.TraceIDText = util.TraceIDToHexString(id)
275 ot.TraceID = util.PadTraceIDTo16Bytes(id)
276
277 // Trace-level items
278 traceStart := uint64(0)
279 traceEnd := uint64(0)
280 var rootSpan *v1_trace.Span
281 var rootBatch *v1_trace.ResourceSpans
282
283 // Dedicated attribute column assignments
284 dedicatedResourceAttributes := dedicatedColumnsToColumnMapping(meta.DedicatedColumns, backend.DedicatedColumnScopeResource)
285 dedicatedSpanAttributes := dedicatedColumnsToColumnMapping(meta.DedicatedColumns, backend.DedicatedColumnScopeSpan)
286
287 ot.ResourceSpans = extendReuseSlice(len(tr.ResourceSpans), ot.ResourceSpans)
288 for ib, b := range tr.ResourceSpans {
289 ob := &ot.ResourceSpans[ib]
290 // Clear out any existing fields in case they were set on the original
291 ob.Resource.ServiceName = ""
292 ob.Resource.Cluster = nil
293 ob.Resource.Namespace = nil
294 ob.Resource.Pod = nil
295 ob.Resource.Container = nil
296 ob.Resource.K8sClusterName = nil
297 ob.Resource.K8sNamespaceName = nil
298 ob.Resource.K8sPodName = nil
299 ob.Resource.K8sContainerName = nil
300 ob.Resource.DedicatedAttributes = DedicatedAttributes{}
301
302 if b.Resource != nil {
303 ob.Resource.Attrs = extendReuseSlice(len(b.Resource.Attributes), ob.Resource.Attrs)
304 attrCount := 0
305 for _, a := range b.Resource.Attributes {
306 strVal, ok := a.Value.Value.(*v1.AnyValue_StringValue)
307 written := ok
308 if ok {
309 switch a.Key {
310 case LabelServiceName:
311 ob.Resource.ServiceName = strVal.StringValue
312 case LabelCluster:
313 ob.Resource.Cluster = &strVal.StringValue
314 case LabelNamespace:
315 ob.Resource.Namespace = &strVal.StringValue
316 case LabelPod:
317 ob.Resource.Pod = &strVal.StringValue
318 case LabelContainer:
319 ob.Resource.Container = &strVal.StringValue
320
321 case LabelK8sClusterName:
322 ob.Resource.K8sClusterName = &strVal.StringValue
323 case LabelK8sNamespaceName:
324 ob.Resource.K8sNamespaceName = &strVal.StringValue
325 case LabelK8sPodName:
326 ob.Resource.K8sPodName = &strVal.StringValue

Callers 15

BenchmarkCombineFunction · 0.70
BenchmarkSortTraceFunction · 0.70
TestBackendBlockSearchFunction · 0.70
TestProtoParquetRandoFunction · 0.70
TestFieldsAreClearedFunction · 0.70
TestTraceToParquetFunction · 0.70
BenchmarkProtoToParquetFunction · 0.70
BenchmarkDeconstructFunction · 0.70
createTestBlockFunction · 0.70

Calls 15

SizeMethod · 0.95
MarshalToSizedBufferMethod · 0.95
TraceIDToHexStringFunction · 0.92
PadTraceIDTo16BytesFunction · 0.92
GetStringValueMethod · 0.80
extendReuseSliceFunction · 0.70
attrToParquetFunction · 0.70
eventToParquetFunction · 0.70
getMethod · 0.45
writeValueMethod · 0.45

Tested by 15

BenchmarkCombineFunction · 0.56
BenchmarkSortTraceFunction · 0.56
TestBackendBlockSearchFunction · 0.56
TestProtoParquetRandoFunction · 0.56
TestFieldsAreClearedFunction · 0.56
TestTraceToParquetFunction · 0.56
BenchmarkProtoToParquetFunction · 0.56
BenchmarkDeconstructFunction · 0.56
createTestBlockFunction · 0.56