Skip to content

Commit

Permalink
pkg/csprofiles: default duration and type for partial configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Jun 20, 2024
1 parent 659774f commit 2ef06e6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/csprofiles/csprofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ type Runtime struct {
Logger *log.Entry `json:"-" yaml:"-"`
}

const defaultDuration = "4h"
const (
defaultDuration = "4h"
defaultType = "ban"
)

func NewProfile(profilesCfg []*csconfig.ProfileCfg) ([]*Runtime, error) {
var err error
Expand Down Expand Up @@ -77,7 +80,7 @@ func NewProfile(profilesCfg []*csconfig.ProfileCfg) ([]*Runtime, error) {
for _, decision := range profile.Decisions {
if runtime.RuntimeDurationExpr == nil {
var duration string
if decision.Duration != nil {
if decision.Duration != nil && *decision.Duration != "" {
duration = *decision.Duration
} else {
runtime.Logger.Warningf("No duration specified for %s, using default duration %s", profile.Name, defaultDuration)
Expand Down Expand Up @@ -121,8 +124,10 @@ func (Profile *Runtime) GenerateDecisionFromProfile(Alert *models.Alert) ([]*mod
/*some fields are populated from the reference object : duration, scope, type*/

decision.Duration = new(string)
if refDecision.Duration != nil {
if refDecision.Duration != nil && *refDecision.Duration != "" {
*decision.Duration = *refDecision.Duration
} else {
*decision.Duration = defaultDuration
}

if Profile.Cfg.DurationExpr != "" && Profile.RuntimeDurationExpr != nil {
Expand All @@ -145,7 +150,11 @@ func (Profile *Runtime) GenerateDecisionFromProfile(Alert *models.Alert) ([]*mod
}

decision.Type = new(string)
*decision.Type = *refDecision.Type
if refDecision.Type != nil && *refDecision.Type != "" {
*decision.Type = *refDecision.Type
} else {
*decision.Type = defaultType
}

Check warning on line 157 in pkg/csprofiles/csprofiles.go

View check run for this annotation

Codecov / codecov/patch

pkg/csprofiles/csprofiles.go#L156-L157

Added lines #L156 - L157 were not covered by tests

/*for the others, let's populate it from the alert and its source*/
decision.Value = new(string)
Expand Down

0 comments on commit 2ef06e6

Please sign in to comment.