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

[storage] Simplify integration tests #5312

Merged
merged 5 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 17 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SHELL := /bin/bash
JAEGER_IMPORT_PATH = github.com/jaegertracing/jaeger
STORAGE_PKGS = ./plugin/storage/integration/...
JAEGER_STORAGE_PKGS = ./cmd/jaeger/internal/integration
JAEGER_V2_STORAGE_PKGS = ./cmd/jaeger/internal/integration

# These DOCKER_xxx vars are used when building Docker images.
DOCKER_NAMESPACE?=jaegertracing
Expand Down Expand Up @@ -57,6 +57,7 @@ GOARCH ?= $(shell $(GO) env GOARCH)
GOBUILD=CGO_ENABLED=0 installsuffix=cgo $(GO) build -trimpath
GOTEST_QUIET=$(GO) test $(RACE)
GOTEST=$(GOTEST_QUIET) -v
COVEROUT=cover.out
GOFMT=gofmt
GOFUMPT=gofumpt
FMT_LOG=.fmt.log
Expand Down Expand Up @@ -112,13 +113,6 @@ test:
all-in-one-integration-test:
TEST_MODE=integration $(GOTEST) ./cmd/all-in-one/

.PHONY: storage-integration-test
storage-integration-test:
# Expire tests results for storage integration tests since the environment might change
# even though the code remains the same.
go clean -testcache
bash -c "set -e; set -o pipefail; $(GOTEST) -coverpkg=./... -coverprofile cover.out $(STORAGE_PKGS) $(COLORIZE)"

# A general integration tests for jaeger-v2 storage backends,
# these tests placed at `./cmd/jaeger/internal/integration/*_test.go`.
# The integration tests are filtered by STORAGE env,
Expand All @@ -129,34 +123,37 @@ jaeger-storage-integration-test:
# Expire tests results for jaeger storage integration tests since the environment might change
# even though the code remains the same.
go clean -testcache
bash -c "set -e; set -o pipefail; $(GOTEST) -coverpkg=./... -coverprofile cover.out $(JAEGER_STORAGE_PKGS) $(COLORIZE)"
bash -c "set -e; set -o pipefail; $(GOTEST) -coverpkg=./... -coverprofile $(COVEROUT) $(JAEGER_V2_STORAGE_PKGS) $(COLORIZE)"

.PHONY: storage-integration-test
storage-integration-test:
# Expire tests results for storage integration tests since the environment might change
# even though the code remains the same.
go clean -testcache
bash -c "set -e; set -o pipefail; $(GOTEST) -coverpkg=./... -coverprofile $(COVEROUT) $(STORAGE_PKGS) $(COLORIZE)"

.PHONY: badger-storage-integration-test
badger-storage-integration-test:
bash -c "set -e; set -o pipefail; $(GOTEST) -tags=badger_storage_integration -coverpkg=./... -coverprofile cover.out $(STORAGE_PKGS) $(COLORIZE)"
STORAGE=badger $(MAKE) storage-integration-test

.PHONY: grpc-storage-integration-test
grpc-storage-integration-test:
(cd examples/memstore-plugin/ && go build .)
bash -c "set -e; set -o pipefail; $(GOTEST) -tags=grpc_storage_integration -coverpkg=./... -coverprofile cover.out $(STORAGE_PKGS) $(COLORIZE)"
STORAGE=grpc $(MAKE) storage-integration-test

# this test assumes STORAGE environment variable is set to elasticsearch|opensearch
.PHONY: index-cleaner-integration-test
index-cleaner-integration-test: docker-images-elastic
# Expire test results for storage integration tests since the environment might change
# even though the code remains the same.
go clean -testcache
bash -c "set -e; set -o pipefail; $(GOTEST) -tags index_cleaner -coverpkg=./... -coverprofile cover-index-cleaner.out $(STORAGE_PKGS) $(COLORIZE)"
$(MAKE) storage-integration-test COVEROUT=cover-index-cleaner.out

# this test assumes STORAGE environment variable is set to elasticsearch|opensearch
.PHONY: index-rollover-integration-test
index-rollover-integration-test: docker-images-elastic
# Expire test results for storage integration tests since the environment might change
# even though the code remains the same.
go clean -testcache
bash -c "set -e; set -o pipefail; $(GOTEST) -tags index_rollover -coverpkg=./... -coverprofile cover-index-rollover.out $(STORAGE_PKGS) $(COLORIZE)"
$(MAKE) storage-integration-test COVEROUT=cover-index-rollover.out

.PHONY: cover
cover: nocover
bash -c "set -e; set -o pipefail; $(GOTEST) -tags=memory_storage_integration -timeout 5m -coverprofile cover.out ./... | tee test-results.json"
bash -c "set -e; set -o pipefail; STORAGE=memory $(GOTEST) -timeout 5m -coverprofile $(COVEROUT) ./... | tee test-results.json"
go tool cover -html=cover.out -o cover.html

.PHONY: nocover
Expand Down
57 changes: 20 additions & 37 deletions plugin/storage/integration/badgerstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build badger_storage_integration
// +build badger_storage_integration

package integration

Expand All @@ -33,60 +31,45 @@ type BadgerIntegrationStorage struct {
factory *badger.Factory
}

func (s *BadgerIntegrationStorage) initialize() error {
func (s *BadgerIntegrationStorage) initialize(t *testing.T) {
s.factory = badger.NewFactory()

err := s.factory.Initialize(metrics.NullFactory, zap.NewNop())
if err != nil {
return err
}

sw, err := s.factory.CreateSpanWriter()
if err != nil {
return err
}
sr, err := s.factory.CreateSpanReader()
if err != nil {
return err
}
if s.SamplingStore, err = s.factory.CreateSamplingStore(0); err != nil {
return err
}

s.SpanReader = sr
s.SpanWriter = sw

s.Refresh = s.refresh
require.NoError(t, err)

s.SpanWriter, err = s.factory.CreateSpanWriter()
require.NoError(t, err)

s.SpanReader, err = s.factory.CreateSpanReader()
require.NoError(t, err)

s.SamplingStore, err = s.factory.CreateSamplingStore(0)
require.NoError(t, err)

s.Refresh = func(_ *testing.T) {}
s.CleanUp = s.cleanUp

logger, _ := testutils.NewLogger()
s.logger = logger
s.logger, _ = testutils.NewLogger()

// TODO: remove this badger supports returning spanKind from GetOperations
s.GetOperationsMissingSpanKind = true
s.SkipArchiveTest = true
return nil
}

func (s *BadgerIntegrationStorage) clear() error {
return s.factory.Close()
}

func (s *BadgerIntegrationStorage) cleanUp() error {
func (s *BadgerIntegrationStorage) cleanUp(t *testing.T) {
err := s.clear()
if err != nil {
return err
}
return s.initialize()
}

func (s *BadgerIntegrationStorage) refresh() error {
return nil
require.NoError(t, err)
s.initialize(t)
}

func TestBadgerStorage(t *testing.T) {
skipUnlessEnv(t, "badger")
s := &BadgerIntegrationStorage{}
require.NoError(t, s.initialize())
s.IntegrationTestAll(t)
s.initialize(t)
s.RunAll(t)
defer s.clear()
}
73 changes: 29 additions & 44 deletions plugin/storage/integration/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
package integration

import (
"errors"
"fmt"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -32,8 +29,6 @@ import (
"github.com/jaegertracing/jaeger/storage/dependencystore"
)

var errInitializeCassandraDependencyWriter = errors.New("failed to initialize cassandra dependency writer")

type CassandraStorageIntegration struct {
StorageIntegration

Expand All @@ -47,7 +42,7 @@ func newCassandraStorageIntegration() *CassandraStorageIntegration {
GetDependenciesReturnsSource: true,
SkipArchiveTest: true,

Refresh: func() error { return nil },
Refresh: func(_ *testing.T) {},
SkipList: []string{
"Tags_+_Operation_name_+_Duration_range",
"Tags_+_Duration_range",
Expand All @@ -64,68 +59,58 @@ func newCassandraStorageIntegration() *CassandraStorageIntegration {
return s
}

func (s *CassandraStorageIntegration) cleanUp() error {
return s.session.Query("TRUNCATE traces").Exec()
func (s *CassandraStorageIntegration) cleanUp(t *testing.T) {
require.NoError(t, s.session.Query("TRUNCATE traces").Exec())
}

func (s *CassandraStorageIntegration) initializeCassandraFactory(flags []string) (*cassandra.Factory, error) {
func (s *CassandraStorageIntegration) initializeCassandraFactory(t *testing.T, flags []string) *cassandra.Factory {
s.logger, _ = testutils.NewLogger()
f := cassandra.NewFactory()
v, command := config.Viperize(f.AddFlags)
if err := command.ParseFlags(flags); err != nil {
return nil, fmt.Errorf("unable to parse flags: %w", err)
{
err := command.ParseFlags(flags)
require.NoError(t, err)
}
f.InitFromViper(v, zap.NewNop())
if err := f.Initialize(metrics.NullFactory, s.logger); err != nil {
return nil, err
{
err := f.Initialize(metrics.NullFactory, s.logger)
require.NoError(t, err)
}
return f, nil
return f
}

func (s *CassandraStorageIntegration) initializeCassandra() error {
f, err := s.initializeCassandraFactory([]string{
func (s *CassandraStorageIntegration) initializeCassandra(t *testing.T) {
f := s.initializeCassandraFactory(t, []string{
"--cassandra.keyspace=jaeger_v1_dc1",
})
if err != nil {
return err
}
s.session = f.PrimarySession()
if s.SpanWriter, err = f.CreateSpanWriter(); err != nil {
return err
}
if s.SpanReader, err = f.CreateSpanReader(); err != nil {
return err
}
if s.SamplingStore, err = f.CreateSamplingStore(0); err != nil {
return err
}

if err = s.initializeDependencyReaderAndWriter(f); err != nil {
return err
}
return nil
var err error
s.SpanWriter, err = f.CreateSpanWriter()
require.NoError(t, err)
s.SpanReader, err = f.CreateSpanReader()
require.NoError(t, err)
s.SamplingStore, err = f.CreateSamplingStore(0)
require.NoError(t, err)
s.initializeDependencyReaderAndWriter(t, f)
}

func (s *CassandraStorageIntegration) initializeDependencyReaderAndWriter(f *cassandra.Factory) error {
func (s *CassandraStorageIntegration) initializeDependencyReaderAndWriter(t *testing.T, f *cassandra.Factory) {
var (
err error
ok bool
)
if s.DependencyReader, err = f.CreateDependencyReader(); err != nil {
return err
}
s.DependencyReader, err = f.CreateDependencyReader()
require.NoError(t, err)

// TODO: Update this when the factory interface has CreateDependencyWriter
if s.DependencyWriter, ok = s.DependencyReader.(dependencystore.Writer); !ok {
return errInitializeCassandraDependencyWriter
t.Log("DependencyWriter not implemented ")
}
return nil
}

func TestCassandraStorage(t *testing.T) {
if os.Getenv("STORAGE") != "cassandra" {
t.Skip("Integration test against Cassandra skipped; set STORAGE env var to cassandra to run this")
}
skipUnlessEnv(t, "cassandra")
s := newCassandraStorageIntegration()
require.NoError(t, s.initializeCassandra())
s.IntegrationTestAll(t)
s.initializeCassandra(t)
s.RunAll(t)
}
22 changes: 7 additions & 15 deletions plugin/storage/integration/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"errors"
"net/http"
"os"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -117,9 +116,8 @@ func (s *ESStorageIntegration) initializeES(t *testing.T, allTagsAsFields bool)
s.initSpanstore(t, allTagsAsFields)
s.initSamplingStore(t)

s.CleanUp = func() error {
s.CleanUp = func(t *testing.T) {
s.esCleanUp(t, allTagsAsFields)
return nil
}
s.Refresh = s.esRefresh
s.esCleanUp(t, allTagsAsFields)
Expand Down Expand Up @@ -252,13 +250,11 @@ func (s *ESStorageIntegration) initSpanstore(t *testing.T, allTagsAsFields bool)
return nil
}

func (s *ESStorageIntegration) esRefresh() error {
func (s *ESStorageIntegration) esRefresh(t *testing.T) {
err := s.bulkProcessor.Flush()
if err != nil {
return err
}
require.NoError(t, err)
_, err = s.client.Refresh().Do(context.Background())
return err
require.NoError(t, err)
}

func healthCheck() error {
Expand All @@ -272,9 +268,7 @@ func healthCheck() error {
}

func testElasticsearchStorage(t *testing.T, allTagsAsFields bool) {
if os.Getenv("STORAGE") != "elasticsearch" && os.Getenv("STORAGE") != "opensearch" {
t.Skip("Integration test against ElasticSearch skipped; set STORAGE env var to elasticsearch to run this")
}
skipUnlessEnv(t, "elasticsearch", "opensearch")
if err := healthCheck(); err != nil {
t.Fatal(err)
}
Expand All @@ -283,7 +277,7 @@ func testElasticsearchStorage(t *testing.T, allTagsAsFields bool) {

s.Fixtures = LoadAndParseQueryTestCases(t, "fixtures/queries_es.json")

s.IntegrationTestAll(t)
s.RunAll(t)
}

func TestElasticsearchStorage(t *testing.T) {
Expand All @@ -295,9 +289,7 @@ func TestElasticsearchStorage_AllTagsAsObjectFields(t *testing.T) {
}

func TestElasticsearchStorage_IndexTemplates(t *testing.T) {
if os.Getenv("STORAGE") != "elasticsearch" {
t.Skip("Integration test against ElasticSearch skipped; set STORAGE env var to elasticsearch to run this")
}
skipUnlessEnv(t, "elasticsearch", "opensearch")
if err := healthCheck(); err != nil {
t.Fatal(err)
}
Expand Down
Loading
Loading