mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tempo: remove deprecated model package usage (remove replace) (#71687)
* Tempo: remove deprecated model package usage (remove replace) * fix root test
This commit is contained in:
parent
4a59022fe8
commit
614f1af190
3
go.mod
3
go.mod
@ -25,8 +25,6 @@ replace go.opentelemetry.io/otel/trace => go.opentelemetry.io/otel/trace v1.16.0
|
||||
|
||||
replace go.opentelemetry.io/otel/metric => go.opentelemetry.io/otel/metric v1.16.0 // @grafana/backend-platform
|
||||
|
||||
replace go.opentelemetry.io/collector/pdata => go.opentelemetry.io/collector/pdata v0.50.0 // @grafana/backend-platform
|
||||
|
||||
// Override Prometheus version because Prometheus v2.X is tagged as v0.X for Go modules purposes and Go assumes
|
||||
// that v1.Y is higher than v0.X, so when we resolve dependencies if any dependency imports v1.Y we'd
|
||||
// import that instead of v0.X even though v0.X is newer.
|
||||
@ -105,7 +103,6 @@ require (
|
||||
github.com/vectordotdev/go-datemath v0.1.1-0.20220323213446-f3954d0b18ae // @grafana/backend-platform
|
||||
github.com/yalue/merged_fs v1.2.2 // @grafana/grafana-as-code
|
||||
github.com/yudai/gojsondiff v1.0.0 // @grafana/backend-platform
|
||||
go.opentelemetry.io/collector/model v0.50.0 // @grafana/backend-platform
|
||||
go.opentelemetry.io/collector/pdata v1.0.0-rc8 // @grafana/backend-platform
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.37.0 // @grafana/grafana-operator-experience-squad
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.10.0 // @grafana/backend-platform
|
||||
|
6
go.sum
6
go.sum
@ -2470,10 +2470,8 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
|
||||
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
|
||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||
go.opentelemetry.io/collector/model v0.50.0 h1:1wt8pQ4O6GaUeYEaR+dh3zHmYsFicduF2bbPGMZeSKk=
|
||||
go.opentelemetry.io/collector/model v0.50.0/go.mod h1:vKpC0JMtrL7g9tUHmzcQqd8rEbnahKVdTWZSVO7x3Ms=
|
||||
go.opentelemetry.io/collector/pdata v0.50.0 h1:pXDzXJTze0KqO47BASmKurOIkddk5j4tBLI2cQ94mWg=
|
||||
go.opentelemetry.io/collector/pdata v0.50.0/go.mod h1:jrnUDnlHCTSKf9H7LYTmldQUmNQmPvilNNG/cKlv8Lc=
|
||||
go.opentelemetry.io/collector/pdata v1.0.0-rc8 h1:vBikWdZFsRiT5dVsLQhnE99w3edM7eem3Q9dSqMlStE=
|
||||
go.opentelemetry.io/collector/pdata v1.0.0-rc8/go.mod h1:BVCBhWgclYCh7Oi6BkMiQfRa6MXv1uRTlKXuL5oBby8=
|
||||
go.opentelemetry.io/contrib v0.18.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0 h1:ZOLJc06r4CB42laIXg/7udr0pbZyuAihN10A/XuiQRY=
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0/go.mod h1:5z+/ZWJQKXa9YT34fQNx5K8Hd1EoIhvtUygUQPqEOgQ=
|
||||
|
@ -5,13 +5,13 @@ as soon as we can use agent as a dependency this can be refactored
|
||||
package frontendlogging
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
om "github.com/wk8/go-ordered-map"
|
||||
"go.opentelemetry.io/collector/model/otlp"
|
||||
"go.opentelemetry.io/collector/pdata/pcommon"
|
||||
"go.opentelemetry.io/collector/pdata/ptrace"
|
||||
)
|
||||
@ -148,7 +148,7 @@ type Traces struct {
|
||||
|
||||
// UnmarshalJSON unmarshals Traces model.
|
||||
func (t *Traces) UnmarshalJSON(b []byte) error {
|
||||
unmarshaler := otlp.NewJSONTracesUnmarshaler()
|
||||
unmarshaler := ptrace.JSONUnmarshaler{}
|
||||
td, err := unmarshaler.UnmarshalTraces(b)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -159,7 +159,7 @@ func (t *Traces) UnmarshalJSON(b []byte) error {
|
||||
|
||||
// MarshalJSON marshals Traces model to json.
|
||||
func (t Traces) MarshalJSON() ([]byte, error) {
|
||||
marshaler := otlp.NewJSONTracesMarshaler()
|
||||
marshaler := ptrace.JSONMarshaler{}
|
||||
return marshaler.MarshalTraces(t.Traces)
|
||||
}
|
||||
|
||||
@ -182,6 +182,15 @@ func (t Traces) SpanSlice() []ptrace.Span {
|
||||
|
||||
// SpanToKeyVal returns KeyVal representation of a Span.
|
||||
func SpanToKeyVal(s ptrace.Span) *KeyVal {
|
||||
traceID := s.TraceID()
|
||||
traceIDHex := hex.EncodeToString(traceID[:])
|
||||
|
||||
spanID := s.SpanID()
|
||||
spanIDHex := hex.EncodeToString(spanID[:])
|
||||
|
||||
parentSpanID := s.ParentSpanID()
|
||||
parentSpanIDHex := hex.EncodeToString(parentSpanID[:])
|
||||
|
||||
kv := NewKeyVal()
|
||||
if s.StartTimestamp() > 0 {
|
||||
KeyValAdd(kv, "timestamp", s.StartTimestamp().AsTime().String())
|
||||
@ -190,11 +199,11 @@ func SpanToKeyVal(s ptrace.Span) *KeyVal {
|
||||
KeyValAdd(kv, "end_timestamp", s.StartTimestamp().AsTime().String())
|
||||
}
|
||||
KeyValAdd(kv, "kind", "span")
|
||||
KeyValAdd(kv, "traceID", s.TraceID().HexString())
|
||||
KeyValAdd(kv, "spanID", s.SpanID().HexString())
|
||||
KeyValAdd(kv, "traceID", traceIDHex)
|
||||
KeyValAdd(kv, "spanID", spanIDHex)
|
||||
KeyValAdd(kv, "span_kind", s.Kind().String())
|
||||
KeyValAdd(kv, "name", s.Name())
|
||||
KeyValAdd(kv, "parent_spanID", s.ParentSpanID().HexString())
|
||||
KeyValAdd(kv, "parent_spanID", parentSpanIDHex)
|
||||
s.Attributes().Range(func(k string, v pcommon.Value) bool {
|
||||
KeyValAdd(kv, "attr_"+k, fmt.Sprintf("%v", v))
|
||||
return true
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/grafana/grafana/pkg/tsdb/tempo/kinds/dataquery"
|
||||
"go.opentelemetry.io/collector/model/otlp"
|
||||
"go.opentelemetry.io/collector/pdata/ptrace"
|
||||
)
|
||||
|
||||
func (s *Service) getTrace(ctx context.Context, pCtx backend.PluginContext, query backend.DataQuery) (*backend.DataResponse, error) {
|
||||
@ -54,7 +54,8 @@ func (s *Service) getTrace(ctx context.Context, pCtx backend.PluginContext, quer
|
||||
return result, nil
|
||||
}
|
||||
|
||||
otTrace, err := otlp.NewProtobufTracesUnmarshaler().UnmarshalTraces(body)
|
||||
pbUnmarshaler := ptrace.ProtoUnmarshaler{}
|
||||
otTrace, err := pbUnmarshaler.UnmarshalTraces(body)
|
||||
|
||||
if err != nil {
|
||||
return &backend.DataResponse{}, fmt.Errorf("failed to convert tempo response to Otlp: %w", err)
|
||||
|
@ -1,12 +1,12 @@
|
||||
package tempo
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"go.opentelemetry.io/collector/model/pdata"
|
||||
"go.opentelemetry.io/collector/pdata/pcommon"
|
||||
"go.opentelemetry.io/collector/pdata/ptrace"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
@ -118,12 +118,16 @@ func resourceSpansToRows(rs ptrace.ResourceSpans) ([][]interface{}, error) {
|
||||
|
||||
func spanToSpanRow(span ptrace.Span, libraryTags pcommon.InstrumentationScope, resource pcommon.Resource) ([]interface{}, error) {
|
||||
// If the id representation changed from hexstring to something else we need to change the transformBase64IDToHexString in the frontend code
|
||||
traceID := span.TraceID().HexString()
|
||||
traceID = strings.TrimPrefix(traceID, strings.Repeat("0", 16))
|
||||
traceID := span.TraceID()
|
||||
traceIDHex := hex.EncodeToString(traceID[:])
|
||||
traceIDHex = strings.TrimPrefix(traceIDHex, strings.Repeat("0", 16))
|
||||
|
||||
spanID := span.SpanID().HexString()
|
||||
spanID := span.SpanID()
|
||||
spanIDHex := hex.EncodeToString(spanID[:])
|
||||
|
||||
parentSpanID := span.ParentSpanID()
|
||||
parentSpanIDHex := hex.EncodeToString(parentSpanID[:])
|
||||
|
||||
parentSpanID := span.ParentSpanID().HexString()
|
||||
startTime := float64(span.StartTimestamp()) / 1_000_000
|
||||
serviceName, serviceTags := resourceToProcess(resource)
|
||||
|
||||
@ -158,9 +162,9 @@ func spanToSpanRow(span ptrace.Span, libraryTags pcommon.InstrumentationScope, r
|
||||
|
||||
// Order matters (look at dataframe order)
|
||||
return []interface{}{
|
||||
traceID,
|
||||
spanID,
|
||||
parentSpanID,
|
||||
traceIDHex,
|
||||
spanIDHex,
|
||||
parentSpanIDHex,
|
||||
span.Name(),
|
||||
serviceName,
|
||||
getSpanKind(span.Kind()),
|
||||
@ -188,7 +192,7 @@ func resourceToProcess(resource pcommon.Resource) (string, []*KeyValue) {
|
||||
tags := make([]*KeyValue, 0, attrs.Len()-1)
|
||||
attrs.Range(func(key string, attr pcommon.Value) bool {
|
||||
if attribute.Key(key) == semconv.ServiceNameKey {
|
||||
serviceName = attr.StringVal()
|
||||
serviceName = attr.Str()
|
||||
}
|
||||
tags = append(tags, &KeyValue{Key: key, Value: getAttributeVal(attr)})
|
||||
return true
|
||||
@ -199,14 +203,14 @@ func resourceToProcess(resource pcommon.Resource) (string, []*KeyValue) {
|
||||
|
||||
func getAttributeVal(attr pcommon.Value) interface{} {
|
||||
switch attr.Type() {
|
||||
case pcommon.ValueTypeString:
|
||||
return attr.StringVal()
|
||||
case pcommon.ValueTypeStr:
|
||||
return attr.Str()
|
||||
case pcommon.ValueTypeInt:
|
||||
return attr.IntVal()
|
||||
return attr.Int()
|
||||
case pcommon.ValueTypeBool:
|
||||
return attr.BoolVal()
|
||||
return attr.Bool()
|
||||
case pcommon.ValueTypeDouble:
|
||||
return attr.DoubleVal()
|
||||
return attr.Double()
|
||||
case pcommon.ValueTypeMap, pcommon.ValueTypeSlice:
|
||||
return attr.AsString()
|
||||
default:
|
||||
@ -243,8 +247,8 @@ func getSpanKind(spanKind ptrace.SpanKind) string {
|
||||
return tagStr
|
||||
}
|
||||
|
||||
func getTraceState(traceState ptrace.TraceState) string {
|
||||
return string(traceState)
|
||||
func getTraceState(traceState pcommon.TraceState) string {
|
||||
return traceState.AsRaw()
|
||||
}
|
||||
|
||||
func spanEventsToLogs(events ptrace.SpanEventSlice) []*TraceLog {
|
||||
@ -275,7 +279,7 @@ func spanEventsToLogs(events ptrace.SpanEventSlice) []*TraceLog {
|
||||
return logs
|
||||
}
|
||||
|
||||
func spanLinksToReferences(links pdata.SpanLinkSlice) []*TraceReference {
|
||||
func spanLinksToReferences(links ptrace.SpanLinkSlice) []*TraceReference {
|
||||
if links.Len() == 0 {
|
||||
return nil
|
||||
}
|
||||
@ -284,10 +288,12 @@ func spanLinksToReferences(links pdata.SpanLinkSlice) []*TraceReference {
|
||||
for i := 0; i < links.Len(); i++ {
|
||||
link := links.At(i)
|
||||
|
||||
traceId := link.TraceID().HexString()
|
||||
traceId = strings.TrimLeft(traceId, "0")
|
||||
traceID := link.TraceID()
|
||||
traceIDHex := hex.EncodeToString(traceID[:])
|
||||
traceIDHex = strings.TrimLeft(traceIDHex, "0")
|
||||
|
||||
spanId := link.SpanID().HexString()
|
||||
spanID := link.SpanID()
|
||||
spanIDHex := hex.EncodeToString(spanID[:])
|
||||
|
||||
tags := make([]*KeyValue, 0, link.Attributes().Len())
|
||||
link.Attributes().Range(func(key string, attr pcommon.Value) bool {
|
||||
@ -296,8 +302,8 @@ func spanLinksToReferences(links pdata.SpanLinkSlice) []*TraceReference {
|
||||
})
|
||||
|
||||
references = append(references, &TraceReference{
|
||||
TraceID: traceId,
|
||||
SpanID: spanId,
|
||||
TraceID: traceIDHex,
|
||||
SpanID: spanIDHex,
|
||||
Tags: tags,
|
||||
})
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.opentelemetry.io/collector/model/otlp"
|
||||
)
|
||||
|
||||
func TestTraceToFrame(t *testing.T) {
|
||||
@ -23,7 +22,8 @@ func TestTraceToFrame(t *testing.T) {
|
||||
proto, err := os.ReadFile("testData/tempo_proto_response")
|
||||
require.NoError(t, err)
|
||||
|
||||
otTrace, err := otlp.NewProtobufTracesUnmarshaler().UnmarshalTraces(proto)
|
||||
pbUnmarshaler := ptrace.ProtoUnmarshaler{}
|
||||
otTrace, err := pbUnmarshaler.UnmarshalTraces(proto)
|
||||
require.NoError(t, err)
|
||||
|
||||
frame, err := TraceToFrame(otTrace)
|
||||
@ -58,7 +58,8 @@ func TestTraceToFrame(t *testing.T) {
|
||||
proto, err := os.ReadFile("testData/tempo_proto_response")
|
||||
require.NoError(t, err)
|
||||
|
||||
otTrace, err := otlp.NewProtobufTracesUnmarshaler().UnmarshalTraces(proto)
|
||||
pbUnmarshaler := ptrace.ProtoUnmarshaler{}
|
||||
otTrace, err := pbUnmarshaler.UnmarshalTraces(proto)
|
||||
require.NoError(t, err)
|
||||
|
||||
var index int
|
||||
@ -66,10 +67,10 @@ func TestTraceToFrame(t *testing.T) {
|
||||
rsp.ScopeSpans().RemoveIf(func(sp ptrace.ScopeSpans) bool {
|
||||
sp.Spans().RemoveIf(func(span ptrace.Span) bool {
|
||||
if index == 0 {
|
||||
span.SetTraceID(pcommon.NewTraceID([16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}))
|
||||
span.SetTraceID(pcommon.TraceID([16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}))
|
||||
}
|
||||
if index == 1 {
|
||||
span.SetTraceID(pcommon.NewTraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7}))
|
||||
span.SetTraceID(pcommon.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7}))
|
||||
}
|
||||
index++
|
||||
return false
|
||||
@ -125,7 +126,7 @@ func (f *BetterFrame) FindRowWithValue(fieldName string, value interface{}) Row
|
||||
}
|
||||
|
||||
func rootSpan(frame *BetterFrame) Row {
|
||||
return frame.FindRowWithValue("parentSpanID", "")
|
||||
return frame.FindRowWithValue("parentSpanID", "0000000000000000")
|
||||
}
|
||||
|
||||
func fieldNames(frame *data.Frame) []string {
|
||||
|
Loading…
Reference in New Issue
Block a user