(t *testing.T)
| 1574 | } |
| 1575 | |
| 1576 | func TestDistributor_PushQuery(t *testing.T) { |
| 1577 | t.Parallel() |
| 1578 | const shuffleShardSize = 5 |
| 1579 | |
| 1580 | ctx := user.InjectOrgID(context.Background(), "user") |
| 1581 | nameMatcher := mustEqualMatcher(model.MetricNameLabel, "foo") |
| 1582 | barMatcher := mustEqualMatcher("bar", "baz") |
| 1583 | |
| 1584 | type testcase struct { |
| 1585 | name string |
| 1586 | numIngesters int |
| 1587 | happyIngesters int |
| 1588 | samples int |
| 1589 | metadata int |
| 1590 | matchers []*labels.Matcher |
| 1591 | expectedIngesters int |
| 1592 | expectedResponse model.Matrix |
| 1593 | expectedError error |
| 1594 | shardByAllLabels bool |
| 1595 | shuffleShardEnabled bool |
| 1596 | } |
| 1597 | |
| 1598 | // We'll programmatically build the test cases now, as we want complete |
| 1599 | // coverage along quite a few different axis. |
| 1600 | testcases := []testcase{} |
| 1601 | |
| 1602 | // Run every test in both sharding modes. |
| 1603 | for _, shardByAllLabels := range []bool{true, false} { |
| 1604 | |
| 1605 | // Test with between 2 and 10 ingesters. |
| 1606 | for numIngesters := 2; numIngesters < 10; numIngesters++ { |
| 1607 | |
| 1608 | // Test with between 0 and numIngesters "happy" ingesters. |
| 1609 | for happyIngesters := 0; happyIngesters <= numIngesters; happyIngesters++ { |
| 1610 | |
| 1611 | // Test either with shuffle-sharding enabled or disabled. |
| 1612 | for _, shuffleShardEnabled := range []bool{false, true} { |
| 1613 | scenario := fmt.Sprintf("shardByAllLabels=%v, numIngester=%d, happyIngester=%d, shuffleSharding=%v)", shardByAllLabels, numIngesters, happyIngesters, shuffleShardEnabled) |
| 1614 | |
| 1615 | // The number of ingesters we expect to query depends whether shuffle sharding and/or |
| 1616 | // shard by all labels are enabled. |
| 1617 | var expectedIngesters int |
| 1618 | if shuffleShardEnabled { |
| 1619 | expectedIngesters = min(shuffleShardSize, numIngesters) |
| 1620 | } else if shardByAllLabels { |
| 1621 | expectedIngesters = numIngesters |
| 1622 | } else { |
| 1623 | expectedIngesters = 3 // Replication factor |
| 1624 | } |
| 1625 | |
| 1626 | // When we're not sharding by metric name, queriers with more than one |
| 1627 | // failed ingester should fail. |
| 1628 | if shardByAllLabels && numIngesters-happyIngesters > 1 { |
| 1629 | testcases = append(testcases, testcase{ |
| 1630 | name: fmt.Sprintf("ExpectFail(%s)", scenario), |
| 1631 | numIngesters: numIngesters, |
| 1632 | happyIngesters: happyIngesters, |
| 1633 | matchers: []*labels.Matcher{nameMatcher, barMatcher}, |
nothing calls this directly
no test coverage detected