Skip to content

Commit

Permalink
Change testbed validator to use pdata (#2561)
Browse files Browse the repository at this point in the history
Added a TODO to fix the span links attributes and tracestate propagation when Jaeger is used.

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Apr 1, 2021
1 parent 4dcd2b8 commit f16bb4c
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 320 deletions.
2 changes: 1 addition & 1 deletion testbed/correctness/traces/correctness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func testWithTracingGoldenDataset(
factories, err := defaultcomponents.Components()
require.NoError(t, err, "default components resulted in: %v", err)
runner := testbed.NewInProcessCollector(factories)
validator := testbed.NewCorrectTestValidator(dataProvider)
validator := testbed.NewCorrectTestValidator(sender.ProtocolName(), receiver.ProtocolName(), dataProvider)
config := correctness.CreateConfigYaml(sender, receiver, processors, "traces")
configCleanup, cfgErr := runner.PrepareConfig(config)
require.NoError(t, cfgErr, "collector configuration resulted in: %v", cfgErr)
Expand Down
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"
"path/filepath"
Expand All @@ -33,7 +32,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 @@ -46,8 +44,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 @@ -166,11 +162,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 @@ -220,7 +211,6 @@ type GoldenDataProvider struct {

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

metricPairsFile string
metricsGenerated []pdata.Metrics
Expand Down Expand Up @@ -284,35 +274,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 @@ -397,11 +358,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 f16bb4c

Please sign in to comment.