Skip to content

Commit

Permalink
Change testbed validator to use pdata
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Mar 23, 2021
1 parent 3660f5c commit fa5e4bb
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 310 deletions.
44 changes: 0 additions & 44 deletions testbed/testbed/data_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package testbed

import (
"encoding/binary"
"fmt"
"log"
"os"
"strconv"
Expand All @@ -32,7 +31,6 @@ import (
otlplogscol "go.opentelemetry.io/collector/internal/data/protogen/collector/logs/v1"
otlpmetricscol "go.opentelemetry.io/collector/internal/data/protogen/collector/metrics/v1"
otlptracecol "go.opentelemetry.io/collector/internal/data/protogen/collector/trace/v1"
otlptrace "go.opentelemetry.io/collector/internal/data/protogen/trace/v1"
"go.opentelemetry.io/collector/internal/goldendataset"
)

Expand All @@ -45,8 +43,6 @@ type DataProvider interface {
GenerateTraces() (pdata.Traces, bool)
// GenerateMetrics returns an internal MetricData instance with an OTLP ResourceMetrics slice of test data.
GenerateMetrics() (pdata.Metrics, bool)
// GetGeneratedSpan returns the generated Span matching the provided traceId and spanId or else nil if no match found.
GetGeneratedSpan(traceID pdata.TraceID, spanID pdata.SpanID) *otlptrace.Span
// GenerateLogs returns the internal pdata.Logs format
GenerateLogs() (pdata.Logs, bool)
}
Expand Down Expand Up @@ -165,11 +161,6 @@ func (dp *PerfTestDataProvider) GenerateMetrics() (pdata.Metrics, bool) {
return md, false
}

func (dp *PerfTestDataProvider) GetGeneratedSpan(pdata.TraceID, pdata.SpanID) *otlptrace.Span {
// function not supported for this data provider
return nil
}

func (dp *PerfTestDataProvider) GenerateLogs() (pdata.Logs, bool) {
logs := pdata.NewLogs()
logs.ResourceLogs().Resize(1)
Expand Down Expand Up @@ -219,7 +210,6 @@ type GoldenDataProvider struct {

tracesGenerated []pdata.Traces
tracesIndex int
spansMap map[string]*otlptrace.Span

metricPairsFile string
metricsGenerated []pdata.Metrics
Expand Down Expand Up @@ -283,35 +273,6 @@ func (dp *GoldenDataProvider) GenerateLogs() (pdata.Logs, bool) {
return pdata.NewLogs(), true
}

func (dp *GoldenDataProvider) GetGeneratedSpan(traceID pdata.TraceID, spanID pdata.SpanID) *otlptrace.Span {
if dp.spansMap == nil {
var resourceSpansList []*otlptrace.ResourceSpans
for _, td := range dp.tracesGenerated {
resourceSpansList = append(resourceSpansList, internal.TracesToOtlp(td.InternalRep()).ResourceSpans...)
}
dp.spansMap = populateSpansMap(resourceSpansList)
}
key := traceIDAndSpanIDToString(traceID, spanID)
return dp.spansMap[key]
}

func populateSpansMap(resourceSpansList []*otlptrace.ResourceSpans) map[string]*otlptrace.Span {
spansMap := make(map[string]*otlptrace.Span)
for _, resourceSpans := range resourceSpansList {
for _, libSpans := range resourceSpans.InstrumentationLibrarySpans {
for _, span := range libSpans.Spans {
key := traceIDAndSpanIDToString(pdata.TraceID(span.TraceId), pdata.SpanID(span.SpanId))
spansMap[key] = span
}
}
}
return spansMap
}

func traceIDAndSpanIDToString(traceID pdata.TraceID, spanID pdata.SpanID) string {
return fmt.Sprintf("%s-%s", traceID.HexString(), spanID.HexString())
}

// FileDataProvider in an implementation of the DataProvider for use in performance tests.
// The data to send is loaded from a file. The file should contain one JSON-encoded
// Export*ServiceRequest Protobuf message. The file can be recorded using the "file"
Expand Down Expand Up @@ -396,11 +357,6 @@ func (dp *FileDataProvider) GenerateMetrics() (pdata.Metrics, bool) {
return md, false
}

func (dp *FileDataProvider) GetGeneratedSpan(pdata.TraceID, pdata.SpanID) *otlptrace.Span {
// Nothing to do. This function is only used by data providers used in correctness tests for traces.
return nil
}

func (dp *FileDataProvider) GenerateLogs() (pdata.Logs, bool) {
// TODO: implement similar to GenerateMetrics.
return pdata.NewLogs(), true
Expand Down
Loading

0 comments on commit fa5e4bb

Please sign in to comment.