Skip to content

Commit

Permalink
moving stats into topology and removing float64 support of standardDe…
Browse files Browse the repository at this point in the history
…viationList
  • Loading branch information
joyjwang committed Oct 8, 2024
1 parent 5592226 commit 0141ce4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 39 deletions.
3 changes: 1 addition & 2 deletions x/mongo/driver/topology/rtt_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"sync"
"time"

"go.mongodb.org/mongo-driver/v2/internal/stats"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/mnet"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation"
Expand Down Expand Up @@ -213,7 +212,7 @@ func (r *rttMonitor) appendMovingMin(rtt time.Duration) {

// Collect a sum of stddevs over maxRTTSamplesForMovingMin calls, ignore if calls are less than max
if r.callsToAppendMovingMin >= maxRTTSamplesForMovingMin {
stddev := stats.StandardDeviationList[time.Duration](r.movingMin)
stddev := standardDeviationList(r.movingMin)
r.stddevSum += stddev
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/stats/stats.go → x/mongo/driver/topology/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

package stats
package topology

import (
"container/list"
"math"
"time"
)

func StandardDeviationList[T time.Duration | float64](l *list.List) float64 {
func standardDeviationList(l *list.List) float64 {
if l.Len() == 0 {
return 0
}
Expand All @@ -22,7 +22,7 @@ func StandardDeviationList[T time.Duration | float64](l *list.List) float64 {

for el := l.Front(); el != nil; el = el.Next() {
count++
sample := float64(el.Value.(T))
sample := float64(el.Value.(time.Duration))

delta := sample - mean
mean += delta / count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

package stats
package topology

import (
"container/list"
Expand All @@ -14,38 +14,6 @@ import (
"go.mongodb.org/mongo-driver/v2/internal/assert"
)

func TestStandardDeviationList_Float64(t *testing.T) {
tests := []struct {
name string
data []float64
want float64
}{
{
name: "empty",
data: []float64{},
want: 0,
},
{
name: "multiple",
data: []float64{-1, 1, 6, 8, 10},
want: 4.1665333,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
l := list.New()
for _, d := range test.data {
l.PushBack(d)
}

got := StandardDeviationList[float64](l)

assert.InDelta(t, test.want, got, 1e-6)
})
}
}

func TestStandardDeviationList_Duration(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -75,7 +43,7 @@ func TestStandardDeviationList_Duration(t *testing.T) {
l.PushBack(d)
}

got := StandardDeviationList[time.Duration](l)
got := standardDeviationList(l)

assert.InDelta(t, test.want, got, 1e-6)
})
Expand Down

0 comments on commit 0141ce4

Please sign in to comment.