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

Remove Config Backwards Compatibility: File System Stored Requests #3124

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,6 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
v.ReadInConfig()

// Migrate config settings to maintain compatibility with old configs
migrateConfig(v)
migrateConfigPurposeOneTreatment(v)
migrateConfigSpecialFeature1(v)
migrateConfigTCF2PurposeFlags(v)
Expand Down Expand Up @@ -1135,19 +1134,6 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
}
}

func migrateConfig(v *viper.Viper) {
// if stored_requests.filesystem is not a map in conf file as expected from defaults,
// means we have old-style settings; migrate them to new filesystem map to avoid breaking viper
if _, ok := v.Get("stored_requests.filesystem").(map[string]interface{}); !ok {
glog.Warning("stored_requests.filesystem should be changed to stored_requests.filesystem.enabled")
glog.Warning("stored_requests.directorypath should be changed to stored_requests.filesystem.directorypath")
m := v.GetStringMap("stored_requests.filesystem")
m["enabled"] = v.GetBool("stored_requests.filesystem")
m["directorypath"] = v.GetString("stored_requests.directorypath")
v.Set("stored_requests.filesystem", m)
}
}

func migrateConfigCompression(v *viper.Viper) {
oldField := "enable_gzip"
newField := "compression.response.enable_gzip"
Expand Down
27 changes: 0 additions & 27 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,6 @@ tmax_adjustments:
pbs_response_preparation_duration_ms: 100
`)

var oldStoredRequestsConfig = []byte(`
stored_requests:
filesystem: true
directorypath: "/somepath"
`)

func cmpStrings(t *testing.T, key, expected, actual string) {
t.Helper()
assert.Equal(t, expected, actual, "%s: %s != %s", key, expected, actual)
Expand Down Expand Up @@ -818,36 +812,15 @@ func TestValidateConfig(t *testing.T) {
assert.Nil(t, err, "OpenRTB filesystem config should work. %v", err)
}

func TestMigrateConfig(t *testing.T) {
v := viper.New()
SetupViper(v, "", bidderInfos)
v.Set("gdpr.default_value", "0")
v.SetConfigType("yaml")
v.ReadConfig(bytes.NewBuffer(oldStoredRequestsConfig))
migrateConfig(v)
cfg, err := New(v, bidderInfos, mockNormalizeBidderName)
assert.NoError(t, err, "Setting up config should work but it doesn't")
cmpBools(t, "stored_requests.filesystem.enabled", true, cfg.StoredRequests.Files.Enabled)
cmpStrings(t, "stored_requests.filesystem.path", "/somepath", cfg.StoredRequests.Files.Path)
}

func TestMigrateConfigFromEnv(t *testing.T) {
if oldval, ok := os.LookupEnv("PBS_STORED_REQUESTS_FILESYSTEM"); ok {
defer os.Setenv("PBS_STORED_REQUESTS_FILESYSTEM", oldval)
} else {
defer os.Unsetenv("PBS_STORED_REQUESTS_FILESYSTEM")
}

if oldval, ok := os.LookupEnv("PBS_ADAPTERS_BIDDER1_ENDPOINT"); ok {
defer os.Setenv("PBS_ADAPTERS_BIDDER1_ENDPOINT", oldval)
} else {
defer os.Unsetenv("PBS_ADAPTERS_BIDDER1_ENDPOINT")
}

os.Setenv("PBS_STORED_REQUESTS_FILESYSTEM", "true")
os.Setenv("PBS_ADAPTERS_BIDDER1_ENDPOINT", "http://bidder1_override.com")
cfg, _ := newDefaultConfig(t)
cmpBools(t, "stored_requests.filesystem.enabled", true, cfg.StoredRequests.Files.Enabled)
cmpStrings(t, "adapters.bidder1.endpoint", "http://bidder1_override.com", cfg.BidderInfos["bidder1"].Endpoint)
}

Expand Down
Loading