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

[es cit] Use storage factory instead of manual creation #5313

Merged
merged 28 commits into from
Apr 6, 2024
Merged
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5497453
Intialized ES factory
Wise-Wizard Mar 30, 2024
9f6fcf6
Merge branch 'main' into Test/ES_Factory
Wise-Wizard Mar 30, 2024
86cb9a6
Initialized with Viper
Wise-Wizard Mar 30, 2024
5b3d546
Debugging
Wise-Wizard Mar 30, 2024
56e025e
Debugging
Wise-Wizard Mar 30, 2024
ae967db
Debugging-3
Wise-Wizard Mar 30, 2024
0d44d41
Merge branch 'main' into Test/ES_Factory
Wise-Wizard Mar 31, 2024
1dc9cec
Initialized with ES Config
Wise-Wizard Apr 1, 2024
ceeafbc
Merge branch 'main' into Test/ES_Factory
Wise-Wizard Apr 1, 2024
21c464f
Initialized Configuration
Wise-Wizard Apr 1, 2024
c2aba8a
Merge branch 'main' into Test/ES_Factory
Wise-Wizard Apr 2, 2024
7e42382
Removed New Factory
Wise-Wizard Apr 2, 2024
71322ea
Fix Lint Errors
Wise-Wizard Apr 2, 2024
771cabe
Removed Unneccessary Initializations
Wise-Wizard Apr 2, 2024
ff5ce35
Merge branch 'main' into Test/ES_Factory
Wise-Wizard Apr 2, 2024
941647c
Merge branch 'main' into Test/ES_Factory
Wise-Wizard Apr 3, 2024
66e73de
Merge branch 'main' into Test/ES_Factory
Wise-Wizard Apr 4, 2024
823a144
Created a Dummy Fix to ES Factory
Wise-Wizard Apr 4, 2024
2c999fc
Fix Submodule
Wise-Wizard Apr 4, 2024
32262d4
Fix Lint
Wise-Wizard Apr 4, 2024
f691324
Fix failing CI
Wise-Wizard Apr 5, 2024
17f65c3
Merge branch 'main' into Test/ES_Factory
Wise-Wizard Apr 5, 2024
e906787
Added All Tags as Field Bool
Wise-Wizard Apr 5, 2024
a3f2e68
Added All Tags as Field Bool
Wise-Wizard Apr 5, 2024
45b1e59
Merge branch 'main' into Test/ES_Factory
Wise-Wizard Apr 5, 2024
9ff6012
Removed Comments
Wise-Wizard Apr 5, 2024
406985b
Merge branch 'Test/ES_Factory' of https://github.com/Wise-Wizard/jaeg…
Wise-Wizard Apr 5, 2024
2863e8d
simplify
yurishkuro Apr 6, 2024
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
160 changes: 92 additions & 68 deletions plugin/storage/integration/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,16 @@ import (
"github.com/olivere/elastic"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"

estemplate "github.com/jaegertracing/jaeger/pkg/es"
eswrapper "github.com/jaegertracing/jaeger/pkg/es/wrapper"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/storage/es"
"github.com/jaegertracing/jaeger/plugin/storage/es/dependencystore"
"github.com/jaegertracing/jaeger/plugin/storage/es/mappings"
"github.com/jaegertracing/jaeger/plugin/storage/es/samplingstore"
"github.com/jaegertracing/jaeger/plugin/storage/es/spanstore"
)

const (
Expand All @@ -56,6 +53,8 @@ const (
spanTemplateName = "jaeger-span"
serviceTemplateName = "jaeger-service"
dependenciesTemplateName = "jaeger-dependencies"
primaryNamespace = "es"
archiveNamespace = "es-archive"
)

type ESStorageIntegration struct {
Expand All @@ -67,19 +66,19 @@ type ESStorageIntegration struct {
logger *zap.Logger
}

func (s *ESStorageIntegration) tracerProvider() (trace.TracerProvider, *tracetest.InMemoryExporter, func()) {
exporter := tracetest.NewInMemoryExporter()
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithSyncer(exporter),
)
closer := func() {
if err := tp.Shutdown(context.Background()); err != nil {
s.logger.Error("failed to close tracer", zap.Error(err))
}
}
return tp, exporter, closer
}
// func (s *ESStorageIntegration) tracerProvider() (trace.TracerProvider, *tracetest.InMemoryExporter, func()) {
// exporter := tracetest.NewInMemoryExporter()
// tp := sdktrace.NewTracerProvider(
// sdktrace.WithSampler(sdktrace.AlwaysSample()),
// sdktrace.WithSyncer(exporter),
// )
// closer := func() {
// if err := tp.Shutdown(context.Background()); err != nil {
// s.logger.Error("failed to close tracer", zap.Error(err))
// }
// }
// return tp, exporter, closer
// }

func (s *ESStorageIntegration) getVersion() (uint, error) {
pingResult, _, err := s.client.Ping(queryURL).Do(context.Background())
Expand All @@ -105,14 +104,38 @@ func (s *ESStorageIntegration) initializeES(t *testing.T, allTagsAsFields bool)
elastic.SetSniff(false))
Wise-Wizard marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)
s.logger, _ = testutils.NewLogger()

s.client = rawClient
s.v8Client, err = elasticsearch8.NewClient(elasticsearch8.Config{
Addresses: []string{queryURL},
DiscoverNodesOnStart: false,
})
require.NoError(t, err)

// Initialize ES Factory
opts := es.NewOptions(primaryNamespace, archiveNamespace)
cfg := opts.Primary.Configuration

f, err := es.NewFactoryWithConfig(cfg, metrics.NullFactory, s.logger)
if err != nil {
return err
}
// Create Span Writer and Reader
s.SpanWriter, err = f.CreateSpanWriter()
if err != nil {
return err
}
s.SpanReader, err = f.CreateSpanReader()
if err != nil {
return err
}
s.ArchiveSpanWriter, err = f.CreateArchiveSpanWriter()
if err != nil {
return err
}
s.ArchiveSpanReader, err = f.CreateArchiveSpanReader()
if err != nil {
return err
}
s.initSpanstore(t, allTagsAsFields)
s.initSamplingStore(t)

Expand All @@ -124,6 +147,7 @@ func (s *ESStorageIntegration) initializeES(t *testing.T, allTagsAsFields bool)
// TODO: remove this flag after ES support returning spanKind when get operations
s.GetOperationsMissingSpanKind = true
s.SkipArchiveTest = false

return nil
}

Expand Down Expand Up @@ -178,61 +202,61 @@ func (s *ESStorageIntegration) initSpanstore(t *testing.T, allTagsAsFields bool)
IndexPrefix: indexPrefix,
UseILM: false,
}
spanMapping, serviceMapping, err := mappingBuilder.GetSpanServiceMappings()
require.NoError(t, err)
// spanMapping, serviceMapping, err := mappingBuilder.GetSpanServiceMappings()
// require.NoError(t, err)
clientFn := func() estemplate.Client { return client }

// Initializing Span Reader and Writer
w := spanstore.NewSpanWriter(
spanstore.SpanWriterParams{
Client: clientFn,
Logger: s.logger,
MetricsFactory: metrics.NullFactory,
IndexPrefix: indexPrefix,
AllTagsAsFields: allTagsAsFields,
TagDotReplacement: tagKeyDeDotChar,
Archive: false,
})
err = w.CreateTemplates(spanMapping, serviceMapping, indexPrefix)
require.NoError(t, err)
tracer, _, closer := s.tracerProvider()
defer closer()
s.SpanWriter = w
s.SpanReader = spanstore.NewSpanReader(spanstore.SpanReaderParams{
Client: clientFn,
Logger: s.logger,
MetricsFactory: metrics.NullFactory,
IndexPrefix: indexPrefix,
MaxSpanAge: maxSpanAge,
TagDotReplacement: tagKeyDeDotChar,
MaxDocCount: defaultMaxDocCount,
Tracer: tracer.Tracer("test"),
Archive: false,
})

// Initializing Archive Span Reader and Writer
s.ArchiveSpanWriter = spanstore.NewSpanWriter(
spanstore.SpanWriterParams{
Client: clientFn,
Logger: s.logger,
MetricsFactory: metrics.NullFactory,
IndexPrefix: indexPrefix,
AllTagsAsFields: allTagsAsFields,
TagDotReplacement: tagKeyDeDotChar,
Archive: true,
})
s.ArchiveSpanReader = spanstore.NewSpanReader(spanstore.SpanReaderParams{
Client: clientFn,
Logger: s.logger,
MetricsFactory: metrics.NullFactory,
IndexPrefix: indexPrefix,
MaxSpanAge: maxSpanAge,
TagDotReplacement: tagKeyDeDotChar,
MaxDocCount: defaultMaxDocCount,
Tracer: tracer.Tracer("test"),
Archive: true,
})
// w := spanstore.NewSpanWriter(
// spanstore.SpanWriterParams{
// Client: clientFn,
// Logger: s.logger,
// MetricsFactory: metrics.NullFactory,
// IndexPrefix: indexPrefix,
// AllTagsAsFields: allTagsAsFields,
// TagDotReplacement: tagKeyDeDotChar,
// Archive: false,
// })
// err = w.CreateTemplates(spanMapping, serviceMapping, indexPrefix)
// require.NoError(t, err)
// tracer, _, closer := s.tracerProvider()
// defer closer()
// s.SpanWriter = w
// s.SpanReader = spanstore.NewSpanReader(spanstore.SpanReaderParams{
// Client: clientFn,
// Logger: s.logger,
// MetricsFactory: metrics.NullFactory,
// IndexPrefix: indexPrefix,
// MaxSpanAge: maxSpanAge,
// TagDotReplacement: tagKeyDeDotChar,
// MaxDocCount: defaultMaxDocCount,
// Tracer: tracer.Tracer("test"),
// Archive: false,
// })

// Initializing Archive Span Reader and Writer
// s.ArchiveSpanWriter = spanstore.NewSpanWriter(
// spanstore.SpanWriterParams{
// Client: clientFn,
// Logger: s.logger,
// MetricsFactory: metrics.NullFactory,
// IndexPrefix: indexPrefix,
// AllTagsAsFields: allTagsAsFields,
// TagDotReplacement: tagKeyDeDotChar,
// Archive: true,
// })
// s.ArchiveSpanReader = spanstore.NewSpanReader(spanstore.SpanReaderParams{
// Client: clientFn,
// Logger: s.logger,
// MetricsFactory: metrics.NullFactory,
// IndexPrefix: indexPrefix,
// MaxSpanAge: maxSpanAge,
// TagDotReplacement: tagKeyDeDotChar,
// MaxDocCount: defaultMaxDocCount,
// Tracer: tracer.Tracer("test"),
// Archive: true,
// })
dependencyStore := dependencystore.NewDependencyStore(dependencystore.DependencyStoreParams{
Client: clientFn,
Logger: s.logger,
Expand Down
Loading