Skip to content

Commit

Permalink
fix: stop iqr filtering on empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
b4nst committed Sep 3, 2024
1 parent 288eca9 commit 7bf815a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/icmperf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func main() {
return nil
})

m := model.NewModel(pinger, record, (*net.UDPAddr)(&cli.Target), cli.MTU, cli.Duration)
peer := net.UDPAddr(cli.Target)
m := model.NewModel(pinger, record, &peer, cli.MTU, cli.Duration)
if err := pinger.Start(ctx); err != nil {
ktx.FatalIfErrorf(err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"fmt"
"net"
"time"
)
Expand All @@ -10,7 +11,7 @@ type Target net.UDPAddr
func (t *Target) UnmarshalText(text []byte) error {
ip, err := net.LookupIP(string(text))
if err != nil {
return err
return fmt.Errorf("failed to lookup target: %w", err)
}
t.IP = ip[0]
return nil
Expand Down
5 changes: 5 additions & 0 deletions pkg/recorder/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ type Stats struct {
// iqrFilter filters the data using the Interquartile Range method.
func iqrFilter(data []float64) []float64 {
sort.Float64s(data)
if len(data) < 4 {
// Not enough data to filter
return data
}

q1 := data[len(data)/4]
q3 := data[3*len(data)/4]
iqr := q3 - q1
Expand Down

0 comments on commit 7bf815a

Please sign in to comment.