-
Notifications
You must be signed in to change notification settings - Fork 816
Flusher target to flush WAL #2075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
750d935
Flusher target to flush WAL
1e25d5d
Merge remote-tracking branch 'upstream/master' into flusher-target
9ccc629
Use ingester.Flush inside flusher
df38a40
Merge remote-tracking branch 'upstream/master' into flusher-target
a20527d
Adapt services model for flusher
574c43b
Fix review comments
b92df09
Merge remote-tracking branch 'upstream/master' into flusher-target
02fddf5
Ignore util.ErrStopCortex in cortex Run() return error
3922604
Fix review comments
a5182b7
Merge remote-tracking branch 'upstream/master' into flusher-target
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package flusher | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"time" | ||
|
||
"github.com/go-kit/kit/log/level" | ||
"github.com/pkg/errors" | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"github.com/cortexproject/cortex/pkg/ingester" | ||
"github.com/cortexproject/cortex/pkg/ingester/client" | ||
"github.com/cortexproject/cortex/pkg/util" | ||
"github.com/cortexproject/cortex/pkg/util/services" | ||
) | ||
|
||
// Config for an Ingester. | ||
type Config struct { | ||
WALDir string `yaml:"wal_dir,omitempty"` | ||
ConcurrentFlushes int `yaml:"concurrent_flushes,omitempty"` | ||
FlushOpTimeout time.Duration `yaml:"flush_op_timeout,omitempty"` | ||
} | ||
|
||
// RegisterFlags adds the flags required to config this to the given FlagSet | ||
func (cfg *Config) RegisterFlags(f *flag.FlagSet) { | ||
f.StringVar(&cfg.WALDir, "flusher.wal-dir", "wal", "Directory to read WAL from.") | ||
f.IntVar(&cfg.ConcurrentFlushes, "flusher.concurrent-flushes", 50, "Number of concurrent goroutines flushing to dynamodb.") | ||
f.DurationVar(&cfg.FlushOpTimeout, "flusher.flush-op-timeout", 2*time.Minute, "Timeout for individual flush operations.") | ||
} | ||
|
||
// Flusher is designed to be used as a job to flush the chunks from the WAL on disk. | ||
type Flusher struct { | ||
services.Service | ||
|
||
cfg Config | ||
ingesterConfig ingester.Config | ||
clientConfig client.Config | ||
chunkStore ingester.ChunkStore | ||
registerer prometheus.Registerer | ||
} | ||
|
||
const ( | ||
postFlushSleepTime = 1 * time.Minute | ||
) | ||
|
||
// New constructs a new Flusher and flushes the data from the WAL. | ||
// The returned Flusher has no other operations. | ||
func New( | ||
cfg Config, | ||
ingesterConfig ingester.Config, | ||
clientConfig client.Config, | ||
chunkStore ingester.ChunkStore, | ||
registerer prometheus.Registerer, | ||
) (*Flusher, error) { | ||
|
||
ingesterConfig.WALConfig.Dir = cfg.WALDir | ||
ingesterConfig.ConcurrentFlushes = cfg.ConcurrentFlushes | ||
ingesterConfig.FlushOpTimeout = cfg.FlushOpTimeout | ||
|
||
f := &Flusher{ | ||
cfg: cfg, | ||
ingesterConfig: ingesterConfig, | ||
clientConfig: clientConfig, | ||
chunkStore: chunkStore, | ||
registerer: registerer, | ||
} | ||
f.Service = services.NewBasicService(nil, f.running, nil) | ||
return f, nil | ||
} | ||
|
||
func (f *Flusher) running(ctx context.Context) error { | ||
ing, err := ingester.NewForFlusher(f.ingesterConfig, f.clientConfig, f.chunkStore, f.registerer) | ||
if err != nil { | ||
return errors.Wrap(err, "create ingester") | ||
} | ||
|
||
if err := services.StartAndAwaitRunning(ctx, ing); err != nil { | ||
return errors.Wrap(err, "start and await running ingester") | ||
} | ||
|
||
ing.Flush() | ||
|
||
// Sleeping to give a chance to Prometheus | ||
// to collect the metrics. | ||
level.Info(util.Logger).Log("msg", "sleeping to give chance for collection of metrics", "duration", postFlushSleepTime.String()) | ||
time.Sleep(postFlushSleepTime) | ||
|
||
if err := services.StopAndAwaitTerminated(ctx, ing); err != nil { | ||
return errors.Wrap(err, "stop and await terminated ingester") | ||
} | ||
return util.ErrStopCortex | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package util | ||
|
||
import "errors" | ||
|
||
// ErrStopCortex is the error returned by a service as a hint to stop the Cortex server entirely. | ||
var ErrStopCortex = errors.New("stop cortex") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.