MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestRing_ShuffleShard_Shuffling

Function TestRing_ShuffleShard_Shuffling

pkg/ring/ring_test.go:1789–1886  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1787}
1788
1789func TestRing_ShuffleShard_Shuffling(t *testing.T) {
1790 var (
1791 numTenants = 1000
1792 numInstances = 90
1793 numZones = 3
1794 shardSize = 3
1795
1796 // This is the expected theoretical distribution of matching instances
1797 // between different shards, given the settings above. It has been computed
1798 // using this spreadsheet:
1799 // https://docs.google.com/spreadsheets/d/1FXbiWTXi6bdERtamH-IfmpgFq1fNL4GP_KX_yJvbRi4/edit
1800 theoreticalMatchings = map[int]float64{
1801 0: 90.2239,
1802 1: 9.55312,
1803 2: 0.22217,
1804 3: 0.00085,
1805 }
1806 )
1807
1808 // Initialise the ring instances. To have stable tests we generate tokens using a linear
1809 // distribution. Tokens within the same zone are evenly distributed too.
1810 instances := make(map[string]InstanceDesc, numInstances)
1811 for i := range numInstances {
1812 id := fmt.Sprintf("instance-%d", i)
1813 instances[id] = InstanceDesc{
1814 Addr: fmt.Sprintf("127.0.0.%d", i),
1815 Timestamp: time.Now().Unix(),
1816 RegisteredTimestamp: time.Now().Unix(),
1817 State: ACTIVE,
1818 Tokens: generateTokensLinear(i, numInstances, 128),
1819 Zone: fmt.Sprintf("zone-%d", i%numZones),
1820 }
1821 }
1822
1823 // Initialise the ring.
1824 ringDesc := &Desc{Ingesters: instances}
1825 ring := Ring{
1826 cfg: Config{
1827 HeartbeatTimeout: time.Hour,
1828 ZoneAwarenessEnabled: true,
1829 },
1830 ringDesc: ringDesc,
1831 ringTokens: ringDesc.GetTokens(),
1832 ringTokensByZone: ringDesc.getTokensByZone(),
1833 ringInstanceByToken: ringDesc.getTokensInfo(),
1834 ringZones: getZones(ringDesc.getTokensByZone()),
1835 strategy: NewDefaultReplicationStrategy(),
1836 KVClient: &MockClient{},
1837 }
1838
1839 // Compute the shard for each tenant.
1840 shards := map[string][]string{}
1841
1842 for i := 1; i <= numTenants; i++ {
1843 tenantID := fmt.Sprintf("%d", i)
1844 r := ring.ShuffleShard(tenantID, shardSize)
1845 set, err := r.GetAllHealthy(Read)
1846 require.NoError(t, err)

Callers

nothing calls this directly

Calls 8

GetTokensMethod · 0.95
getTokensByZoneMethod · 0.95
getTokensInfoMethod · 0.95
ShuffleShardMethod · 0.95
generateTokensLinearFunction · 0.85
getZonesFunction · 0.85
GetAllHealthyMethod · 0.65

Tested by

no test coverage detected