Skip to content

Commit d6aa67a

Browse files
committed
Use ingester prefix for LifecyclerConfig
Many ingester flags were recently broken. This fixes the flags that were broken, but if anyone is running the new HA Ruler they will need to update their consul flags. Signed-off-by: Chris Marchbanks <[email protected]>
1 parent 88541de commit d6aa67a

File tree

6 files changed

+70
-22
lines changed

6 files changed

+70
-22
lines changed

pkg/ingester/ingester.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type Config struct {
100100

101101
// RegisterFlags adds the flags required to config this to the given FlagSet
102102
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
103-
cfg.LifecyclerConfig.RegisterFlags(f)
103+
cfg.LifecyclerConfig.RegisterFlagsWithPrefix("ingester.", f)
104104

105105
f.IntVar(&cfg.MaxTransferRetries, "ingester.max-transfer-retries", 10, "Number of times to try and transfer chunks before falling back to flushing.")
106106
f.DurationVar(&cfg.FlushCheckPeriod, "ingester.flush-period", 1*time.Minute, "Period with which to attempt to flush chunks.")

pkg/ring/consul_client.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
cleanhttp "github.com/hashicorp/go-cleanhttp"
1414

1515
"github.com/cortexproject/cortex/pkg/util"
16+
"github.com/cortexproject/cortex/pkg/util/flagext"
1617
"github.com/weaveworks/common/httpgrpc"
1718
"github.com/weaveworks/common/instrument"
1819
)
@@ -30,14 +31,14 @@ type ConsulConfig struct {
3031
ConsistentReads bool
3132
}
3233

33-
// RegisterFlags adds the flags required to config this to the given FlagSet
34+
// RegisterFlags adds the flags required to config this to the given FlagSet.
3435
// If prefix is not an empty string it should end with a period.
3536
func (cfg *ConsulConfig) RegisterFlags(f *flag.FlagSet, prefix string) {
36-
f.StringVar(&cfg.Host, prefix+"consul.hostname", "localhost:8500", "Hostname and port of Consul.")
37-
f.StringVar(&cfg.Prefix, prefix+"consul.prefix", "collectors/", "Prefix for keys in Consul. Should end with a /.")
38-
f.StringVar(&cfg.ACLToken, prefix+"consul.acltoken", "", "ACL Token used to interact with Consul.")
39-
f.DurationVar(&cfg.HTTPClientTimeout, prefix+"consul.client-timeout", 2*longPollDuration, "HTTP timeout when talking to consul")
40-
f.BoolVar(&cfg.ConsistentReads, prefix+"consul.consistent-reads", true, "Enable consistent reads to consul.")
37+
flagext.StringVarOnce(f, &cfg.Host, prefix+"consul.hostname", "localhost:8500", "Hostname and port of Consul.")
38+
flagext.StringVarOnce(f, &cfg.Prefix, prefix+"consul.prefix", "collectors/", "Prefix for keys in Consul. Should end with a /.")
39+
flagext.StringVarOnce(f, &cfg.ACLToken, prefix+"consul.acltoken", "", "ACL Token used to interact with Consul.")
40+
flagext.DurationVarOnce(f, &cfg.HTTPClientTimeout, prefix+"consul.client-timeout", 2*longPollDuration, "HTTP timeout when talking to consul")
41+
flagext.BoolVarOnce(f, &cfg.ConsistentReads, prefix+"consul.consistent-reads", true, "Enable consistent reads to consul.")
4142
}
4243

4344
type kv interface {

pkg/ring/kvstore.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"sync"
88

9+
"github.com/cortexproject/cortex/pkg/util/flagext"
910
"github.com/golang/protobuf/proto"
1011
"github.com/golang/snappy"
1112
)
@@ -47,7 +48,7 @@ func (cfg *KVConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
4748
if prefix == "" {
4849
prefix = "ring."
4950
}
50-
f.StringVar(&cfg.Store, prefix+"store", "consul", "Backend storage to use for the ring (consul, inmemory).")
51+
flagext.StringVarOnce(f, &cfg.Store, prefix+"store", "consul", "Backend storage to use for the ring (consul, inmemory).")
5152
}
5253

5354
// CASCallback is the type of the callback to CAS. If err is nil, out must be non-nil.

pkg/ring/lifecycler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var (
4141
type LifecyclerConfig struct {
4242
RingConfig Config `yaml:"ring,omitempty"`
4343

44-
// Config for the ingester lifecycle control
44+
// Config for the ingester lifecycle control.
4545
ListenPort *int
4646
NumTokens int `yaml:"num_tokens,omitempty"`
4747
HeartbeatPeriod time.Duration `yaml:"heartbeat_period,omitempty"`
@@ -52,21 +52,21 @@ type LifecyclerConfig struct {
5252
InfNames []string `yaml:"interface_names"`
5353
FinalSleep time.Duration `yaml:"final_sleep"`
5454

55-
// For testing, you can override the address and ID of this ingester
55+
// For testing, you can override the address and ID of this ingester.
5656
Addr string `yaml:"address"`
5757
Port int
5858
ID string
5959
SkipUnregister bool
6060
}
6161

62-
// RegisterFlags adds the flags required to config this to the given FlagSet
62+
// RegisterFlags adds the flags required to config this to the given FlagSet.
6363
func (cfg *LifecyclerConfig) RegisterFlags(f *flag.FlagSet) {
6464
cfg.RegisterFlagsWithPrefix("", f)
6565
}
6666

67-
// RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet
67+
// RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet.
6868
func (cfg *LifecyclerConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
69-
cfg.RingConfig.RegisterFlagsWithPrefix(prefix, f)
69+
cfg.RingConfig.RegisterFlags(f)
7070

7171
f.IntVar(&cfg.NumTokens, prefix+"num-tokens", 128, "Number of tokens for each ingester.")
7272
f.DurationVar(&cfg.HeartbeatPeriod, prefix+"heartbeat-period", 5*time.Second, "Period at which to heartbeat to consul.")

pkg/ring/ring.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/prometheus/client_golang/prometheus"
1717

1818
"github.com/cortexproject/cortex/pkg/util"
19+
"github.com/cortexproject/cortex/pkg/util/flagext"
1920
)
2021

2122
const (
@@ -61,17 +62,12 @@ type Config struct {
6162
ReplicationFactor int `yaml:"replication_factor,omitempty"`
6263
}
6364

64-
// RegisterFlags adds the flags required to config this to the given FlagSet with a specified prefix
65+
// RegisterFlags adds the flags required to config this to the given FlagSet.
6566
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
66-
cfg.RegisterFlagsWithPrefix("", f)
67-
}
68-
69-
// RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet with a specified prefix
70-
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
71-
cfg.KVStore.RegisterFlagsWithPrefix(prefix, f)
67+
cfg.KVStore.RegisterFlagsWithPrefix("", f)
7268

73-
f.DurationVar(&cfg.HeartbeatTimeout, prefix+"ring.heartbeat-timeout", time.Minute, "The heartbeat timeout after which ingesters are skipped for reads/writes.")
74-
f.IntVar(&cfg.ReplicationFactor, prefix+"distributor.replication-factor", 3, "The number of ingesters to write to and read from.")
69+
flagext.DurationVarOnce(f, &cfg.HeartbeatTimeout, "ring.heartbeat-timeout", time.Minute, "The heartbeat timeout after which ingesters are skipped for reads/writes.")
70+
flagext.IntVarOnce(f, &cfg.ReplicationFactor, "distributor.replication-factor", 3, "The number of ingesters to write to and read from.")
7571
}
7672

7773
// Ring holds the information about the members of the consistent hash ring.

pkg/util/flagext/once.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package flagext
2+
3+
import (
4+
"flag"
5+
"time"
6+
)
7+
8+
// IntVarOnce will check to see if a flag has already been registered. If
9+
// so it will set the value to the value already parsed. If not, it will
10+
// register the new flag.
11+
func IntVarOnce(f *flag.FlagSet, p *int, name string, value int, usage string) {
12+
if fl := f.Lookup(name); fl == nil {
13+
f.IntVar(p, name, value, usage)
14+
} else {
15+
*p = fl.Value.(flag.Getter).Get().(int)
16+
}
17+
}
18+
19+
// BoolVarOnce will check to see if a flag has already been registered. If
20+
// so it will set the value to the value already parsed. If not, it will
21+
// register the new flag.
22+
func BoolVarOnce(f *flag.FlagSet, p *bool, name string, value bool, usage string) {
23+
if fl := f.Lookup(name); fl == nil {
24+
f.BoolVar(p, name, value, usage)
25+
} else {
26+
*p = fl.Value.(flag.Getter).Get().(bool)
27+
}
28+
}
29+
30+
// StringVarOnce will check to see if a flag has already been registered. If
31+
// so it will set the value to the value already parsed. If not, it will
32+
// register the new flag.
33+
func StringVarOnce(f *flag.FlagSet, p *string, name string, value string, usage string) {
34+
if fl := f.Lookup(name); fl == nil {
35+
f.StringVar(p, name, value, usage)
36+
} else {
37+
*p = fl.Value.(flag.Getter).Get().(string)
38+
}
39+
}
40+
41+
// DurationVarOnce will check to see if a flag has already been registered. If
42+
// so it will set the value to the value already parsed. If not, it will
43+
// register the new flag.
44+
func DurationVarOnce(f *flag.FlagSet, p *time.Duration, name string, value time.Duration, usage string) {
45+
if fl := f.Lookup(name); fl == nil {
46+
f.DurationVar(p, name, value, usage)
47+
} else {
48+
*p = fl.Value.(flag.Getter).Get().(time.Duration)
49+
}
50+
}

0 commit comments

Comments
 (0)