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

Method ToProto

pkg/traceql/engine_metrics.go:350–423  ·  view source on GitHub ↗
(req *tempopb.QueryRangeRequest)

Source from the content-addressed store, hash-verified

348type SeriesSet map[SeriesMapKey]TimeSeries
349
350func (set SeriesSet) ToProto(req *tempopb.QueryRangeRequest) []*tempopb.TimeSeries {
351 mapper := NewIntervalMapperFromReq(req)
352 resp := make([]*tempopb.TimeSeries, 0, len(set))
353
354 for _, s := range set {
355 labels := make([]commonv1proto.KeyValue, 0, len(s.Labels))
356 for _, label := range s.Labels {
357 labels = append(labels,
358 commonv1proto.KeyValue{
359 Key: label.Name,
360 Value: label.Value.AsAnyValue(),
361 },
362 )
363 }
364
365 intervals := mapper.IntervalCount()
366 samples := make([]tempopb.Sample, 0, intervals)
367 for i, value := range s.Values {
368 // todo: this loop should be able to be restructured to directly pass over
369 // the desired intervals
370 if i >= intervals || math.IsNaN(value) {
371 continue
372 }
373
374 ts := mapper.TimestampOf(i)
375 samples = append(samples, tempopb.Sample{
376 TimestampMs: time.Unix(0, int64(ts)).UnixMilli(),
377 Value: value,
378 })
379 }
380 // Do not include empty TimeSeries
381 if len(samples) == 0 {
382 continue
383 }
384
385 var exemplars []tempopb.Exemplar
386 if len(s.Exemplars) > 0 {
387 exemplars = make([]tempopb.Exemplar, 0, len(s.Exemplars))
388 }
389 for _, e := range s.Exemplars {
390 // skip exemplars that has NaN value
391 i := mapper.IntervalMs(int64(e.TimestampMs))
392 if i < 0 || i >= len(s.Values) || math.IsNaN(s.Values[i]) { // strict bounds check
393 continue
394 }
395
396 labels := make([]commonv1proto.KeyValue, 0, len(e.Labels))
397 for _, label := range e.Labels {
398 labels = append(labels,
399 commonv1proto.KeyValue{
400 Key: label.Name,
401 Value: label.Value.AsAnyValue(),
402 },
403 )
404 }
405
406 exemplars = append(exemplars, tempopb.Exemplar{
407 Labels: labels,

Calls 5

NewIntervalMapperFromReqFunction · 0.85
AsAnyValueMethod · 0.80
IntervalCountMethod · 0.65
TimestampOfMethod · 0.65
IntervalMsMethod · 0.65