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
+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
})