Skip to content

Commit 10dd597

Browse files
committed
addresses pr comments
Signed-off-by: Owen Diehl <[email protected]>
1 parent 7347d45 commit 10dd597

File tree

14 files changed

+72
-64
lines changed

14 files changed

+72
-64
lines changed

CHANGELOG.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## master / unreleased
44

5+
* [FEATURE] Fan out parallelizable queries to backend queriers concurrently. #1878
6+
* `-querier.sum-shards` (bool)
7+
* Requires a shard-compatible schema (v10+)
8+
* This causes the number of traces to increase accordingly.
9+
* The query-frontend now requires a schema config to determine how/when to shard queries, either from a file or from flags (i.e. by the `config-yaml` CLI flag). This is the same schema config the queriers consume. The schema is only required to use this option.
10+
* It's also advised to increase downstream concurrency controls as well:
11+
* `querier.max-outstanding-requests-per-tenant`
12+
* `querier.max-query-parallelism`
13+
* `querier.max-concurrent`
14+
* `server.grpc-max-concurrent-streams` (for both query-frontends and queriers)
515
* [CHANGE] The frontend http server will now send 502 in case of deadline exceeded and 499 if the user requested cancellation. #2156
616
* [CHANGE] Config file changed to remove top level `config_store` field in favor of a nested `configdb` field. #2125
717
* [CHANGE] Removed unnecessary `frontend.cache-split-interval` in favor of `querier.split-queries-by-interval` both to reduce configuration complexity and guarantee alignment of these two configs. Starting from now, `-querier.cache-results` may only be enabled in conjunction with `-querier.split-queries-by-interval` (previously the cache interval default was `24h` so if you want to preserve the same behaviour you should set `-querier.split-queries-by-interval=24h`). #2040
@@ -62,17 +72,6 @@ Note that the ruler flags need to be changed in this upgrade. You're moving from
6272
Further, if you're using the configs service, we've upgraded the migration library and this requires some manual intervention. See full instructions below to upgrade your PostgreSQL.
6373

6474
* [CHANGE] The frontend component now does not cache results if it finds a `Cache-Control` header and if one of its values is `no-store`. #1974
65-
* [FEATURE] Fan out parallelizable queries to backend queriers concurrently.
66-
* `-querier.sum-shards` (bool)
67-
* Requires a shard-compatible schema (v10+)
68-
* This causes the number of traces to increase accordingly.
69-
* The query-frontend now requires a schema config to determine how/when to shard queries, either from a file or from flags (i.e. by the `config-yaml` CLI flag). This is the same schema config the queriers consume.
70-
* It's also advised to increase downstream concurrency controls as well:
71-
* `querier.max-outstanding-requests-per-tenant`
72-
* `querier.max-query-parallelism`
73-
* `querier.max-concurrent`
74-
* `server.grpc-max-concurrent-streams` (for both query-frontends and queriers)
75-
* [ENHANCEMENT] metric `cortex_ingester_flush_reasons` gets a new `reason` value: `Spread`, when `-ingester.spread-flushes` option is enabled.
7675
* [CHANGE] Flags changed with transition to upstream Prometheus rules manager:
7776
* `-ruler.client-timeout` is now `ruler.configs.client-timeout` in order to match `ruler.configs.url`.
7877
* `-ruler.group-timeout`has been removed.

docs/configuration/arguments.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ The ingester query API was improved over time, but defaults to the old behaviour
8686
- `querier.max-outstanding-requests-per-tenant`
8787
- `querier.max-query-parallelism`
8888
- `querier.max-concurrent`
89+
- `server.grpc-max-concurrent-streams` (for both query-frontends and queriers)
90+
8991
Furthermore, both querier and query-frontend components require the `querier.query-ingesters-within` parameter to know when to start sharding requests (ingester queries are not sharded). It's recommended to align this with `ingester.max-chunk-age`.
9092

91-
Instrumentation (traces) also scale with the number of sharded queries and it's suggested to account for increased throughput there as well.
93+
Instrumentation (traces) also scale with the number of sharded queries and it's suggested to account for increased throughput there as well (for instance via `JAEGER_REPORTER_MAX_QUEUE_SIZE`).
9294

9395
- `-querier.align-querier-with-step`
9496

pkg/chunk/chunk_store_utils.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/prometheus/prometheus/promql"
1111

1212
"github.com/cortexproject/cortex/pkg/chunk/cache"
13-
"github.com/cortexproject/cortex/pkg/querier/astmapper"
1413
"github.com/cortexproject/cortex/pkg/util"
1514
"github.com/cortexproject/cortex/pkg/util/spanlogger"
1615
)
@@ -256,10 +255,3 @@ func (c *Fetcher) processCacheResponse(ctx context.Context, chunks []Chunk, keys
256255
}
257256
return found, missing, err
258257
}
259-
260-
func injectShardLabels(chunks []Chunk, shard astmapper.ShardAnnotation) {
261-
for i, chunk := range chunks {
262-
chunk.Metric = append(chunk.Metric, shard.Label())
263-
chunks[i] = chunk
264-
}
265-
}

pkg/chunk/schema_config.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,6 @@ func (cfg *SchemaConfig) Load() error {
317317
return err
318318
}
319319

320-
for i, periodCfg := range cfg.Configs {
321-
// apply default row shards
322-
if periodCfg.RowShards == 0 {
323-
periodCfg.RowShards = defaultRowShards(periodCfg.Schema)
324-
cfg.Configs[i] = periodCfg
325-
}
326-
}
327-
328320
return cfg.Validate()
329321
}
330322

pkg/chunk/series_store.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,14 @@ func (c *seriesStore) calculateIndexEntries(ctx context.Context, from, through m
534534

535535
return result, missing, nil
536536
}
537+
538+
func injectShardLabels(chunks []Chunk, shard astmapper.ShardAnnotation) {
539+
for i, chunk := range chunks {
540+
541+
b := labels.NewBuilder(chunk.Metric)
542+
l := shard.Label()
543+
b.Set(l.Name, l.Value)
544+
chunk.Metric = b.Labels()
545+
chunks[i] = chunk
546+
}
547+
}

pkg/querier/astmapper/embedded.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ be remapped into vector or matrix selectors utilizing a reserved label containin
2121
const (
2222
// QueryLabel is a reserved label containing an embedded query
2323
QueryLabel = "__cortex_queries__"
24-
// EmbeddedQueryFlag is a reserved label (metric name) denoting an embedded query
25-
EmbeddedQueryFlag = "__embedded_queries__"
24+
// EmbeddedQueriesMetricName is a reserved label (metric name) denoting an embedded query
25+
EmbeddedQueriesMetricName = "__embedded_queries__"
2626
)
2727

2828
// EmbeddedQueries is a wrapper type for encoding queries
@@ -35,17 +35,12 @@ var JSONCodec jsonCodec
3535

3636
type jsonCodec struct{}
3737

38-
func (c jsonCodec) Encode(queries []string) string {
38+
func (c jsonCodec) Encode(queries []string) (string, error) {
3939
embedded := EmbeddedQueries{
4040
Concat: queries,
4141
}
4242
b, err := json.Marshal(embedded)
43-
44-
if err != nil {
45-
panic(err)
46-
}
47-
48-
return string(b)
43+
return string(b), err
4944
}
5045

5146
func (c jsonCodec) Decode(encoded string) (queries []string, err error) {
@@ -69,7 +64,10 @@ func VectorSquasher(nodes ...promql.Node) (promql.Expr, error) {
6964
strs = append(strs, node.String())
7065
}
7166

72-
encoded := JSONCodec.Encode(strs)
67+
encoded, err := JSONCodec.Encode(strs)
68+
if err != nil {
69+
return nil, err
70+
}
7371

7472
embeddedQuery, err := labels.NewMatcher(labels.MatchEqual, QueryLabel, encoded)
7573

@@ -78,7 +76,7 @@ func VectorSquasher(nodes ...promql.Node) (promql.Expr, error) {
7876
}
7977

8078
return &promql.VectorSelector{
81-
Name: EmbeddedQueryFlag,
79+
Name: EmbeddedQueriesMetricName,
8280
LabelMatchers: []*labels.Matcher{embeddedQuery},
8381
}, nil
8482

pkg/querier/astmapper/parallel.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package astmapper
22

33
import (
4-
"github.com/pkg/errors"
4+
"fmt"
5+
6+
"github.com/cortexproject/cortex/pkg/util"
7+
"github.com/go-kit/kit/log/level"
58
"github.com/prometheus/prometheus/promql"
69
)
710

@@ -76,7 +79,8 @@ func CanParallel(node promql.Node) bool {
7679
return true
7780

7881
default:
79-
panic(errors.Errorf("CanParallel: unhandled node type %T", node))
82+
level.Error(util.Logger).Log("err", fmt.Sprintf("CanParallel: unhandled node type %T", node))
83+
return false
8084
}
8185

8286
}

pkg/querier/astmapper/subtree_folder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ func (f *subtreeFolder) MapNode(node promql.Node) (promql.Node, bool, error) {
4242
func isEmbedded(node promql.Node) (bool, error) {
4343
switch n := node.(type) {
4444
case *promql.VectorSelector:
45-
if n.Name == EmbeddedQueryFlag {
45+
if n.Name == EmbeddedQueriesMetricName {
4646
return true, nil
4747
}
4848

4949
case *promql.MatrixSelector:
50-
if n.Name == EmbeddedQueryFlag {
50+
if n.Name == EmbeddedQueriesMetricName {
5151
return true, nil
5252
}
5353

pkg/querier/queryrange/instrumentation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var (
2525
splitByCounter = promauto.NewCounter(prometheus.CounterOpts{
2626
Namespace: "cortex",
2727
Name: "frontend_split_queries_total",
28-
Help: "Total number of split (parallelized) request segments",
28+
Help: "Total number of underlying query requests after the split by interval is applied",
2929
})
3030
)
3131

pkg/querier/queryrange/queryable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (q *DownstreamQuerier) Select(
4141
var embeddedQuery string
4242
var isEmbedded bool
4343
for _, matcher := range matchers {
44-
if matcher.Name == labels.MetricName && matcher.Value == astmapper.EmbeddedQueryFlag {
44+
if matcher.Name == labels.MetricName && matcher.Value == astmapper.EmbeddedQueriesMetricName {
4545
isEmbedded = true
4646
}
4747

0 commit comments

Comments
 (0)