Skip to content

Commit

Permalink
Added sampling store mock factory in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alok Kumar Singh <[email protected]>
  • Loading branch information
akstron committed Dec 9, 2024
1 parent 6d5c718 commit 2e23786
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
7 changes: 6 additions & 1 deletion cmd/remote-storage/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (
"github.com/jaegertracing/jaeger/storage/spanstore"
)

const (
DEFAULT_MAX_BUCKET_SIZE = 1
)

// Server runs a gRPC server
type Server struct {
opts *Options
Expand Down Expand Up @@ -68,7 +72,8 @@ func createGRPCHandler(f storage.BaseFactory, samplingStoreFactory storage.Sampl
if err != nil {
return nil, err
}
samplingStore, err := samplingStoreFactory.CreateSamplingStore(1)
// TODO: Update this to use bucket size from config
samplingStore, err := samplingStoreFactory.CreateSamplingStore(DEFAULT_MAX_BUCKET_SIZE)
if err != nil {
return nil, err
}
Expand Down
17 changes: 13 additions & 4 deletions cmd/remote-storage/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ func TestNewServer_CreateStorageErrors(t *testing.T) {
factory.On("CreateSpanWriter").Return(nil, nil)
factory.On("CreateDependencyReader").Return(nil, errors.New("no deps")).Once()
factory.On("CreateDependencyReader").Return(nil, nil)
samplingStoreFactoryMocks := factoryMocks.NewSamplingStoreFactory(t)
f := func() (*Server, error) {
return NewServer(
&Options{GRPCHostPort: ":0"},
factory,
tenancy.NewManager(&tenancy.Options{}),
telemetry.NoopSettings(),
nil,
samplingStoreFactoryMocks,
)
}
_, err := f()
Expand Down Expand Up @@ -114,12 +115,14 @@ func TestNewServer_TLSConfigError(t *testing.T) {
ReportStatus: telemetry.HCAdapter(healthcheck.New()),
}
storageMocks := newStorageMocks()
samplingStoreFactoryMocks := factoryMocks.NewSamplingStoreFactory(t)

_, err := NewServer(
&Options{GRPCHostPort: ":8081", TLSGRPC: tlsCfg},
storageMocks.factory,
tenancy.NewManager(&tenancy.Options{}),
telset,
nil,
samplingStoreFactoryMocks,
)
assert.ErrorContains(t, err, "invalid TLS config")
}
Expand Down Expand Up @@ -322,12 +325,15 @@ func TestServerGRPCTLS(t *testing.T) {
Logger: flagsSvc.Logger,
ReportStatus: telemetry.HCAdapter(flagsSvc.HC()),
}

samplingStoreFactoryMocks := factoryMocks.NewSamplingStoreFactory(t)

server, err := NewServer(
serverOptions,
storageMocks.factory,
tm,
telset,
nil,
samplingStoreFactoryMocks,
)
require.NoError(t, err)
require.NoError(t, server.Start())
Expand Down Expand Up @@ -372,12 +378,15 @@ func TestServerHandlesPortZero(t *testing.T) {
Logger: flagsSvc.Logger,
ReportStatus: telemetry.HCAdapter(flagsSvc.HC()),
}

samplingStoreFactoryMocks := factoryMocks.NewSamplingStoreFactory(t)

server, err := NewServer(
&Options{GRPCHostPort: ":0"},
storageMocks.factory,
tenancy.NewManager(&tenancy.Options{}),
telset,
nil,
samplingStoreFactoryMocks,
)
require.NoError(t, err)

Expand Down
7 changes: 6 additions & 1 deletion cmd/remote-storage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ func main() {
logger.Fatal("Failed to init storage factory", zap.Error(err))
}

samplingStoreFactory, err := storageFactory.CreateSamplingStoreFactory()
if err != nil {
logger.Fatal("Failed to init sampling storage factory", zap.Error(err))
}

tm := tenancy.NewManager(&opts.Tenancy)
telset := baseTelset // copy
telset.Metrics = metricsFactory
server, err := app.NewServer(opts, storageFactory, tm, telset, nil)
server, err := app.NewServer(opts, storageFactory, tm, telset, samplingStoreFactory)
if err != nil {
logger.Fatal("Failed to create server", zap.Error(err))
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/grpc/shared/grpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestNewGRPCClient(t *testing.T) {
assert.Implements(t, (*storage_v1.PluginCapabilitiesClient)(nil), client.capabilitiesClient)
assert.Implements(t, (*storage_v1.DependenciesReaderPluginClient)(nil), client.depsReaderClient)
assert.Implements(t, (*storage_v1.StreamingSpanWriterPluginClient)(nil), client.streamWriterClient)
assert.Implements(t, (*storage_v1.SamplingStorePluginClient)(nil), client.samplingStoreClient)
assert.Implements(t, (*storage_v1.SamplingStorePluginClient)(nil), client.streamWriterClient)
}

func TestGRPCClientGetServices(t *testing.T) {
Expand Down

0 comments on commit 2e23786

Please sign in to comment.