From 85899d01381e9ddc2e3a0e4db17f2bdad9548c6a Mon Sep 17 00:00:00 2001 From: Jacek Wysocki Date: Wed, 14 Feb 2024 12:39:06 +0100 Subject: [PATCH] fix: rollback NewMongoREpository construct function to not be changed (#5008) --- cmd/api-server/main.go | 2 +- pkg/repository/result/mongo.go | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cmd/api-server/main.go b/cmd/api-server/main.go index abf397aba98..5f6644b5ca8 100644 --- a/cmd/api-server/main.go +++ b/cmd/api-server/main.go @@ -252,7 +252,7 @@ func main() { db, err := storage.GetMongoDatabase(cfg.APIMongoDSN, cfg.APIMongoDB, cfg.APIMongoDBType, cfg.APIMongoAllowTLS, mongoSSLConfig) ui.ExitOnError("Getting mongo database", err) isDocDb := cfg.APIMongoDBType == storage.TypeDocDB - mongoResultsRepository := result.NewMongoRepository(db, logGrpcClient, cfg.APIMongoAllowDiskUse, isDocDb, features) + mongoResultsRepository := result.NewMongoRepository(db, cfg.APIMongoAllowDiskUse, isDocDb, result.WithFeatureFlags(features), result.WithLogsClient(logGrpcClient)) resultsRepository = mongoResultsRepository testResultsRepository = testresult.NewMongoRepository(db, cfg.APIMongoAllowDiskUse, isDocDb) configRepository = configrepository.NewMongoRepository(db) diff --git a/pkg/repository/result/mongo.go b/pkg/repository/result/mongo.go index 7448d6213ef..1a44acbaf37 100644 --- a/pkg/repository/result/mongo.go +++ b/pkg/repository/result/mongo.go @@ -36,17 +36,15 @@ const ( StepMaxCount = 100 ) -func NewMongoRepository(db *mongo.Database, logGrpcClient logsclient.StreamGetter, allowDiskUse, isDocDb bool, - features featureflags.FeatureFlags, opts ...MongoRepositoryOpt) *MongoRepository { +// NewMongoRepository creates a new MongoRepository - used by other testkube components - use opts to extend the functionality +func NewMongoRepository(db *mongo.Database, allowDiskUse, isDocDb bool, opts ...MongoRepositoryOpt) *MongoRepository { r := &MongoRepository{ db: db, ResultsColl: db.Collection(CollectionResults), SequencesColl: db.Collection(CollectionSequences), OutputRepository: NewMongoOutputRepository(db), - logGrpcClient: logGrpcClient, allowDiskUse: allowDiskUse, isDocDb: isDocDb, - features: features, log: log.DefaultLogger, } @@ -112,6 +110,18 @@ type MongoRepository struct { type MongoRepositoryOpt func(*MongoRepository) +func WithLogsClient(client logsclient.StreamGetter) MongoRepositoryOpt { + return func(r *MongoRepository) { + r.logGrpcClient = client + } +} + +func WithFeatureFlags(features featureflags.FeatureFlags) MongoRepositoryOpt { + return func(r *MongoRepository) { + r.features = features + } +} + func WithMongoRepositoryResultCollection(collection *mongo.Collection) MongoRepositoryOpt { return func(r *MongoRepository) { r.ResultsColl = collection