Skip to content

Commit ad1949a

Browse files
committed
Merge branch 'master' into cache-freshness
Signed-off-by: Annanay <[email protected]>
2 parents 756993a + af9bdc9 commit ad1949a

34 files changed

+1430
-473
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* [FEATURE] Experimental: Added support for `/api/v1/metadata` Prometheus-based endpoint. #2549
3535
* [FEATURE] Add ability to limit concurrent queries to Cassandra with `-cassandra.query-concurrency` flag. #2562
3636
* [FEATURE] TLS config options added for GRPC clients in Querier (Query-frontend client & Ingester client), Ruler, Store Gateway, as well as HTTP client in Config store client. #2502
37+
* [ENHANCEMENT] `query-tee` supports `/metadata`, `/alerts`, and `/rules` #2600
3738
* [ENHANCEMENT] Ruler: Automatically remove unhealthy rulers from the ring. #2587
3839
* [ENHANCEMENT] Experimental TSDB: sample ingestion errors are now reported via existing `cortex_discarded_samples_total` metric. #2370
3940
* [ENHANCEMENT] Failures on samples at distributors and ingesters return the first validation error as opposed to the last. #2383
@@ -82,6 +83,7 @@
8283
* `cortex_storegateway_blocks_last_successful_sync_timestamp_seconds`
8384
* [ENHANCEMENT] Experimental TSDB: added the flag `-experimental.tsdb.wal-compression-enabled` to allow to enable TSDB WAL compression. #2585
8485
* [ENHANCEMENT] Experimental TSDB: Querier and store-gateway components can now use so-called "caching bucket", which can currently cache fetched chunks into shared memcached server. #2572
86+
* [ENHANCEMENT] Experimental TSDB: added per-tenant blocks sharding support in the compactor, in order to parallelize blocks compaction for a single tenant in a single node. Sharding can be enabled via `-compactor.per-tenant-num-shards` while the parallelization can be controlled with `-compactor.per-tenant-shards-concurrency`. #2599
8587
* [BUGFIX] Ruler: Ensure temporary rule files with special characters are properly mapped and cleaned up. #2506
8688
* [BUGFIX] Fixes #2411, Ensure requests are properly routed to the prometheus api embedded in the query if `-server.path-prefix` is set. #2372
8789
* [BUGFIX] Experimental TSDB: fixed chunk data corruption when querying back series using the experimental blocks storage. #2400
@@ -95,6 +97,7 @@
9597
* [BUGFIX] Querier: Fixed a situation where querier would crash because of an unresponsive frontend instance. #2569
9698
* [BUGFIX] Fixed collection of tracing spans from Thanos components used internally. #2584
9799
* [BUGFIX] Experimental TSDB: fixed memory leak in ingesters. #2586
100+
* [BUGFIX] Ingester: Fix an ingester starting up in the JOINING state and staying there forever. #2565
98101

99102
## 1.0.1 / 2020-04-23
100103

cmd/cortex/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func main() {
104104
util.InitEvents(eventSampleRate)
105105

106106
// Setting the environment variable JAEGER_AGENT_HOST enables tracing
107-
if trace, err := tracing.NewFromEnv("cortex-" + cfg.Target.String()); err != nil {
107+
if trace, err := tracing.NewFromEnv("cortex-" + cfg.Target); err != nil {
108108
level.Error(util.Logger).Log("msg", "Failed to setup tracing", "err", err.Error())
109109
} else {
110110
defer trace.Close()

cmd/cortex/main_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@ func TestFlagParsing(t *testing.T) {
2626
stderrMessage: configFileOption,
2727
},
2828

29-
// check that config file is used
30-
"config with unknown target": {
31-
yaml: "target: unknown",
32-
stderrMessage: "unrecognised module name: unknown",
33-
},
34-
35-
"argument with unknown target": {
36-
arguments: []string{"-target=unknown"},
37-
stderrMessage: "unrecognised module name: unknown",
38-
},
39-
4029
"unknown flag": {
4130
arguments: []string{"-unknown.flag"},
4231
stderrMessage: "-unknown.flag",
@@ -48,12 +37,6 @@ func TestFlagParsing(t *testing.T) {
4837
stdoutMessage: "target: ingester",
4938
},
5039

51-
"config with wrong argument override": {
52-
yaml: "target: ingester",
53-
arguments: []string{"-target=unknown"},
54-
stderrMessage: "unrecognised module name: unknown",
55-
},
56-
5740
"default values": {
5841
stdoutMessage: "target: all\n",
5942
},
@@ -63,11 +46,6 @@ func TestFlagParsing(t *testing.T) {
6346
stdoutMessage: "target: ingester\n",
6447
},
6548

66-
"config without expand-env": {
67-
yaml: "target: $TARGET",
68-
stderrMessage: "Error parsing config file: unrecognised module name: $TARGET\n",
69-
},
70-
7149
"config with expand-env": {
7250
arguments: []string{"-config.expand-env"},
7351
yaml: "target: $TARGET",

cmd/query-tee/proxy.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,25 @@ func (p *Proxy) Start() error {
9999
w.WriteHeader(http.StatusOK)
100100
}))
101101

102-
// Read endpoints.
103-
router.Path("/api/v1/query").Methods("GET").Handler(NewProxyEndpoint(p.backends, "api_v1_query", p.metrics, p.logger))
104-
router.Path("/api/v1/query_range").Methods("GET").Handler(NewProxyEndpoint(p.backends, "api_v1_query_range", p.metrics, p.logger))
105-
router.Path("/api/v1/labels").Methods("GET").Handler(NewProxyEndpoint(p.backends, "api_v1_labels", p.metrics, p.logger))
106-
router.Path("/api/v1/label/{name}/values").Methods("GET").Handler(NewProxyEndpoint(p.backends, "api_v1_label_name_values", p.metrics, p.logger))
107-
router.Path("/api/v1/series").Methods("GET").Handler(NewProxyEndpoint(p.backends, "api_v1_series", p.metrics, p.logger))
102+
endpoints := []struct {
103+
endpoint string
104+
methods string
105+
routeName string
106+
}{
107+
{"/api/v1/query", "GET", "api_v1_query"},
108+
{"/api/v1/query_range", "GET", "api_v1_query_range"},
109+
{"/api/v1/labels", "GET", "api_v1_labels"},
110+
{"/api/v1/label/{name}/values", "GET", "api_v1_label_name_values"},
111+
{"/api/v1/series", "GET", "api_v1_series"},
112+
{"/api/v1/metadata", "GET", "api_v1_metadata"},
113+
{"/api/v1/rules", "GET", "api_v1_rules"},
114+
{"/api/v1/alerts", "GET", "api_v1_alerts"},
115+
}
116+
117+
// Read endpoints
118+
for _, e := range endpoints {
119+
router.Path(e.endpoint).Methods(e.methods).Handler(NewProxyEndpoint(p.backends, e.routeName, p.metrics, p.logger))
120+
}
108121

109122
p.srvListener = listener
110123
p.srv = &http.Server{

docs/configuration/config-file-reference.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,15 @@ sharding_ring:
29932993
# the ring.
29942994
# CLI flag: -compactor.ring.heartbeat-timeout
29952995
[heartbeat_timeout: <duration> | default = 1m]
2996+
2997+
# Number of shards a single tenant blocks should be grouped into (0 or 1 means
2998+
# per-tenant blocks sharding is disabled).
2999+
# CLI flag: -compactor.per-tenant-num-shards
3000+
[per_tenant_num_shards: <int> | default = 1]
3001+
3002+
# Number of concurrent shards compacted for a single tenant.
3003+
# CLI flag: -compactor.per-tenant-shards-concurrency
3004+
[per_tenant_shards_concurrency: <int> | default = 1]
29963005
```
29973006

29983007
### `store_gateway_config`

docs/operations/blocks-storage.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,15 @@ compactor:
613613
# within the ring.
614614
# CLI flag: -compactor.ring.heartbeat-timeout
615615
[heartbeat_timeout: <duration> | default = 1m]
616+
617+
# Number of shards a single tenant blocks should be grouped into (0 or 1 means
618+
# per-tenant blocks sharding is disabled).
619+
# CLI flag: -compactor.per-tenant-num-shards
620+
[per_tenant_num_shards: <int> | default = 1]
621+
622+
# Number of concurrent shards compacted for a single tenant.
623+
# CLI flag: -compactor.per-tenant-shards-concurrency
624+
[per_tenant_shards_concurrency: <int> | default = 1]
616625
```
617626

618627
## Known issues

docs/operations/query-tee.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ The following Prometheus API endpoints are supported by `query-tee`:
3535
- `/api/v1/labels` (GET)
3636
- `/api/v1/label/{name}/values` (GET)
3737
- `/api/v1/series` (GET)
38+
- `/api/v1/metadata` (GET)
39+
- `/api/v1/alerts` (GET)
40+
- `/api/v1/rules` (GET)
3841

3942
### Authentication
4043

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ require (
5050
github.com/segmentio/fasthash v0.0.0-20180216231524-a72b379d632e
5151
github.com/spf13/afero v1.2.2
5252
github.com/stretchr/testify v1.4.0
53-
github.com/thanos-io/thanos v0.12.3-0.20200507181659-b9ff23c5c31d
53+
github.com/thanos-io/thanos v0.12.3-0.20200518091645-762eb5e1dfab
5454
github.com/uber/jaeger-client-go v2.20.1+incompatible
5555
github.com/weaveworks/common v0.0.0-20200512154658-384f10054ec5
5656
go.etcd.io/bbolt v1.3.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
869869
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
870870
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
871871
github.com/thanos-io/thanos v0.8.1-0.20200109203923-552ffa4c1a0d/go.mod h1:usT/TxtJQ7DzinTt+G9kinDQmRS5sxwu0unVKZ9vdcw=
872-
github.com/thanos-io/thanos v0.12.3-0.20200507181659-b9ff23c5c31d h1:rNFFyjaZmsyB0EItY6EM+QN2PdDoxIeCNy8CbIbIxNo=
873-
github.com/thanos-io/thanos v0.12.3-0.20200507181659-b9ff23c5c31d/go.mod h1:N3stAuvPDLaWMQym7uDXAoAanu4ujieMjK7zzxJzky4=
872+
github.com/thanos-io/thanos v0.12.3-0.20200518091645-762eb5e1dfab h1:MDobfwpPIBYUbSaynWnGKNKECcAxYiJO9d8q/TjJm4M=
873+
github.com/thanos-io/thanos v0.12.3-0.20200518091645-762eb5e1dfab/go.mod h1:N3stAuvPDLaWMQym7uDXAoAanu4ujieMjK7zzxJzky4=
874874
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
875875
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
876876
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package compactor
2+
3+
import (
4+
"context"
5+
"strconv"
6+
7+
"github.com/oklog/ulid"
8+
"github.com/thanos-io/thanos/pkg/block/metadata"
9+
"github.com/thanos-io/thanos/pkg/extprom"
10+
11+
"github.com/cortexproject/cortex/pkg/ingester/client"
12+
cortex_tsdb "github.com/cortexproject/cortex/pkg/storage/tsdb"
13+
)
14+
15+
type BlocksShardingFilter struct {
16+
shards uint32
17+
}
18+
19+
func NewBlocksShardingFilter(shards uint32) *BlocksShardingFilter {
20+
return &BlocksShardingFilter{
21+
shards: shards,
22+
}
23+
}
24+
25+
func (f *BlocksShardingFilter) Filter(_ context.Context, metas map[ulid.ULID]*metadata.Meta, _ *extprom.TxGaugeVec) error {
26+
for _, m := range metas {
27+
// Just remove the ingester ID label if sharding is disabled.
28+
if f.shards <= 1 {
29+
delete(m.Thanos.Labels, cortex_tsdb.IngesterIDExternalLabel)
30+
continue
31+
}
32+
33+
// Skip any block already containing the shard ID to avoid any manipulation
34+
// (ie. in case the sharding algorithm changes over the time).
35+
if _, ok := m.Thanos.Labels[cortex_tsdb.ShardIDExternalLabel]; ok {
36+
continue
37+
}
38+
39+
// Skip any block without the ingester ID, which means the block has been generated
40+
// before the introduction of the ingester ID.
41+
ingesterID, ok := m.Thanos.Labels[cortex_tsdb.IngesterIDExternalLabel]
42+
if !ok {
43+
continue
44+
}
45+
46+
// Compute the shard ID and replace the ingester label with the shard label
47+
// so that the compactor will group blocks based on the shard.
48+
shardID := shardByIngesterID(ingesterID, f.shards)
49+
delete(m.Thanos.Labels, cortex_tsdb.IngesterIDExternalLabel)
50+
m.Thanos.Labels[cortex_tsdb.ShardIDExternalLabel] = shardID
51+
}
52+
53+
return nil
54+
}
55+
56+
// hashIngesterID returns a 32-bit hash of the ingester ID.
57+
func hashIngesterID(id string) uint32 {
58+
h := client.HashNew32()
59+
h = client.HashAdd32(h, id)
60+
return h
61+
}
62+
63+
// shardByIngesterID returns the shard given an ingester ID.
64+
func shardByIngesterID(id string, numShards uint32) string {
65+
return strconv.Itoa(int(hashIngesterID(id) % numShards))
66+
}

0 commit comments

Comments
 (0)