Skip to content

Commit c0b0238

Browse files
slim-beanpracucci
andauthored
Experimental TSDB: Add support for local filesystem backend (#2245)
* Experimental TSDB: Add support for local filesystem object store Signed-off-by: Edward Welch <[email protected]> * Updated doc Signed-off-by: Marco Pracucci <[email protected]> * Renamed blocks storage filesystem directory config option name to keep it more consistent with the rest of the config Signed-off-by: Marco Pracucci <[email protected]> * Removed unused params from filesystem.NewBucketClient() Signed-off-by: Marco Pracucci <[email protected]> Co-authored-by: Marco Pracucci <[email protected]>
1 parent ea4c0fb commit c0b0238

File tree

11 files changed

+281
-7
lines changed

11 files changed

+281
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* `-flusher.wal-dir` for the WAL directory to recover from.
99
* `-flusher.concurrent-flushes` for number of concurrent flushes.
1010
* `-flusher.flush-op-timeout` is duration after which a flush should timeout.
11+
* [ENHANCEMENT] Experimental TSDB: Add support for local `filesystem` backend. #2245
1112

1213
## 0.7.0-rc.0 / 2020-03-09
1314

docs/architecture.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ The blocks storage doesn't require a dedicated storage backend for the index. Th
6161
* [Amazon S3](https://aws.amazon.com/s3)
6262
* [Google Cloud Storage](https://cloud.google.com/storage/)
6363
* [Microsoft Azure Storage](https://azure.microsoft.com/en-us/services/storage/)
64+
* [Local Filesystem](https://thanos.io/storage.md/#filesystem) (single node only)
6465

6566
For more information, please check out the [Blocks storage](operations/blocks-storage.md) documentation.
6667

docs/configuration/config-file-reference.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,7 @@ The `tsdb_config` configures the experimental blocks storage.
21642164
# CLI flag: -experimental.tsdb.ship-concurrency
21652165
[ship_concurrency: <int> | default = 10]
21662166
2167-
# Backend storage to use. Either "s3" or "gcs".
2167+
# Backend storage to use. Supported backends are: s3, gcs, azure, filesystem.
21682168
# CLI flag: -experimental.tsdb.backend
21692169
[backend: <string> | default = "s3"]
21702170
@@ -2295,6 +2295,11 @@ azure:
22952295
# Number of retries for recoverable errors
22962296
# CLI flag: -experimental.tsdb.azure.max-retries
22972297
[max_retries: <int> | default = 20]
2298+
2299+
filesystem:
2300+
# Local filesystem storage directory.
2301+
# CLI flag: -experimental.tsdb.filesystem.dir
2302+
[dir: <string> | default = ""]
22982303
```
22992304

23002305
### `compactor_config`

docs/operations/blocks-storage.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The supported backends for the blocks storage are:
1212
* [Amazon S3](https://aws.amazon.com/s3)
1313
* [Google Cloud Storage](https://cloud.google.com/storage/)
1414
* [Microsoft Azure Storage](https://azure.microsoft.com/en-us/services/storage/)
15+
* [Local Filesystem](https://thanos.io/storage.md/#filesystem) (single node only)
1516

1617
_Internally, this storage engine is based on [Thanos](https://thanos.io), but no Thanos knowledge is required in order to run it._
1718

@@ -119,7 +120,7 @@ tsdb:
119120
# CLI flag: -experimental.tsdb.ship-concurrency
120121
[ship_concurrency: <int> | default = 10]
121122
122-
# Backend storage to use. Either "s3" or "gcs".
123+
# Backend storage to use. Supported backends are: s3, gcs, azure, filesystem.
123124
# CLI flag: -experimental.tsdb.backend
124125
[backend: <string> | default = "s3"]
125126
@@ -252,6 +253,11 @@ tsdb:
252253
# Number of retries for recoverable errors
253254
# CLI flag: -experimental.tsdb.azure.max-retries
254255
[max_retries: <int> | default = 20]
256+
257+
filesystem:
258+
# Local filesystem storage directory.
259+
# CLI flag: -experimental.tsdb.filesystem.dir
260+
[dir: <string> | default = ""]
255261
```
256262
### `compactor_config`
257263

docs/operations/blocks-storage.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The supported backends for the blocks storage are:
1212
* [Amazon S3](https://aws.amazon.com/s3)
1313
* [Google Cloud Storage](https://cloud.google.com/storage/)
1414
* [Microsoft Azure Storage](https://azure.microsoft.com/en-us/services/storage/)
15+
* [Local Filesystem](https://thanos.io/storage.md/#filesystem) (single node only)
1516

1617
_Internally, this storage engine is based on [Thanos](https://thanos.io), but no Thanos knowledge is required in order to run it._
1718

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package filesystem
2+
3+
import (
4+
"github.com/thanos-io/thanos/pkg/objstore"
5+
"github.com/thanos-io/thanos/pkg/objstore/filesystem"
6+
)
7+
8+
// NewBucketClient creates a new filesystem bucket client
9+
func NewBucketClient(cfg Config) (objstore.Bucket, error) {
10+
return filesystem.NewBucket(cfg.Directory)
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package filesystem
2+
3+
import "flag"
4+
5+
// Config stores the configuration for storing and accessing objects in the local filesystem.
6+
type Config struct {
7+
Directory string `yaml:"dir"`
8+
}
9+
10+
// RegisterFlags registers the flags for TSDB filesystem storage
11+
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
12+
f.StringVar(&cfg.Directory, "experimental.tsdb.filesystem.dir", "", "Local filesystem storage directory.")
13+
}

pkg/storage/tsdb/bucket_client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/thanos-io/thanos/pkg/objstore"
88

99
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/azure"
10+
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/filesystem"
1011
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/gcs"
1112
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/s3"
1213
)
@@ -20,6 +21,8 @@ func NewBucketClient(ctx context.Context, cfg Config, name string, logger log.Lo
2021
return gcs.NewBucketClient(ctx, cfg.GCS, name, logger)
2122
case BackendAzure:
2223
return azure.NewBucketClient(cfg.Azure, name, logger)
24+
case BackendFilesystem:
25+
return filesystem.NewBucketClient(cfg.Filesystem)
2326
default:
2427
return nil, errUnsupportedBackend
2528
}

pkg/storage/tsdb/config.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package tsdb
33
import (
44
"errors"
55
"flag"
6+
"fmt"
67
"path/filepath"
78
"strings"
89
"time"
910

1011
"github.com/alecthomas/units"
1112

1213
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/azure"
14+
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/filesystem"
1315
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/gcs"
1416
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/s3"
1517
)
@@ -24,12 +26,17 @@ const (
2426
// BackendAzure is the value for the Azure storage backend
2527
BackendAzure = "azure"
2628

29+
// BackendFilesystem is the value for the filesystem storge backend
30+
BackendFilesystem = "filesystem"
31+
2732
// TenantIDExternalLabel is the external label set when shipping blocks to the storage
2833
TenantIDExternalLabel = "__org_id__"
2934
)
3035

3136
// Validation errors
3237
var (
38+
supportedBackends = []string{BackendS3, BackendGCS, BackendAzure, BackendFilesystem}
39+
3340
errUnsupportedBackend = errors.New("unsupported TSDB storage backend")
3441
errInvalidShipConcurrency = errors.New("invalid TSDB ship concurrency")
3542
errInvalidCompactionInterval = errors.New("invalid TSDB compaction interval")
@@ -54,9 +61,10 @@ type Config struct {
5461
MaxTSDBOpeningConcurrencyOnStartup int `yaml:"max_tsdb_opening_concurrency_on_startup"`
5562

5663
// Backends
57-
S3 s3.Config `yaml:"s3"`
58-
GCS gcs.Config `yaml:"gcs"`
59-
Azure azure.Config `yaml:"azure"`
64+
S3 s3.Config `yaml:"s3"`
65+
GCS gcs.Config `yaml:"gcs"`
66+
Azure azure.Config `yaml:"azure"`
67+
Filesystem filesystem.Config `yaml:"filesystem"`
6068
}
6169

6270
// DurationList is the block ranges for a tsdb
@@ -102,6 +110,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
102110
cfg.GCS.RegisterFlags(f)
103111
cfg.Azure.RegisterFlags(f)
104112
cfg.BucketStore.RegisterFlags(f)
113+
cfg.Filesystem.RegisterFlags(f)
105114

106115
if len(cfg.BlockRanges) == 0 {
107116
cfg.BlockRanges = []time.Duration{2 * time.Hour} // Default 2h block
@@ -112,7 +121,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
112121
f.DurationVar(&cfg.Retention, "experimental.tsdb.retention-period", 6*time.Hour, "TSDB blocks retention in the ingester before a block is removed. This should be larger than the block_ranges_period and large enough to give queriers enough time to discover newly uploaded blocks.")
113122
f.DurationVar(&cfg.ShipInterval, "experimental.tsdb.ship-interval", 1*time.Minute, "How frequently the TSDB blocks are scanned and new ones are shipped to the storage. 0 means shipping is disabled.")
114123
f.IntVar(&cfg.ShipConcurrency, "experimental.tsdb.ship-concurrency", 10, "Maximum number of tenants concurrently shipping blocks to the storage.")
115-
f.StringVar(&cfg.Backend, "experimental.tsdb.backend", "s3", `Backend storage to use. Either "s3" or "gcs".`)
124+
f.StringVar(&cfg.Backend, "experimental.tsdb.backend", "s3", fmt.Sprintf("Backend storage to use. Supported backends are: %s.", strings.Join(supportedBackends, ", ")))
116125
f.IntVar(&cfg.MaxTSDBOpeningConcurrencyOnStartup, "experimental.tsdb.max-tsdb-opening-concurrency-on-startup", 10, "limit the number of concurrently opening TSDB's on startup")
117126
f.DurationVar(&cfg.HeadCompactionInterval, "experimental.tsdb.head-compaction-interval", 1*time.Minute, "How frequently does Cortex try to compact TSDB head. Block is only created if data covers smallest block range. Must be greater than 0 and max 5 minutes.")
118127
f.IntVar(&cfg.HeadCompactionConcurrency, "experimental.tsdb.head-compaction-concurrency", 5, "Maximum number of tenants concurrently compacting TSDB head into a new block")
@@ -121,7 +130,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
121130

122131
// Validate the config
123132
func (cfg *Config) Validate() error {
124-
if cfg.Backend != BackendS3 && cfg.Backend != BackendGCS && cfg.Backend != BackendAzure {
133+
if cfg.Backend != BackendS3 && cfg.Backend != BackendGCS && cfg.Backend != BackendAzure && cfg.Backend != BackendFilesystem {
125134
return errUnsupportedBackend
126135
}
127136

0 commit comments

Comments
 (0)