-
Notifications
You must be signed in to change notification settings - Fork 825
Added shuffle sharding support to generate a subring #3090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pracucci
merged 10 commits into
cortexproject:master
from
pracucci:fix-shuffle-sharding
Sep 17, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
00b0600
Added shuffle sharding support to generate a subring
pracucci 485ceb6
Solved all TODOs
pracucci 115c735
Simplified unlock
pracucci 162569f
Fixed linter
pracucci baeeed2
Added benchmark
pracucci 6b09381
Replaced Subring() with ShuffleShard()
pracucci 7131ffc
Small improvements
pracucci 9df4eac
Shortened CHANGELOG entry
pracucci fe24ed2
Make golang doc happy
pracucci 048341a
Fixed flag name and added integration test
pracucci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// +build requires_docker | ||
|
||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/prometheus/prometheus/pkg/labels" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cortexproject/cortex/integration/e2e" | ||
e2edb "github.com/cortexproject/cortex/integration/e2e/db" | ||
"github.com/cortexproject/cortex/integration/e2ecortex" | ||
) | ||
|
||
func TestIngesterSharding(t *testing.T) { | ||
const numSeriesToPush = 1000 | ||
|
||
tests := map[string]struct { | ||
shardingStrategy string | ||
tenantShardSize int | ||
expectedIngestersWithSeries int | ||
}{ | ||
"default sharding strategy should spread series across all ingesters": { | ||
shardingStrategy: "default", | ||
tenantShardSize: 2, // Ignored by default strategy. | ||
expectedIngestersWithSeries: 3, | ||
}, | ||
"shuffle-sharding strategy should spread series across the configured shard size number of ingesters": { | ||
shardingStrategy: "shuffle-sharding", | ||
tenantShardSize: 2, | ||
expectedIngestersWithSeries: 2, | ||
}, | ||
} | ||
|
||
for testName, testData := range tests { | ||
t.Run(testName, func(t *testing.T) { | ||
s, err := e2e.NewScenario(networkName) | ||
require.NoError(t, err) | ||
defer s.Close() | ||
|
||
flags := BlocksStorageFlags | ||
flags["-distributor.sharding-strategy"] = testData.shardingStrategy | ||
flags["-distributor.ingestion-tenant-shard-size"] = strconv.Itoa(testData.tenantShardSize) | ||
|
||
// Start dependencies. | ||
consul := e2edb.NewConsul() | ||
minio := e2edb.NewMinio(9000, flags["-blocks-storage.s3.bucket-name"]) | ||
require.NoError(t, s.StartAndWaitReady(consul, minio)) | ||
|
||
// Start Cortex components. | ||
distributor := e2ecortex.NewDistributor("distributor", consul.NetworkHTTPEndpoint(), flags, "") | ||
ingester1 := e2ecortex.NewIngester("ingester-1", consul.NetworkHTTPEndpoint(), flags, "") | ||
ingester2 := e2ecortex.NewIngester("ingester-2", consul.NetworkHTTPEndpoint(), flags, "") | ||
ingester3 := e2ecortex.NewIngester("ingester-3", consul.NetworkHTTPEndpoint(), flags, "") | ||
querier := e2ecortex.NewQuerier("querier", consul.NetworkHTTPEndpoint(), flags, "") | ||
require.NoError(t, s.StartAndWaitReady(distributor, ingester1, ingester2, ingester3, querier)) | ||
|
||
// Wait until distributor and queriers have updated the ring. | ||
require.NoError(t, distributor.WaitSumMetricsWithOptions(e2e.Equals(3), []string{"cortex_ring_members"}, e2e.WithLabelMatchers( | ||
labels.MustNewMatcher(labels.MatchEqual, "name", "ingester"), | ||
labels.MustNewMatcher(labels.MatchEqual, "state", "ACTIVE")))) | ||
|
||
require.NoError(t, querier.WaitSumMetricsWithOptions(e2e.Equals(3), []string{"cortex_ring_members"}, e2e.WithLabelMatchers( | ||
labels.MustNewMatcher(labels.MatchEqual, "name", "ingester"), | ||
labels.MustNewMatcher(labels.MatchEqual, "state", "ACTIVE")))) | ||
|
||
// Push series. | ||
now := time.Now() | ||
|
||
client, err := e2ecortex.NewClient(distributor.HTTPEndpoint(), "", "", "", userID) | ||
require.NoError(t, err) | ||
|
||
for i := 1; i <= numSeriesToPush; i++ { | ||
series, _ := generateSeries(fmt.Sprintf("series_%d", i), now) | ||
res, err := client.Push(series) | ||
require.NoError(t, err) | ||
require.Equal(t, 200, res.StatusCode) | ||
} | ||
|
||
// Extract metrics from ingesters. | ||
numIngestersWithSeries := 0 | ||
totalIngestedSeries := 0 | ||
|
||
for _, ing := range []*e2ecortex.CortexService{ingester1, ingester2, ingester3} { | ||
values, err := ing.SumMetrics([]string{"cortex_ingester_memory_series"}) | ||
require.NoError(t, err) | ||
|
||
numMemorySeries := e2e.SumValues(values) | ||
totalIngestedSeries += int(numMemorySeries) | ||
if numMemorySeries > 0 { | ||
numIngestersWithSeries++ | ||
} | ||
} | ||
|
||
require.Equal(t, testData.expectedIngestersWithSeries, numIngestersWithSeries) | ||
require.Equal(t, numSeriesToPush, totalIngestedSeries) | ||
|
||
// Ensure no service-specific metrics prefix is used by the wrong service. | ||
assertServiceMetricsPrefixes(t, Distributor, distributor) | ||
assertServiceMetricsPrefixes(t, Ingester, ingester1) | ||
assertServiceMetricsPrefixes(t, Ingester, ingester2) | ||
assertServiceMetricsPrefixes(t, Ingester, ingester3) | ||
assertServiceMetricsPrefixes(t, Querier, querier) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it based on the similar "store_gateway_tenant_shard_size" flag from https://github.com/cortexproject/cortex/pull/3069/files you are planning to name all the similar flags "_tenant_shard_size"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, are you planning to take/keep the -experimental off this when you are ready to submit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I do. The reason is that overrides are specified within the same YAML node, so we need a way to clearly differentiate them. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would plan to remove the experimental flag once ready to submit, unless you have any concerns. Generally speaking, I think originally adding the experimental prefix to CLI flags was a mistake and shouldn't be done anymore. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean document as experimental but not name the flag experimental? That sounds fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes Richard, you're correct (sorry for being unclear). This way, once we're all comfortable marking it stable, it will just be a doc change instead of a config change.