Skip to content

Commit

Permalink
Support MySql driver (prebid#2356)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorshevtsov authored Nov 17, 2022
1 parent 563f6c6 commit f40f0c3
Show file tree
Hide file tree
Showing 21 changed files with 1,882 additions and 536 deletions.
201 changes: 165 additions & 36 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,20 +850,6 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
v.SetDefault("stored_requests.filesystem.enabled", false)
v.SetDefault("stored_requests.filesystem.directorypath", "./stored_requests/data/by_id")
v.SetDefault("stored_requests.directorypath", "./stored_requests/data/by_id")
v.SetDefault("stored_requests.postgres.connection.dbname", "")
v.SetDefault("stored_requests.postgres.connection.host", "")
v.SetDefault("stored_requests.postgres.connection.port", 0)
v.SetDefault("stored_requests.postgres.connection.user", "")
v.SetDefault("stored_requests.postgres.connection.password", "")
v.SetDefault("stored_requests.postgres.fetcher.query", "")
v.SetDefault("stored_requests.postgres.fetcher.amp_query", "")
v.SetDefault("stored_requests.postgres.initialize_caches.timeout_ms", 0)
v.SetDefault("stored_requests.postgres.initialize_caches.query", "")
v.SetDefault("stored_requests.postgres.initialize_caches.amp_query", "")
v.SetDefault("stored_requests.postgres.poll_for_updates.refresh_rate_seconds", 0)
v.SetDefault("stored_requests.postgres.poll_for_updates.timeout_ms", 0)
v.SetDefault("stored_requests.postgres.poll_for_updates.query", "")
v.SetDefault("stored_requests.postgres.poll_for_updates.amp_query", "")
v.SetDefault("stored_requests.http.endpoint", "")
v.SetDefault("stored_requests.http.amp_endpoint", "")
v.SetDefault("stored_requests.in_memory_cache.type", "none")
Expand All @@ -880,17 +866,6 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
// PBS is not in the business of storing video content beyond the normal prebid cache system.
v.SetDefault("stored_video_req.filesystem.enabled", false)
v.SetDefault("stored_video_req.filesystem.directorypath", "")
v.SetDefault("stored_video_req.postgres.connection.dbname", "")
v.SetDefault("stored_video_req.postgres.connection.host", "")
v.SetDefault("stored_video_req.postgres.connection.port", 0)
v.SetDefault("stored_video_req.postgres.connection.user", "")
v.SetDefault("stored_video_req.postgres.connection.password", "")
v.SetDefault("stored_video_req.postgres.fetcher.query", "")
v.SetDefault("stored_video_req.postgres.initialize_caches.timeout_ms", 0)
v.SetDefault("stored_video_req.postgres.initialize_caches.query", "")
v.SetDefault("stored_video_req.postgres.poll_for_updates.refresh_rate_seconds", 0)
v.SetDefault("stored_video_req.postgres.poll_for_updates.timeout_ms", 0)
v.SetDefault("stored_video_req.postgres.poll_for_updates.query", "")
v.SetDefault("stored_video_req.http.endpoint", "")
v.SetDefault("stored_video_req.in_memory_cache.type", "none")
v.SetDefault("stored_video_req.in_memory_cache.ttl_seconds", 0)
Expand All @@ -904,17 +879,6 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
v.SetDefault("stored_video_req.http_events.timeout_ms", 0)
v.SetDefault("stored_responses.filesystem.enabled", false)
v.SetDefault("stored_responses.filesystem.directorypath", "")
v.SetDefault("stored_responses.postgres.connection.dbname", "")
v.SetDefault("stored_responses.postgres.connection.host", "")
v.SetDefault("stored_responses.postgres.connection.port", 0)
v.SetDefault("stored_responses.postgres.connection.user", "")
v.SetDefault("stored_responses.postgres.connection.password", "")
v.SetDefault("stored_responses.postgres.fetcher.query", "")
v.SetDefault("stored_responses.postgres.initialize_caches.timeout_ms", 0)
v.SetDefault("stored_responses.postgres.initialize_caches.query", "")
v.SetDefault("stored_responses.postgres.poll_for_updates.refresh_rate_seconds", 0)
v.SetDefault("stored_responses.postgres.poll_for_updates.timeout_ms", 0)
v.SetDefault("stored_responses.postgres.poll_for_updates.query", "")
v.SetDefault("stored_responses.http.endpoint", "")
v.SetDefault("stored_responses.in_memory_cache.type", "none")
v.SetDefault("stored_responses.in_memory_cache.ttl_seconds", 0)
Expand Down Expand Up @@ -1039,6 +1003,7 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
migrateConfigPurposeOneTreatment(v)
migrateConfigSpecialFeature1(v)
migrateConfigTCF2PurposeFlags(v)
migrateConfigDatabaseConnection(v)

// These defaults must be set after the migrate functions because those functions look for the presence of these
// config fields and there isn't a way to detect presence of a config field using the viper package if a default
Expand Down Expand Up @@ -1190,6 +1155,170 @@ func migrateConfigTCF2PurposeEnabledFlags(v *viper.Viper) {
}
}

func migrateConfigDatabaseConnection(v *viper.Viper) {

type QueryParamMigration struct {
old string
new string
}

type QueryMigration struct {
name string
params []QueryParamMigration
}

type Migration struct {
old string
new string
fields []string
queryMigrations []QueryMigration
}

queryParamMigrations := struct {
RequestIdList QueryParamMigration
ImpIdList QueryParamMigration
IdList QueryParamMigration
LastUpdated QueryParamMigration
}{
RequestIdList: QueryParamMigration{
old: "%REQUEST_ID_LIST%",
new: "$REQUEST_ID_LIST",
},
ImpIdList: QueryParamMigration{
old: "%IMP_ID_LIST%",
new: "$IMP_ID_LIST",
},
IdList: QueryParamMigration{
old: "%ID_LIST%",
new: "$ID_LIST",
},
LastUpdated: QueryParamMigration{
old: "$1",
new: "$LAST_UPDATED",
},
}

queryMigrations := []QueryMigration{
{
name: "fetcher.query",
params: []QueryParamMigration{queryParamMigrations.RequestIdList, queryParamMigrations.ImpIdList, queryParamMigrations.IdList},
},
{
name: "fetcher.amp_query",
params: []QueryParamMigration{queryParamMigrations.RequestIdList, queryParamMigrations.ImpIdList, queryParamMigrations.IdList},
},
{
name: "poll_for_updates.query",
params: []QueryParamMigration{queryParamMigrations.LastUpdated},
},
{
name: "poll_for_updates.amp_query",
params: []QueryParamMigration{queryParamMigrations.LastUpdated},
},
}

migrations := []Migration{
{
old: "stored_requests.postgres",
new: "stored_requests.database",
fields: []string{
"connection.dbname",
"connection.host",
"connection.port",
"connection.user",
"connection.password",
"fetcher.query",
"fetcher.amp_query",
"initialize_caches.timeout_ms",
"initialize_caches.query",
"initialize_caches.amp_query",
"poll_for_updates.refresh_rate_seconds",
"poll_for_updates.timeout_ms",
"poll_for_updates.query",
"poll_for_updates.amp_query",
},
queryMigrations: queryMigrations,
},
{
old: "stored_video_req.postgres",
new: "stored_video_req.database",
fields: []string{
"connection.dbname",
"connection.host",
"connection.port",
"connection.user",
"connection.password",
"fetcher.query",
"initialize_caches.timeout_ms",
"initialize_caches.query",
"poll_for_updates.refresh_rate_seconds",
"poll_for_updates.timeout_ms",
"poll_for_updates.query",
},
queryMigrations: queryMigrations,
},
{
old: "stored_responses.postgres",
new: "stored_responses.database",
fields: []string{
"connection.dbname",
"connection.host",
"connection.port",
"connection.user",
"connection.password",
"fetcher.query",
"initialize_caches.timeout_ms",
"initialize_caches.query",
"poll_for_updates.refresh_rate_seconds",
"poll_for_updates.timeout_ms",
"poll_for_updates.query",
},
queryMigrations: queryMigrations,
},
}

for _, migration := range migrations {
driverField := migration.new + ".connection.driver"
if !v.IsSet(migration.new) && v.IsSet(migration.old) {
glog.Warning(fmt.Sprintf("%s is deprecated and should be changed to %s", migration.old, migration.new))
glog.Warning(fmt.Sprintf("%s is not set, using default (postgres)", driverField))
v.Set(driverField, "postgres")

for _, field := range migration.fields {
oldField := migration.old + "." + field
newField := migration.new + "." + field
if v.IsSet(oldField) {
glog.Warning(fmt.Sprintf("%s is deprecated and should be changed to %s", oldField, newField))
v.Set(newField, v.Get(oldField))
}
}

for _, queryMigration := range migration.queryMigrations {
oldQueryField := migration.old + "." + queryMigration.name
newQueryField := migration.new + "." + queryMigration.name
queryString := v.GetString(oldQueryField)
for _, queryParam := range queryMigration.params {
if strings.Contains(queryString, queryParam.old) {
glog.Warning(fmt.Sprintf("Query param %s for %s is deprecated and should be changed to %s", queryParam.old, oldQueryField, queryParam.new))
queryString = strings.ReplaceAll(queryString, queryParam.old, queryParam.new)
v.Set(newQueryField, queryString)
}
}
}
} else if v.IsSet(migration.new) && v.IsSet(migration.old) {
glog.Warning(fmt.Sprintf("using %s and ignoring deprecated %s", migration.new, migration.old))

for _, field := range migration.fields {
oldField := migration.old + "." + field
newField := migration.new + "." + field
if v.IsSet(oldField) {
glog.Warning(fmt.Sprintf("using %s and ignoring deprecated %s", newField, oldField))
}
}
}
}
}

func setBidderDefaults(v *viper.Viper, bidder string) {
adapterCfgPrefix := "adapters." + bidder
v.BindEnv(adapterCfgPrefix+".disabled", "")
Expand Down
Loading

0 comments on commit f40f0c3

Please sign in to comment.