Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade storage integration test to v2 Trace Reader #6388

Merged
merged 15 commits into from
Dec 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor storage integrationtest methods use v1adapters `PTracesSeq…
…2ToModel`

Signed-off-by: Emmanuel Emonueje Ebenezer <[email protected]>
ekefan committed Dec 25, 2024
commit 5c8bdb7997ab9f83eb55d144d80f3b1aebd8f86b
38 changes: 9 additions & 29 deletions plugin/storage/integration/integration.go
Original file line number Diff line number Diff line change
@@ -21,15 +21,14 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
otlp2jaeger "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger"

samplemodel "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/model"
"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/pkg/iter"
"github.com/jaegertracing/jaeger/storage/dependencystore"
"github.com/jaegertracing/jaeger/storage/samplingstore"
"github.com/jaegertracing/jaeger/storage/spanstore"
"github.com/jaegertracing/jaeger/storage_v2/tracestore"
"github.com/jaegertracing/jaeger/storage_v2/v1adapter"
)

//go:embed fixtures
@@ -161,15 +160,14 @@ func (s *StorageIntegration) testGetServices(t *testing.T) {
iterTraces := s.TraceReader.FindTraces(context.Background(), tracestore.TraceQueryParams{
ServiceName: service,
})
traces, err := iter.FlattenWithErrors(iterTraces)
traces, err := v1adapter.PTracesSeq2ToModel(iterTraces)
if err != nil {
t.Log(err)
continue
}
for _, trace := range traces {
spans := extractSpansFromTraces(trace)
for _, span := range spans {
t.Logf("span: Service: %s, TraceID: %s, Operation: %s", service, span.TraceID(), span.Name())
for _, span := range trace.Spans {
t.Logf("span: Service: %s, TraceID: %s, Operation: %s", service, span.TraceID, span.OperationName)
}
}
}
@@ -225,12 +223,8 @@ func (s *StorageIntegration) testGetLargeSpan(t *testing.T) {
found := s.waitForCondition(t, func(_ *testing.T) bool {
var err error
iterTraces := s.TraceReader.GetTraces(context.Background(), tracestore.GetTraceParams{TraceID: expectedOtelTraceID})
traces, err := iter.FlattenWithErrors(iterTraces)

batches := otlp2jaeger.ProtoFromTraces(traces[0])
for _, batch := range batches {
actual.Spans = append(actual.Spans, batch.Spans...)
}
traces, err := v1adapter.PTracesSeq2ToModel(iterTraces)
actual = traces[0]
return err == nil && len(actual.Spans) >= len(expected.Spans)
})

@@ -305,15 +299,11 @@ func (s *StorageIntegration) testGetTrace(t *testing.T) {
found := s.waitForCondition(t, func(t *testing.T) bool {
var err error
iterTraces := s.TraceReader.GetTraces(context.Background(), tracestore.GetTraceParams{TraceID: expectedOtelTraceID})
traces, err := iter.FlattenWithErrors(iterTraces)

batches := otlp2jaeger.ProtoFromTraces(traces[0])
for _, batch := range batches {
actual.Spans = append(actual.Spans, batch.Spans...)
}
traces, err := v1adapter.PTracesSeq2ToModel(iterTraces)
if err != nil {
t.Log(err)
}
actual = traces[0]
return err == nil && len(actual.Spans) == len(expected.Spans)
})
if !assert.True(t, found) {
@@ -367,21 +357,11 @@ func (s *StorageIntegration) findTracesByQuery(t *testing.T, query *tracestore.T
found := s.waitForCondition(t, func(t *testing.T) bool {
var err error
iterTraces := s.TraceReader.FindTraces(context.Background(), *query)
tracesFound, err := iter.FlattenWithErrors(iterTraces)
traces, err := v1adapter.PTracesSeq2ToModel(iterTraces)
if err != nil {
t.Log(err)
return false
}

for _, traceFound := range tracesFound {
modelTrace := &model.Trace{}
batches := otlp2jaeger.ProtoFromTraces(traceFound)
for _, batch := range batches {
modelTrace.Spans = append(modelTrace.Spans, batch.Spans...)
}
traces = append(traces, modelTrace)
}


if len(expected) != len(traces) {
t.Logf("Expecting certain number of traces: expected: %d, actual: %d", len(expected), len(traces))
34 changes: 5 additions & 29 deletions plugin/storage/integration/integration_v2.go
Original file line number Diff line number Diff line change
@@ -5,37 +5,13 @@
package integration

import (
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/jaegertracing/jaeger/storage_v2/tracestore"
)

// StorageIntegrationV2 performs same functions as StorageIntegration
//
// However StorageIntegrationV2 upgrades storage integration tests
// to storage v2 tests
type StorageIntegrationV2 struct {
TraceReader tracestore.Reader
}

// extractSpansFromTraces returns a slice of spans contained in one otel trace
func extractSpansFromTraces(traces ptrace.Traces) []ptrace.Span {
var allSpans []ptrace.Span

// Iterate through ResourceSpans
resourceSpans := traces.ResourceSpans()
for i := 0; i < resourceSpans.Len(); i++ {
resourceSpan := resourceSpans.At(i)

// Iterate through ScopeSpans within ResourceSpans
scopeSpans := resourceSpan.ScopeSpans()
for j := 0; j < scopeSpans.Len(); j++ {
scopeSpan := scopeSpans.At(j)

// Iterate through Spans within ScopeSpans
spans := scopeSpan.Spans()
for k := 0; k < spans.Len(); k++ {
span := spans.At(k)
allSpans = append(allSpans, span)
}
}
}

return allSpans
}
}