[#117] Refactor fetch/parse config parameters functions #189

Merged
alexvanin merged 1 commit from :feature/117-refactor-fetch-parse-functions into master 2023-08-22 08:13:18 +00:00
Member

Signed-off-by: Roman Loginov r.loginov@yadro.com

Signed-off-by: Roman Loginov <r.loginov@yadro.com>
r.loginov requested review from storage-services-developers 2023-08-18 04:33:38 +00:00
r.loginov requested review from storage-services-committers 2023-08-18 04:33:38 +00:00
ironbee approved these changes 2023-08-18 08:58:53 +00:00
dkirillov reviewed 2023-08-18 12:47:43 +00:00
cmd/s3-gw/app.go Outdated
@ -786,14 +718,7 @@ func (a *App) initHandler() {
}
if a.cfg.IsSet(cfgDefaultMaxAge) {
Member

Let's move this check into fetchDefaultMaxAge function. If this value isn't set then return handler.DefaultMaxAge from the function

Let's move this check into `fetchDefaultMaxAge` function. If this value isn't set then return `handler.DefaultMaxAge` from the function
dkirillov marked this conversation as resolved
dkirillov reviewed 2023-08-18 12:48:09 +00:00
@ -159,0 +265,4 @@
return defaultValue
}
func fetchSize(v *viper.Viper, l *zap.Logger, cfgEntry string, defaultValue int) int {
Member

Let's rename this to fetchCacheSize.

Let's rename this to `fetchCacheSize`.
dkirillov marked this conversation as resolved
dkirillov reviewed 2023-08-18 12:48:19 +00:00
@ -159,0 +249,4 @@
return timeout
}
func fetchLifetime(v *viper.Viper, l *zap.Logger, cfgEntry string, defaultValue time.Duration) time.Duration {
Member

Let's rename this to fetchCacheLifetime.

Let's rename this to `fetchCacheLifetime`.
dkirillov marked this conversation as resolved
dkirillov reviewed 2023-08-18 12:55:42 +00:00
cmd/s3-gw/app.go Outdated
@ -424,3 +392,1 @@
var defaultPlacementPolicy netmap.PlacementPolicy
if err := defaultPlacementPolicy.DecodeString(defaultPolicy); err != nil {
return fmt.Errorf("parse default policy '%s': %w", defaultPolicy, err)
func (p *placementPolicy) updatePolicy(v *viper.Viper, regionPolicyFilepath string) error {
Member

Let's get regionPolicyFilepath inside this function. Or even create function fetchRegionMappingPolicies that would look likes

func fetchRegionMappingPolicies(cfg *viper.Viper) (map[string]netmap.PlacementPolicy, error) {
	regionPolicyMap, err := readRegionMap(cfg.GetString(cfgPolicyRegionMapFile))
	if err != nil {
		return nil, fmt.Errorf("read region map file: %w", err)
	}

	regionMap := make(map[string]netmap.PlacementPolicy, len(regionPolicyMap))
	for region, policy := range regionPolicyMap {
		var pp netmap.PlacementPolicy
		if err = pp.DecodeString(policy); err == nil {
			regionMap[region] = pp
			continue
		}

		if err = pp.UnmarshalJSON([]byte(policy)); err == nil {
			regionMap[region] = pp
			continue
		}

		return nil, fmt.Errorf("parse region '%s' to policy mapping: %w", region, err)
	}

	return regionMap, nil
}

and we can call it here (in updatePolicy)

Let's get `regionPolicyFilepath` inside this function. Or even create function `fetchRegionMappingPolicies` that would look likes ```golang func fetchRegionMappingPolicies(cfg *viper.Viper) (map[string]netmap.PlacementPolicy, error) { regionPolicyMap, err := readRegionMap(cfg.GetString(cfgPolicyRegionMapFile)) if err != nil { return nil, fmt.Errorf("read region map file: %w", err) } regionMap := make(map[string]netmap.PlacementPolicy, len(regionPolicyMap)) for region, policy := range regionPolicyMap { var pp netmap.PlacementPolicy if err = pp.DecodeString(policy); err == nil { regionMap[region] = pp continue } if err = pp.UnmarshalJSON([]byte(policy)); err == nil { regionMap[region] = pp continue } return nil, fmt.Errorf("parse region '%s' to policy mapping: %w", region, err) } return regionMap, nil } ``` and we can call it here (in `updatePolicy`)
dkirillov marked this conversation as resolved
r.loginov self-assigned this 2023-08-18 13:40:48 +00:00
r.loginov force-pushed feature/117-refactor-fetch-parse-functions from 06b2241503 to 3be0b7b6cf 2023-08-18 13:43:23 +00:00 Compare
dkirillov reviewed 2023-08-18 13:52:10 +00:00
cmd/s3-gw/app.go Outdated
@ -795,3 +704,1 @@
}
cfg.DefaultMaxAge = defaultMaxAge
}
cfg.DefaultMaxAge = fetchDefaultMaxAge(a.cfg, a.log)
Member

Actually, now we can set this field in L699 above

Actually, now we can set this field in `L699` above
dkirillov marked this conversation as resolved
r.loginov force-pushed feature/117-refactor-fetch-parse-functions from 3be0b7b6cf to cebd7ec83e 2023-08-18 14:03:39 +00:00 Compare
dkirillov approved these changes 2023-08-18 14:19:31 +00:00
r.loginov requested review from ironbee 2023-08-18 14:20:06 +00:00
alexvanin approved these changes 2023-08-22 07:45:10 +00:00
alexvanin force-pushed feature/117-refactor-fetch-parse-functions from cebd7ec83e to 6a9d3261a7 2023-08-22 08:05:31 +00:00 Compare
dkirillov approved these changes 2023-08-22 08:12:23 +00:00
dkirillov requested review from storage-services-developers 2023-08-22 08:12:45 +00:00
dkirillov requested review from storage-services-committers 2023-08-22 08:12:46 +00:00
dkirillov approved these changes 2023-08-22 08:13:06 +00:00
alexvanin merged commit 6a9d3261a7 into master 2023-08-22 08:13:18 +00:00
alexvanin deleted branch feature/117-refactor-fetch-parse-functions 2023-08-22 08:13:18 +00:00
Sign in to join this conversation.
No reviewers
TrueCloudLab/storage-services-developers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-s3-gw#189
No description provided.