Skip to content

Commit

Permalink
Add support for mongodb+srv conn format
Browse files Browse the repository at this point in the history
Option can be found in db opts under the name 'mongoSchema'.
  • Loading branch information
ionutboangiu authored and danbogos committed Dec 11, 2023
1 parent 1154cad commit 24cbe49
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 23 deletions.
5 changes: 5 additions & 0 deletions cmd/cgr-loader/cgr-loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ var (
"The amount of wait time until timeout for writing operations")
dbQueryTimeout = cgrLoaderFlags.Duration(utils.MongoQueryTimeoutCfg, dfltCfg.DataDbCfg().Opts.MongoQueryTimeout,
"The timeout for queries")
dbMongoScheme = cgrLoaderFlags.String(utils.MongoSchemeCfg, dfltCfg.DataDbCfg().Opts.MongoScheme,
"Scheme for MongoDB connection <mongodb|mongodb+srv>")
dbRedisTls = cgrLoaderFlags.Bool(utils.RedisTLS, false, "Enable TLS when connecting to Redis")
dbRedisClientCertificate = cgrLoaderFlags.String(utils.RedisClientCertificate, utils.EmptyString, "Path to the client certificate")
dbRedisClientKey = cgrLoaderFlags.String(utils.RedisClientKey, utils.EmptyString, "Path to the client key")
Expand Down Expand Up @@ -187,6 +189,9 @@ func loadConfig() (ldrCfg *config.CGRConfig) {
if *dbQueryTimeout != dfltCfg.DataDbCfg().Opts.MongoQueryTimeout {
ldrCfg.DataDbCfg().Opts.MongoQueryTimeout = *dbQueryTimeout
}
if *dbMongoScheme != dfltCfg.DataDbCfg().Opts.MongoScheme {
ldrCfg.DataDbCfg().Opts.MongoScheme = *dbMongoScheme
}
if *dbRedisTls != dfltCfg.DataDbCfg().Opts.RedisTLS {
ldrCfg.DataDbCfg().Opts.RedisTLS = *dbRedisTls
}
Expand Down
1 change: 1 addition & 0 deletions cmd/cgr-loader/cgr-loader_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func TestLoadConfig(t *testing.T) {
RedisClusterOndownDelay: 0,
RedisConnectTimeout: 5 * time.Second,
MongoQueryTimeout: 10 * time.Second,
MongoScheme: "mongodb",
RedisTLS: false,
},
RmtConns: []string{},
Expand Down
6 changes: 5 additions & 1 deletion cmd/cgr-migrator/cgr-migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ var (
"The amount of wait time until timeout for writing operations")
dbQueryTimeout = cgrMigratorFlags.Duration(utils.MongoQueryTimeoutCfg, dfltCfg.DataDbCfg().Opts.MongoQueryTimeout,
"The timeout for queries")
dbMongoScheme = cgrMigratorFlags.String(utils.MongoSchemeCfg, dfltCfg.DataDbCfg().Opts.MongoScheme,
"Scheme for MongoDB connection <mongodb|mongodb+srv>")
dbRedisTls = cgrMigratorFlags.Bool(utils.RedisTLS, false, "Enable TLS when connecting to Redis")
dbRedisClientCertificate = cgrMigratorFlags.String(utils.RedisClientCertificate, utils.EmptyString, "Path to the client certificate")
dbRedisClientKey = cgrMigratorFlags.String(utils.RedisClientKey, utils.EmptyString, "Path to the client key")
Expand Down Expand Up @@ -209,7 +211,9 @@ func main() {
if *dbQueryTimeout != dfltCfg.DataDbCfg().Opts.MongoQueryTimeout {
mgrCfg.DataDbCfg().Opts.MongoQueryTimeout = *dbQueryTimeout
}

if *dbMongoScheme != dfltCfg.DataDbCfg().Opts.MongoScheme {
mgrCfg.DataDbCfg().Opts.MongoScheme = *dbMongoScheme
}
if *dbRedisTls != dfltCfg.DataDbCfg().Opts.RedisTLS {
mgrCfg.DataDbCfg().Opts.RedisTLS = *dbRedisTls
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/cgr-tester/cgr-tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ var (
"The amount of wait time until timeout for reading operations")
dbRedisWriteTimeout = cgrTesterFlags.Duration(utils.RedisWriteTimeoutCfg, cgrConfig.DataDbCfg().Opts.RedisWriteTimeout,
"The amount of wait time until timeout for writing operations")
dbMongoScheme = cgrTesterFlags.String(utils.MongoSchemeCfg, cgrConfig.DataDbCfg().Opts.MongoScheme,
"Scheme for MongoDB connection <mongodb|mongodb+srv>")
raterAddress = cgrTesterFlags.String("rater_address", "", "Rater address for remote tests. Empty for internal rater.")
minUsage = cgrTesterFlags.Duration("min_usage", 1*time.Second, "Minimum usage a session can have")
maxUsage = cgrTesterFlags.Duration("max_usage", 5*time.Second, "Maximum usage a session can have")
Expand Down Expand Up @@ -299,6 +301,9 @@ func main() {
if *dbQueryTimeout != cgrConfig.DataDbCfg().Opts.MongoQueryTimeout {
tstCfg.DataDbCfg().Opts.MongoQueryTimeout = *dbQueryTimeout
}
if *dbMongoScheme != cgrConfig.DataDbCfg().Opts.MongoScheme {
tstCfg.DataDbCfg().Opts.MongoScheme = *dbMongoScheme
}

if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
Expand Down
7 changes: 6 additions & 1 deletion config/config_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const CGRATES_CFG_JSON = `
"redisReadTimeout": "0", // the amount of wait time until timeout for reading operations
"redisWriteTimeout": "0", // the amount of wait time until timeout for writing operations
"mongoQueryTimeout":"10s", // timeout for query when mongo is used
"mongoScheme": "mongodb", // scheme for MongoDB connection <mongodb|mongodb+srv>
"redisTLS": false, // if true it will use a tls connection and use the redisClientCertificate, redisClientKey and redisCACertificate for tls connection
"redisClientCertificate":"", // path to client certificate
"redisClientKey":"", // path to client key
Expand All @@ -167,6 +168,7 @@ const CGRATES_CFG_JSON = `
"sqlConnMaxLifetime": "0", // maximum amount of time a connection may be reused (0 for unlimited), not applying for mongo
"mysqlDSNParams": {}, // DSN extra paramss
"mongoQueryTimeout": "10s", // timeout for query when mongo is used
"mongoScheme": "mongodb", // scheme for MongoDB connection <mongodb|mongodb+srv>
"pgSSLMode": "disable", // pgSSLMode in case of *postgres
"mysqlLocation": "Local", // the location the time from mysql is retrieved
},
Expand Down Expand Up @@ -1082,8 +1084,11 @@ const CGRATES_CFG_JSON = `
"redisClientCertificate":"", // path to client certificate
"redisClientKey":"", // path to client key
"redisCACertificate":"", // path to CA certificate (populate for self-signed certificate otherwise let it empty)
"mongoScheme": "mongodb", // scheme for MongoDB connection <mongodb|mongodb+srv>
},
"out_stordb_opts":{
"mongoScheme": "mongodb" // scheme for MongoDB connection <mongodb|mongodb+srv>
},
"out_stordb_opts":{},
},
Expand Down
7 changes: 6 additions & 1 deletion config/config_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func TestDfDataDbJsonCfg(t *testing.T) {
RedisReadTimeout: utils.StringPointer("0"),
RedisWriteTimeout: utils.StringPointer("0"),
MongoQueryTimeout: utils.StringPointer("10s"),
MongoScheme: utils.StringPointer("mongodb"),
RedisTLS: utils.BoolPointer(false),
RedisClientCertificate: utils.StringPointer(utils.EmptyString),
RedisClientKey: utils.StringPointer(utils.EmptyString),
Expand Down Expand Up @@ -554,6 +555,7 @@ func TestDfStorDBJsonCfg(t *testing.T) {
SQLMaxOpenConns: utils.IntPointer(100),
SQLMaxIdleConns: utils.IntPointer(10),
MongoQueryTimeout: utils.StringPointer("10s"),
MongoScheme: utils.StringPointer("mongodb"),
SQLConnMaxLifetime: utils.StringPointer("0"),
MySQLDSNParams: make(map[string]string),
PgSSLMode: utils.StringPointer(utils.PostgresSSLModeDisable),
Expand Down Expand Up @@ -1891,7 +1893,9 @@ func TestDfMigratorCfg(t *testing.T) {
Out_storDB_user: utils.StringPointer("cgrates"),
Out_storDB_password: utils.StringPointer(""),
Users_filters: &[]string{},
Out_storDB_opts: &DBOptsJson{},
Out_storDB_opts: &DBOptsJson{
MongoScheme: utils.StringPointer("mongodb"),
},
Out_dataDB_opts: &DBOptsJson{
RedisMaxConns: utils.IntPointer(10),
RedisConnectAttempts: utils.IntPointer(20),
Expand All @@ -1906,6 +1910,7 @@ func TestDfMigratorCfg(t *testing.T) {
RedisClientCertificate: utils.StringPointer(utils.EmptyString),
RedisClientKey: utils.StringPointer(utils.EmptyString),
RedisCACertificate: utils.StringPointer(utils.EmptyString),
MongoScheme: utils.StringPointer("mongodb"),
},
}
dfCgrJSONCfg, err := NewCgrJsonCfgFromBytes([]byte(CGRATES_CFG_JSON))
Expand Down

0 comments on commit 24cbe49

Please sign in to comment.