Prechádzať zdrojové kódy

Use a default duration if no duration is provided in a profile (#2520)

blotus 1 rok pred
rodič
commit
6b5da29e3d

+ 9 - 2
pkg/csprofiles/csprofiles.go

@@ -86,8 +86,15 @@ func NewProfile(profilesCfg []*csconfig.ProfileCfg) ([]*Runtime, error) {
 
 		for _, decision := range profile.Decisions {
 			if runtime.RuntimeDurationExpr == nil {
-				if _, err := time.ParseDuration(*decision.Duration); err != nil {
-					return []*Runtime{}, errors.Wrapf(err, "error parsing duration '%s' of %s", *decision.Duration, profile.Name)
+				var duration string
+				if decision.Duration != nil {
+					duration = *decision.Duration
+				} else {
+					runtime.Logger.Warningf("No duration specified for %s, using default duration %s", profile.Name, defaultDuration)
+					duration = defaultDuration
+				}
+				if _, err := time.ParseDuration(duration); err != nil {
+					return []*Runtime{}, errors.Wrapf(err, "error parsing duration '%s' of %s", duration, profile.Name)
 				}
 			}
 		}

+ 13 - 0
pkg/csprofiles/csprofiles_test.go

@@ -86,6 +86,19 @@ func TestNewProfile(t *testing.T) {
 			},
 			expectedNbProfile: 1,
 		},
+		{
+			name: "filter ok and no duration",
+			profileCfg: &csconfig.ProfileCfg{
+				Filters: []string{
+					"1==1",
+				},
+				Debug: &boolTrue,
+				Decisions: []models.Decision{
+					{Type: &typ, Scope: &scope, Simulated: &boolFalse},
+				},
+			},
+			expectedNbProfile: 1,
+		},
 	}
 
 	for _, test := range tests {