From d007a8c188896e5998afb8c819612bcde6015f28 Mon Sep 17 00:00:00 2001 From: Oleg Obleukhov Date: Fri, 18 Oct 2024 05:08:04 -0700 Subject: [PATCH] mean -> median Summary: Make t3lurid3 happy Reviewed By: deathowl Differential Revision: D64596575 fbshipit-source-id: 1398d9d1dca9a94746ca46718ac96548f5ec1ed3 --- cmd/ntpcheck/checker/stats.go | 6 +++--- cmd/ntpcheck/checker/stats_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/ntpcheck/checker/stats.go b/cmd/ntpcheck/checker/stats.go index b0a29cb9..0f68de0d 100644 --- a/cmd/ntpcheck/checker/stats.go +++ b/cmd/ntpcheck/checker/stats.go @@ -38,7 +38,7 @@ type NTPStats struct { StatError bool `json:"ntp.stat.error"` // error reported in Leap Status Correction float64 `json:"ntp.correction"` // current correction PeerCount int `json:"ntp.peer.count"` // number of upstream peers - OffsetComparedToPeers float64 `json:"ntp.sys.offset_selected_vs_peers_ms"` // sys peer offset vs mean peer offset in ms + OffsetComparedToPeers float64 `json:"ntp.sys.offset_selected_vs_peers_ms"` // sys peer offset vs median peer offset in ms } type averages struct { @@ -84,7 +84,7 @@ func peersAverages(peers []*Peer) (*averages, error) { }, nil } -func meanOffset(peers []*Peer) float64 { +func medianOffset(peers []*Peer) float64 { offsets := []float64{} for _, p := range peers { offsets = append(offsets, p.Offset) @@ -135,7 +135,7 @@ func NewNTPStats(r *NTPCheckResult) (*NTPStats, error) { peerAvgs, err := peersAverages(okPeers) if err == nil { log.Debugf("Sys Offset: %v, Avg Peer Offset: %v", time.Duration(offset*float64(time.Millisecond)), time.Duration(peerAvgs.offset*float64(time.Millisecond))) - offsetComparedToPeers = math.Abs(math.Abs(offset) - math.Abs(meanOffset(okPeers))) + offsetComparedToPeers = math.Abs(math.Abs(offset) - math.Abs(medianOffset(okPeers))) } } output := NTPStats{ diff --git a/cmd/ntpcheck/checker/stats_test.go b/cmd/ntpcheck/checker/stats_test.go index e7bc739e..b1babbb0 100644 --- a/cmd/ntpcheck/checker/stats_test.go +++ b/cmd/ntpcheck/checker/stats_test.go @@ -196,7 +196,7 @@ func TestNTPStatsWithSysPeerAndNoSelect(t *testing.T) { require.Equal(t, want, stats) } -func TestMeanOffset(t *testing.T) { +func TestMedianOffset(t *testing.T) { peers := []*Peer{ 0: {Offset: 1}, 1: {Offset: 2}, @@ -206,6 +206,6 @@ func TestMeanOffset(t *testing.T) { 5: {Offset: 6}, 6: {Offset: 100500}, } - meanOffset := meanOffset(peers) - require.Equal(t, float64(4), meanOffset) + medianOffset := medianOffset(peers) + require.Equal(t, float64(4), medianOffset) }