Skip to content

Commit

Permalink
Tweak per-interval chance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
multimac committed Jul 2, 2021
1 parent 133e6d7 commit f45361e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"fmt"
"math"
"math/rand"
"strconv"
"strings"
Expand All @@ -17,7 +18,7 @@ const (
Kitchen24 = "15:04"
// a time format that just cares about the day and month.
YearDay = "Jan_2"

// default annotation prefix for configuration overrides
DefaultBaseAnnotation = "chaos.alpha.kubernetes.io"
)

Expand Down Expand Up @@ -148,7 +149,15 @@ func ParseFrequency(text string, interval time.Duration) (float64, error) {
return 0, fmt.Errorf("unknown time period, %v", parts[1])
}

chance := (float64(interval) / float64(period)) * frequency
attempts := float64(period) / float64(interval) / frequency

// We want a 75% chance of a pod being terminated once in the given number of attempts
// Formula for calculating probability of something occurring once in "n" attempts...
// p = 1 - math.Pow(1 - c, n)
// where p = probability, c = chance per attempt, n = number of attempts
// The equation below inverts that formula to calculate that percent chance we need
chance := 1 - math.Pow(1-0.75, (1/attempts))

return chance, nil
}

Expand Down

0 comments on commit f45361e

Please sign in to comment.