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

[jaeger-v2] Add support for Cassandra #5253

Merged
merged 14 commits into from
Mar 16, 2024
Prev Previous commit
Next Next commit
removing unit tests
Signed-off-by: Pushkar Mishra <[email protected]>
Pushkarm029 committed Mar 8, 2024

Verified

This commit was signed with the committer’s verified signature.
targos Michaël Zasso
commit 991d4c0d106110706c644241f3ae9f5bd4385aae
58 changes: 0 additions & 58 deletions cmd/jaeger/internal/extension/jaegerstorage/extension_test.go
Original file line number Diff line number Diff line change
@@ -6,13 +6,9 @@ package jaegerstorage
import (
"context"
"fmt"
"net"
"net/http"
"net/http/httptest"
"strconv"
"sync"
"testing"
"time"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
@@ -22,7 +18,6 @@ import (
nooptrace "go.opentelemetry.io/otel/trace/noop"
"go.uber.org/zap"

cassandraCfg "github.com/jaegertracing/jaeger/pkg/cassandra/config"
esCfg "github.com/jaegertracing/jaeger/pkg/es/config"
memoryCfg "github.com/jaegertracing/jaeger/pkg/memory/config"
"github.com/jaegertracing/jaeger/pkg/metrics"
@@ -199,59 +194,6 @@ func TestESStorageExtensionError(t *testing.T) {
require.ErrorContains(t, err, "badurl")
}

func TestCassandraExtension(t *testing.T) {
mockServerResponse := []byte{}
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

var wg sync.WaitGroup
wg.Add(1)

go func() {
defer wg.Done()
conn, err := listener.Accept()
require.NoError(t, err)
defer conn.Close()

_, err = conn.Write(mockServerResponse)
require.NoError(t, err)
}()
serverURL := listener.Addr().String()
link, portStr, err := net.SplitHostPort(serverURL)
require.NoError(t, err)
port, err := strconv.Atoi(portStr)
require.NoError(t, err)

storageExtension := makeStorageExtenion(t, &Config{
Cassandra: map[string]cassandraCfg.Configuration{
"foo": {
Servers: []string{link},
Keyspace: "test",
ConnectTimeout: 10 * time.Second,
ProtoVersion: 4,
Port: port,
},
},
})
ctx := context.Background()
err = storageExtension.Start(ctx, componenttest.NewNopHost())
require.NoError(t, err)
require.NoError(t, storageExtension.Shutdown(ctx))
}

func TestCassandraExtensionError(t *testing.T) {
ext := makeStorageExtenion(t, &Config{
Cassandra: map[string]cassandraCfg.Configuration{
"foo": {
Servers: []string{"http://badurl"},
},
},
})
err := ext.Start(context.Background(), componenttest.NewNopHost())
require.ErrorContains(t, err, "failed to initialize cassandra storage foo: gocql: unable to create session: strconv.Atoi: parsing \"//badurl\": invalid syntax")
require.ErrorContains(t, err, "badurl")
}

func noopTelemetrySettings() component.TelemetrySettings {
return component.TelemetrySettings{
Logger: zap.L(),
83 changes: 0 additions & 83 deletions plugin/storage/cassandra/factory_test.go
Original file line number Diff line number Diff line change
@@ -17,19 +17,14 @@ package cassandra

import (
"errors"
"net"
"strconv"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/pkg/cassandra"
cassandraCfg "github.com/jaegertracing/jaeger/pkg/cassandra/config"
"github.com/jaegertracing/jaeger/pkg/cassandra/mocks"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/metrics"
@@ -202,81 +197,3 @@ func TestInitFromOptions(t *testing.T) {
assert.Equal(t, o.GetPrimary(), f.primaryConfig)
assert.Equal(t, o.Get(archiveStorageConfig), f.archiveConfig)
}

func TestCassandraStorageFactoryWithConfig(t *testing.T) {
mockServerResponse := []byte{}
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)

var wg sync.WaitGroup
wg.Add(1)

go func() {
defer wg.Done()
conn, err := listener.Accept()
require.NoError(t, err)
defer conn.Close()

_, err = conn.Write(mockServerResponse)
require.NoError(t, err)
}()
serverURL := listener.Addr().String()
link, portStr, err := net.SplitHostPort(serverURL)
require.NoError(t, err)
port, err := strconv.Atoi(portStr)
require.NoError(t, err)
cfg := cassandraCfg.Configuration{
Servers: []string{link},
Keyspace: "test",
ConnectTimeout: 10 * time.Second,
ProtoVersion: 4,
Port: port,
}
factory, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop())
require.NoError(t, err)
defer factory.Close()
}

func TestConfigurationValidation(t *testing.T) {
testCases := []struct {
name string
cfg cassandraCfg.Configuration
wantErr bool
}{
{
name: "valid configuration",
cfg: cassandraCfg.Configuration{
Servers: []string{"http://localhost:9200"},
},
wantErr: false,
},
{
name: "missing servers",
cfg: cassandraCfg.Configuration{},
wantErr: true,
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
err := test.cfg.Validate()
if test.wantErr {
require.Error(t, err)
_, err = NewFactoryWithConfig(test.cfg, metrics.NullFactory, zap.NewNop())
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}

func TestCassandraFactoryWithConfigError(t *testing.T) {
cfg := cassandraCfg.Configuration{
Servers: []string{"http://badurl"},
}
_, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop())
require.Error(t, err)
require.ErrorContains(t, err, "gocql: unable to create session: strconv.Atoi: parsing \"//badurl\": invalid syntax")
err = cfg.Close()
require.NoError(t, err)
}

Unchanged files with check annotations Beta

return fmt.Sprintf("%+v", *c)
}
func (c *Configuration) Validate() error {
_, err := govalidator.ValidateStruct(c)
return err

Check warning on line 177 in pkg/cassandra/config/config.go

Codecov / codecov/patch

pkg/cassandra/config/config.go#L175-L177

Added lines #L175 - L177 were not covered by tests
}
cfg config.Configuration,
metricsFactory metrics.Factory,
logger *zap.Logger,
) (*Factory, error) {
archive := make(map[string]*namespaceConfig)
serverURL, err := getServers(cfg.Servers)
if err != nil {
return nil, err

Check warning on line 92 in plugin/storage/cassandra/factory.go

Codecov / codecov/patch

plugin/storage/cassandra/factory.go#L88-L92

Added lines #L88 - L92 were not covered by tests
}
archive[archiveStorageConfig] = &namespaceConfig{
Configuration: cfg,
servers: serverURL,
namespace: archiveStorageConfig,
Enabled: true,

Check warning on line 98 in plugin/storage/cassandra/factory.go

Codecov / codecov/patch

plugin/storage/cassandra/factory.go#L94-L98

Added lines #L94 - L98 were not covered by tests
}
f := NewFactory()
f.InitFromOptions(&Options{
Primary: namespaceConfig{
Configuration: cfg,
servers: serverURL,
namespace: primaryStorageConfig,
Enabled: true,
},
others: archive,
SpanStoreWriteCacheTTL: time.Hour * 12,
})
err = f.Initialize(metricsFactory, logger)
if err != nil {
return nil, err

Check warning on line 114 in plugin/storage/cassandra/factory.go

Codecov / codecov/patch

plugin/storage/cassandra/factory.go#L101-L114

Added lines #L101 - L114 were not covered by tests
}
return f, nil

Check warning on line 116 in plugin/storage/cassandra/factory.go

Codecov / codecov/patch

plugin/storage/cassandra/factory.go#L116

Added line #L116 was not covered by tests
}
func getServers(servers []string) (string, error) {
if len(servers) == 0 {
return "", fmt.Errorf("servers not found")

Check warning on line 121 in plugin/storage/cassandra/factory.go

Codecov / codecov/patch

plugin/storage/cassandra/factory.go#L119-L121

Added lines #L119 - L121 were not covered by tests
}
serverURL := servers[0]
for i, server := range servers {
if i == 0 {
continue

Check warning on line 126 in plugin/storage/cassandra/factory.go

Codecov / codecov/patch

plugin/storage/cassandra/factory.go#L123-L126

Added lines #L123 - L126 were not covered by tests
}
serverURL = serverURL + ", " + server

Check warning on line 128 in plugin/storage/cassandra/factory.go

Codecov / codecov/patch

plugin/storage/cassandra/factory.go#L128

Added line #L128 was not covered by tests
}
return serverURL, nil

Check warning on line 130 in plugin/storage/cassandra/factory.go

Codecov / codecov/patch

plugin/storage/cassandra/factory.go#L130

Added line #L130 was not covered by tests
}
// AddFlags implements plugin.Configurable