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

Function TestDistributor_MetricsMetadata

pkg/distributor/distributor_test.go:3151–3209  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3149}
3150
3151func TestDistributor_MetricsMetadata(t *testing.T) {
3152 t.Parallel()
3153 const numIngesters = 5
3154
3155 tests := map[string]struct {
3156 shuffleShardEnabled bool
3157 shuffleShardSize int
3158 expectedIngesters int
3159 }{
3160 "should query all ingesters if shuffle sharding is disabled": {
3161 shuffleShardEnabled: false,
3162 expectedIngesters: numIngesters,
3163 },
3164 "should query all ingesters if shuffle sharding is enabled but shard size is 0": {
3165 shuffleShardEnabled: true,
3166 shuffleShardSize: 0,
3167 expectedIngesters: numIngesters,
3168 },
3169 "should query only ingesters belonging to tenant's subring if shuffle sharding is enabled": {
3170 shuffleShardEnabled: true,
3171 shuffleShardSize: 3,
3172 expectedIngesters: 3,
3173 },
3174 }
3175
3176 for testName, testData := range tests {
3177 t.Run(testName, func(t *testing.T) {
3178 t.Parallel()
3179 // Create distributor
3180 ds, ingesters, _, _ := prepare(t, prepConfig{
3181 numIngesters: numIngesters,
3182 happyIngesters: numIngesters,
3183 numDistributors: 1,
3184 shardByAllLabels: true,
3185 shuffleShardEnabled: testData.shuffleShardEnabled,
3186 shuffleShardSize: testData.shuffleShardSize,
3187 limits: nil,
3188 })
3189
3190 // Push metadata
3191 ctx := user.InjectOrgID(context.Background(), "test")
3192
3193 req := makeWriteRequest(0, 0, 10, 0)
3194 _, err := ds[0].Push(ctx, req)
3195 require.NoError(t, err)
3196
3197 // Assert on metric metadata
3198 metadata, err := ds[0].MetricsMetadata(ctx, &client.MetricsMetadataRequest{Limit: -1, LimitPerMetric: -1, Metric: ""})
3199 require.NoError(t, err)
3200 assert.Equal(t, 10, len(metadata))
3201
3202 // Check how many ingesters have been queried.
3203 // Due to the quorum the distributor could cancel the last request towards ingesters
3204 // if all other ones are successful, so we're good either has been queried X or X-1
3205 // ingesters.
3206 assert.Contains(t, []int{testData.expectedIngesters, testData.expectedIngesters - 1}, countMockIngestersCalls(ingesters, "MetricsMetadata"))
3207 })
3208 }

Callers

nothing calls this directly

Calls 7

makeWriteRequestFunction · 0.85
countMockIngestersCallsFunction · 0.85
prepareFunction · 0.70
RunMethod · 0.65
PushMethod · 0.65
MetricsMetadataMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected