-
Notifications
You must be signed in to change notification settings - Fork 816
20190115 ruler better flags #1987
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
6 commits
Select commit
Hold shift + click to select a range
d582f0c
update ruler to use custom ring config similar to the distributor
jtlisi 2bc7f98
add ruler sharding guide and update changelog
jtlisi 5e61d29
mark instance config options hidden in ruler ring
jtlisi 9762120
update changelog
jtlisi bf3a2a4
rename RulerRing to Ring
jtlisi 93fbe0e
make docs
jtlisi 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: "Config for horizontally scaling the Ruler" | ||
linkTitle: "Config for horizontally scaling the Ruler" | ||
weight: 4 | ||
slug: ruler-sharding | ||
--- | ||
|
||
## Context | ||
|
||
One option to scale the ruler is by scaling it horizontally. However, with multiple ruler instances running they will need to coordinate to determine which instance will evaluate which rule. Similar to the ingesters, the rulers establish a hash ring to divide up the responsibilities of evaluating rules. | ||
|
||
## Config | ||
|
||
In order to enable sharding in the ruler the following flag needs to be set: | ||
|
||
``` | ||
-ruler.enable-sharding=true | ||
``` | ||
|
||
In addition the ruler requires it's own ring to be configured, for instance: | ||
|
||
``` | ||
-ruler.ring.consul.hostname=consul.dev.svc.cluster.local:8500 | ||
``` | ||
|
||
The only configuration that is required is to enable sharding and configure a key value store. From there the rulers will shard and handle the division of rules automatically. |
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,92 @@ | ||
package ruler | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"time" | ||
|
||
"github.com/cortexproject/cortex/pkg/ring" | ||
"github.com/cortexproject/cortex/pkg/ring/kv" | ||
"github.com/cortexproject/cortex/pkg/util" | ||
"github.com/cortexproject/cortex/pkg/util/flagext" | ||
"github.com/go-kit/kit/log/level" | ||
) | ||
|
||
// RingConfig masks the ring lifecycler config which contains | ||
// many options not really required by the rulers ring. This config | ||
// is used to strip down the config to the minimum, and avoid confusion | ||
// to the user. | ||
type RingConfig struct { | ||
KVStore kv.Config `yaml:"kvstore,omitempty"` | ||
HeartbeatPeriod time.Duration `yaml:"heartbeat_period,omitempty"` | ||
HeartbeatTimeout time.Duration `yaml:"heartbeat_timeout,omitempty"` | ||
|
||
// Instance details | ||
InstanceID string `yaml:"instance_id" doc:"hidden"` | ||
InstanceInterfaceNames []string `yaml:"instance_interface_names" doc:"hidden"` | ||
InstancePort int `yaml:"instance_port" doc:"hidden"` | ||
InstanceAddr string `yaml:"instance_addr" doc:"hidden"` | ||
NumTokens int `yaml:"num_tokens"` | ||
|
||
// Injected internally | ||
ListenPort int `yaml:"-"` | ||
|
||
// Used for testing | ||
SkipUnregister bool `yaml:"-"` | ||
} | ||
|
||
// RegisterFlags adds the flags required to config this to the given FlagSet | ||
func (cfg *RingConfig) RegisterFlags(f *flag.FlagSet) { | ||
hostname, err := os.Hostname() | ||
if err != nil { | ||
level.Error(util.Logger).Log("msg", "failed to get hostname", "err", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Ring flags | ||
cfg.KVStore.RegisterFlagsWithPrefix("ruler.ring.", "rulers/", f) | ||
pracucci marked this conversation as resolved.
Show resolved
Hide resolved
|
||
f.DurationVar(&cfg.HeartbeatPeriod, "ruler.ring.heartbeat-period", 5*time.Second, "Period at which to heartbeat to the ring.") | ||
f.DurationVar(&cfg.HeartbeatTimeout, "ruler.ring.heartbeat-timeout", time.Minute, "The heartbeat timeout after which rulers are considered unhealthy within the ring.") | ||
|
||
// Instance flags | ||
cfg.InstanceInterfaceNames = []string{"eth0", "en0"} | ||
f.Var((*flagext.Strings)(&cfg.InstanceInterfaceNames), "ruler.ring.instance-interface", "Name of network interface to read address from.") | ||
f.StringVar(&cfg.InstanceAddr, "ruler.ring.instance-addr", "", "IP address to advertise in the ring.") | ||
f.IntVar(&cfg.InstancePort, "ruler.ring.instance-port", 0, "Port to advertise in the ring (defaults to server.grpc-listen-port).") | ||
f.StringVar(&cfg.InstanceID, "ruler.ring.instance-id", hostname, "Instance ID to register in the ring.") | ||
f.IntVar(&cfg.NumTokens, "ruler.ring.num-tokens", 128, "Number of tokens for each ingester.") | ||
} | ||
|
||
// ToLifecyclerConfig returns a LifecyclerConfig based on the ruler | ||
// ring config. | ||
func (cfg *RingConfig) ToLifecyclerConfig() ring.LifecyclerConfig { | ||
// We have to make sure that the ring.LifecyclerConfig and ring.Config | ||
// defaults are preserved | ||
lc := ring.LifecyclerConfig{} | ||
rc := ring.Config{} | ||
|
||
flagext.DefaultValues(&lc) | ||
flagext.DefaultValues(&rc) | ||
|
||
// Configure ring | ||
rc.KVStore = cfg.KVStore | ||
rc.HeartbeatTimeout = cfg.HeartbeatTimeout | ||
rc.ReplicationFactor = 1 | ||
|
||
// Configure lifecycler | ||
lc.RingConfig = rc | ||
lc.ListenPort = &cfg.ListenPort | ||
lc.Addr = cfg.InstanceAddr | ||
lc.Port = cfg.InstancePort | ||
lc.ID = cfg.InstanceID | ||
lc.InfNames = cfg.InstanceInterfaceNames | ||
lc.SkipUnregister = cfg.SkipUnregister | ||
lc.HeartbeatPeriod = cfg.HeartbeatPeriod | ||
lc.NumTokens = cfg.NumTokens | ||
lc.ObservePeriod = 0 | ||
lc.JoinAfter = 0 | ||
lc.MinReadyDuration = 0 | ||
lc.FinalSleep = 0 | ||
|
||
return lc | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After rebasing and
make doc
you will also get the config file documentation updated. Could be worth adding a link to that doc (each root config block has an anchor, so you could link it to#ruler-config
) mentioning it likeTo see the complete set of config option, please check out...