Chore: Add grafana-apiserver (#70721)

* add grafana-apiserver
* remove watchset & move provisioning and http server to background
services
* remove scheme
* otel fixes (#70874)
* remove module ProvideRegistry test
* use certgenerator from apiserver package
* Control collector/pdata from going to v1.0.0-rc8 (as Tempo 1.5.1 would have it)
This commit is contained in:
Todd Treece
2023-07-14 12:22:10 -07:00
committed by GitHub
parent 8ced4343f3
commit 52121b7165
25 changed files with 690 additions and 838 deletions
+4 -4
View File
@@ -15,7 +15,7 @@
package tempo
import (
"go.opentelemetry.io/collector/model/pdata"
"go.opentelemetry.io/collector/pdata/ptrace"
)
// Some of the keys used to represent OTLP constructs as tags or annotations in other formats.
@@ -55,9 +55,9 @@ const (
// StatusCodeFromHTTP takes an HTTP status code and return the appropriate OpenTelemetry status code
// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#status
func StatusCodeFromHTTP(httpStatusCode int) pdata.StatusCode {
func StatusCodeFromHTTP(httpStatusCode int) ptrace.StatusCode {
if httpStatusCode >= 100 && httpStatusCode < 399 {
return pdata.StatusCodeUnset
return ptrace.StatusCodeUnset
}
return pdata.StatusCodeError
return ptrace.StatusCodeError
}
+32 -32
View File
@@ -7,7 +7,10 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/data"
"go.opentelemetry.io/collector/model/pdata"
semconv "go.opentelemetry.io/collector/model/semconv/v1.8.0"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.15.0"
)
type KeyValue struct {
@@ -27,7 +30,7 @@ type TraceReference struct {
Tags []*KeyValue `json:"tags"`
}
func TraceToFrame(td pdata.Traces) (*data.Frame, error) {
func TraceToFrame(td ptrace.Traces) (*data.Frame, error) {
// In open telemetry format the spans are grouped first by resource/service they originated in and inside that
// resource they are grouped by the instrumentation library which created them.
@@ -80,9 +83,9 @@ func TraceToFrame(td pdata.Traces) (*data.Frame, error) {
}
// resourceSpansToRows processes all the spans for a particular resource/service
func resourceSpansToRows(rs pdata.ResourceSpans) ([][]interface{}, error) {
func resourceSpansToRows(rs ptrace.ResourceSpans) ([][]interface{}, error) {
resource := rs.Resource()
ilss := rs.InstrumentationLibrarySpans()
ilss := rs.ScopeSpans()
if resource.Attributes().Len() == 0 || ilss.Len() == 0 {
return [][]interface{}{}, nil
@@ -100,7 +103,7 @@ func resourceSpansToRows(rs pdata.ResourceSpans) ([][]interface{}, error) {
for j := 0; j < spans.Len(); j++ {
span := spans.At(j)
row, err := spanToSpanRow(span, ils.InstrumentationLibrary(), resource)
row, err := spanToSpanRow(span, ils.Scope(), resource)
if err != nil {
return nil, err
}
@@ -113,7 +116,7 @@ func resourceSpansToRows(rs pdata.ResourceSpans) ([][]interface{}, error) {
return rows, nil
}
func spanToSpanRow(span pdata.Span, libraryTags pdata.InstrumentationLibrary, resource pdata.Resource) ([]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))
@@ -175,7 +178,7 @@ func spanToSpanRow(span pdata.Span, libraryTags pdata.InstrumentationLibrary, re
}, nil
}
func resourceToProcess(resource pdata.Resource) (string, []*KeyValue) {
func resourceToProcess(resource pcommon.Resource) (string, []*KeyValue) {
attrs := resource.Attributes()
serviceName := ResourceNoServiceName
if attrs.Len() == 0 {
@@ -183,8 +186,8 @@ func resourceToProcess(resource pdata.Resource) (string, []*KeyValue) {
}
tags := make([]*KeyValue, 0, attrs.Len()-1)
attrs.Range(func(key string, attr pdata.AttributeValue) bool {
if key == semconv.AttributeServiceName {
attrs.Range(func(key string, attr pcommon.Value) bool {
if attribute.Key(key) == semconv.ServiceNameKey {
serviceName = attr.StringVal()
}
tags = append(tags, &KeyValue{Key: key, Value: getAttributeVal(attr)})
@@ -194,44 +197,44 @@ func resourceToProcess(resource pdata.Resource) (string, []*KeyValue) {
return serviceName, tags
}
func getAttributeVal(attr pdata.AttributeValue) interface{} {
func getAttributeVal(attr pcommon.Value) interface{} {
switch attr.Type() {
case pdata.AttributeValueTypeString:
case pcommon.ValueTypeString:
return attr.StringVal()
case pdata.AttributeValueTypeInt:
case pcommon.ValueTypeInt:
return attr.IntVal()
case pdata.AttributeValueTypeBool:
case pcommon.ValueTypeBool:
return attr.BoolVal()
case pdata.AttributeValueTypeDouble:
case pcommon.ValueTypeDouble:
return attr.DoubleVal()
case pdata.AttributeValueTypeMap, pdata.AttributeValueTypeArray:
case pcommon.ValueTypeMap, pcommon.ValueTypeSlice:
return attr.AsString()
default:
return nil
}
}
func getSpanTags(span pdata.Span) []*KeyValue {
func getSpanTags(span ptrace.Span) []*KeyValue {
var tags []*KeyValue
span.Attributes().Range(func(key string, attr pdata.AttributeValue) bool {
span.Attributes().Range(func(key string, attr pcommon.Value) bool {
tags = append(tags, &KeyValue{Key: key, Value: getAttributeVal(attr)})
return true
})
return tags
}
func getSpanKind(spanKind pdata.SpanKind) string {
func getSpanKind(spanKind ptrace.SpanKind) string {
var tagStr string
switch spanKind {
case pdata.SpanKindClient:
case ptrace.SpanKindClient:
tagStr = string(OpenTracingSpanKindClient)
case pdata.SpanKindServer:
case ptrace.SpanKindServer:
tagStr = string(OpenTracingSpanKindServer)
case pdata.SpanKindProducer:
case ptrace.SpanKindProducer:
tagStr = string(OpenTracingSpanKindProducer)
case pdata.SpanKindConsumer:
case ptrace.SpanKindConsumer:
tagStr = string(OpenTracingSpanKindConsumer)
case pdata.SpanKindInternal:
case ptrace.SpanKindInternal:
tagStr = string(OpenTracingSpanKindInternal)
default:
return ""
@@ -240,14 +243,11 @@ func getSpanKind(spanKind pdata.SpanKind) string {
return tagStr
}
func getTraceState(traceState pdata.TraceState) string {
if traceState != pdata.TraceStateEmpty {
return string(traceState)
}
return ""
func getTraceState(traceState ptrace.TraceState) string {
return string(traceState)
}
func spanEventsToLogs(events pdata.SpanEventSlice) []*TraceLog {
func spanEventsToLogs(events ptrace.SpanEventSlice) []*TraceLog {
if events.Len() == 0 {
return nil
}
@@ -259,10 +259,10 @@ func spanEventsToLogs(events pdata.SpanEventSlice) []*TraceLog {
if event.Name() != "" {
fields = append(fields, &KeyValue{
Key: TagMessage,
Value: event.Name(),
Value: attribute.StringValue(event.Name()),
})
}
event.Attributes().Range(func(key string, attr pdata.AttributeValue) bool {
event.Attributes().Range(func(key string, attr pcommon.Value) bool {
fields = append(fields, &KeyValue{Key: key, Value: getAttributeVal(attr)})
return true
})
@@ -290,7 +290,7 @@ func spanLinksToReferences(links pdata.SpanLinkSlice) []*TraceReference {
spanId := link.SpanID().HexString()
tags := make([]*KeyValue, 0, link.Attributes().Len())
link.Attributes().Range(func(key string, attr pdata.AttributeValue) bool {
link.Attributes().Range(func(key string, attr pcommon.Value) bool {
tags = append(tags, &KeyValue{Key: key, Value: getAttributeVal(attr)})
return true
})
+10 -8
View File
@@ -5,15 +5,17 @@ import (
"os"
"testing"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/stretchr/testify/require"
otlp "go.opentelemetry.io/collector/model/otlp"
"go.opentelemetry.io/collector/model/pdata"
"go.opentelemetry.io/collector/model/otlp"
)
func TestTraceToFrame(t *testing.T) {
t.Run("should transform tempo protobuf response into dataframe", func(t *testing.T) {
// For what ever reason you cannot easily create pdata.Traces for the TraceToFrame from something more readable
// For what ever reason you cannot easily create ptrace.Traces for the TraceToFrame from something more readable
// like json. You could tediously create the structures manually using all the setters for everything or use
// https://github.com/grafana/tempo/tree/master/pkg/tempopb to create the protobuf structs from something like
// json. At the moment just saving some real tempo proto response into file and loading was the easiest and
@@ -60,14 +62,14 @@ func TestTraceToFrame(t *testing.T) {
require.NoError(t, err)
var index int
otTrace.ResourceSpans().RemoveIf(func(rsp pdata.ResourceSpans) bool {
rsp.InstrumentationLibrarySpans().RemoveIf(func(sp pdata.InstrumentationLibrarySpans) bool {
sp.Spans().RemoveIf(func(span pdata.Span) bool {
otTrace.ResourceSpans().RemoveIf(func(rsp ptrace.ResourceSpans) bool {
rsp.ScopeSpans().RemoveIf(func(sp ptrace.ScopeSpans) bool {
sp.Spans().RemoveIf(func(span ptrace.Span) bool {
if index == 0 {
span.SetTraceID(pdata.NewTraceID([16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}))
span.SetTraceID(pcommon.NewTraceID([16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}))
}
if index == 1 {
span.SetTraceID(pdata.NewTraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7}))
span.SetTraceID(pcommon.NewTraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7}))
}
index++
return false