Skip to content

Commit

Permalink
Experimental TSDB: Add support for local filesystem object store
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Welch <[email protected]>
  • Loading branch information
slim-bean committed Mar 10, 2020
1 parent 829109c commit bbf1fb4
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* `-flusher.wal-dir` for the WAL directory to recover from.
* `-flusher.concurrent-flushes` for number of concurrent flushes.
* `-flusher.flush-op-timeout` is duration after which a flush should timeout.
* [ENHANCEMENT] Experimental TSDB: Add support for local filesystem backend #2245

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

Expand Down
5 changes: 5 additions & 0 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,11 @@ azure:
# Number of retries for recoverable errors
# CLI flag: -experimental.tsdb.azure.max-retries
[max_retries: <int> | default = 20]
filesystem:
# Local filesystem storage directory
# CLI flag: -experimental.tsdb.filesystem.directory
[directory: <string> | default = ""]
```

### `compactor_config`
Expand Down
6 changes: 6 additions & 0 deletions docs/operations/blocks-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The supported backends for the blocks storage are:
* [Amazon S3](https://aws.amazon.com/s3)
* [Google Cloud Storage](https://cloud.google.com/storage/)
* [Microsoft Azure Storage](https://azure.microsoft.com/en-us/services/storage/)
* [Local Filesystem](https://thanos.io/storage.md/#filesystem)

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

Expand Down Expand Up @@ -252,6 +253,11 @@ tsdb:
# Number of retries for recoverable errors
# CLI flag: -experimental.tsdb.azure.max-retries
[max_retries: <int> | default = 20]
filesystem:
# Local filesystem storage directory
# CLI flag: -experimental.tsdb.filesystem.directory
[directory: <string> | default = ""]
```
### `compactor_config`

Expand Down
1 change: 1 addition & 0 deletions docs/operations/blocks-storage.template
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The supported backends for the blocks storage are:
* [Amazon S3](https://aws.amazon.com/s3)
* [Google Cloud Storage](https://cloud.google.com/storage/)
* [Microsoft Azure Storage](https://azure.microsoft.com/en-us/services/storage/)
* [Local Filesystem](https://thanos.io/storage.md/#filesystem)

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

Expand Down
12 changes: 12 additions & 0 deletions pkg/storage/tsdb/backend/filesystem/bucket_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package filesystem

import (
"github.com/go-kit/kit/log"
"github.com/thanos-io/thanos/pkg/objstore"
"github.com/thanos-io/thanos/pkg/objstore/filesystem"
)

// NewBucketClient creates a new filesystem bucket client
func NewBucketClient(cfg Config, name string, logger log.Logger) (objstore.Bucket, error) {
return filesystem.NewBucket(cfg.Directory)
}
13 changes: 13 additions & 0 deletions pkg/storage/tsdb/backend/filesystem/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package filesystem

import "flag"

// Config stores the configuration for storing and accessing objects in the local filesystem.
type Config struct {
Directory string `yaml:"directory"`
}

// RegisterFlags registers the flags for TSDB filesystem storage
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.StringVar(&cfg.Directory, "experimental.tsdb.filesystem.directory", "", "Local filesystem storage directory")
}
3 changes: 3 additions & 0 deletions pkg/storage/tsdb/bucket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/thanos-io/thanos/pkg/objstore"

"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/azure"
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/filesystem"
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/gcs"
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/s3"
)
Expand All @@ -20,6 +21,8 @@ func NewBucketClient(ctx context.Context, cfg Config, name string, logger log.Lo
return gcs.NewBucketClient(ctx, cfg.GCS, name, logger)
case BackendAzure:
return azure.NewBucketClient(cfg.Azure, name, logger)
case BackendFilesystem:
return filesystem.NewBucketClient(cfg.Filesystem, name, logger)
default:
return nil, errUnsupportedBackend
}
Expand Down
14 changes: 10 additions & 4 deletions pkg/storage/tsdb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/alecthomas/units"

"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/azure"
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/filesystem"
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/gcs"
"github.com/cortexproject/cortex/pkg/storage/tsdb/backend/s3"
)
Expand All @@ -24,6 +25,9 @@ const (
// BackendAzure is the value for the Azure storage backend
BackendAzure = "azure"

// BackendFilesystem is the value for the filesystem storge backend
BackendFilesystem = "filesystem"

// TenantIDExternalLabel is the external label set when shipping blocks to the storage
TenantIDExternalLabel = "__org_id__"
)
Expand Down Expand Up @@ -54,9 +58,10 @@ type Config struct {
MaxTSDBOpeningConcurrencyOnStartup int `yaml:"max_tsdb_opening_concurrency_on_startup"`

// Backends
S3 s3.Config `yaml:"s3"`
GCS gcs.Config `yaml:"gcs"`
Azure azure.Config `yaml:"azure"`
S3 s3.Config `yaml:"s3"`
GCS gcs.Config `yaml:"gcs"`
Azure azure.Config `yaml:"azure"`
Filesystem filesystem.Config `yaml:"filesystem"`
}

// DurationList is the block ranges for a tsdb
Expand Down Expand Up @@ -102,6 +107,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
cfg.GCS.RegisterFlags(f)
cfg.Azure.RegisterFlags(f)
cfg.BucketStore.RegisterFlags(f)
cfg.Filesystem.RegisterFlags(f)

if len(cfg.BlockRanges) == 0 {
cfg.BlockRanges = []time.Duration{2 * time.Hour} // Default 2h block
Expand All @@ -121,7 +127,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {

// Validate the config
func (cfg *Config) Validate() error {
if cfg.Backend != BackendS3 && cfg.Backend != BackendGCS && cfg.Backend != BackendAzure {
if cfg.Backend != BackendS3 && cfg.Backend != BackendGCS && cfg.Backend != BackendAzure && cfg.Backend != BackendFilesystem {
return errUnsupportedBackend
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bbf1fb4

Please sign in to comment.