-
Notifications
You must be signed in to change notification settings - Fork 781
/
storage.go
43 lines (34 loc) · 1018 Bytes
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package ruler
import (
"flag"
"fmt"
"github.com/cortexproject/cortex/pkg/configs/client"
"github.com/cortexproject/cortex/pkg/ruler/rules"
)
// RuleStoreConfig conigures a rule store
type RuleStoreConfig struct {
Type string `yaml:"type"`
ConfigDB client.Config
mock *mockRuleStore
}
// RegisterFlags registers flags.
func (cfg *RuleStoreConfig) RegisterFlags(f *flag.FlagSet) {
cfg.ConfigDB.RegisterFlagsWithPrefix("ruler.", f)
f.StringVar(&cfg.Type, "ruler.storage.type", "configdb", "Method to use for backend rule storage (configdb)")
}
// NewRuleStorage returns a new rule storage backend poller and store
func NewRuleStorage(cfg RuleStoreConfig) (rules.RuleStore, error) {
if cfg.mock != nil {
return cfg.mock, nil
}
switch cfg.Type {
case "configdb":
c, err := client.New(cfg.ConfigDB)
if err != nil {
return nil, err
}
return rules.NewConfigRuleStore(c), nil
default:
return nil, fmt.Errorf("Unrecognized rule storage mode %v, choose one of: configdb", cfg.Type)
}
}