github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/querier/queryrange/shard_resolver_test.go (about) 1 package queryrange 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 "github.com/grafana/loki/pkg/storage/stores/index/stats" 10 ) 11 12 func TestGuessShardFactor(t *testing.T) { 13 for _, tc := range []struct { 14 stats stats.Stats 15 exp int 16 }{ 17 { 18 // no data == no sharding 19 exp: 0, 20 }, 21 { 22 exp: 4, 23 stats: stats.Stats{ 24 Bytes: p90BytesPerSecond * 4, 25 }, 26 }, 27 { 28 // round up shard factor 29 exp: 16, 30 stats: stats.Stats{ 31 Bytes: p90BytesPerSecond * 15, 32 }, 33 }, 34 { 35 exp: 2, 36 stats: stats.Stats{ 37 Bytes: p90BytesPerSecond + 1, 38 }, 39 }, 40 { 41 exp: 0, 42 stats: stats.Stats{ 43 Bytes: p90BytesPerSecond, 44 }, 45 }, 46 } { 47 t.Run(fmt.Sprintf("%+v", tc.stats), func(t *testing.T) { 48 require.Equal(t, tc.exp, guessShardFactor(tc.stats)) 49 }) 50 } 51 }