github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/alertmanager/alertstore/config.go (about) 1 package alertstore 2 3 import ( 4 "flag" 5 6 "github.com/pkg/errors" 7 8 "github.com/cortexproject/cortex/pkg/alertmanager/alertstore/configdb" 9 "github.com/cortexproject/cortex/pkg/alertmanager/alertstore/local" 10 "github.com/cortexproject/cortex/pkg/chunk/aws" 11 "github.com/cortexproject/cortex/pkg/chunk/azure" 12 "github.com/cortexproject/cortex/pkg/chunk/gcp" 13 "github.com/cortexproject/cortex/pkg/configs/client" 14 "github.com/cortexproject/cortex/pkg/storage/bucket" 15 ) 16 17 // LegacyConfig configures the alertmanager storage backend using the legacy storage clients. 18 // TODO remove this legacy config in Cortex 1.11. 19 type LegacyConfig struct { 20 Type string `yaml:"type"` 21 ConfigDB client.Config `yaml:"configdb"` 22 23 // Object Storage Configs 24 Azure azure.BlobStorageConfig `yaml:"azure"` 25 GCS gcp.GCSConfig `yaml:"gcs"` 26 S3 aws.S3Config `yaml:"s3"` 27 Local local.StoreConfig `yaml:"local"` 28 } 29 30 // RegisterFlags registers flags. 31 func (cfg *LegacyConfig) RegisterFlags(f *flag.FlagSet) { 32 cfg.ConfigDB.RegisterFlagsWithPrefix("alertmanager.", f) 33 f.StringVar(&cfg.Type, "alertmanager.storage.type", configdb.Name, "Type of backend to use to store alertmanager configs. Supported values are: \"configdb\", \"gcs\", \"s3\", \"local\".") 34 35 cfg.Azure.RegisterFlagsWithPrefix("alertmanager.storage.", f) 36 cfg.GCS.RegisterFlagsWithPrefix("alertmanager.storage.", f) 37 cfg.S3.RegisterFlagsWithPrefix("alertmanager.storage.", f) 38 cfg.Local.RegisterFlagsWithPrefix("alertmanager.storage.", f) 39 } 40 41 // Validate config and returns error on failure 42 func (cfg *LegacyConfig) Validate() error { 43 if err := cfg.Azure.Validate(); err != nil { 44 return errors.Wrap(err, "invalid Azure Storage config") 45 } 46 if err := cfg.S3.Validate(); err != nil { 47 return errors.Wrap(err, "invalid S3 Storage config") 48 } 49 return nil 50 } 51 52 // IsDefaults returns true if the storage options have not been set. 53 func (cfg *LegacyConfig) IsDefaults() bool { 54 return cfg.Type == configdb.Name && cfg.ConfigDB.ConfigsAPIURL.URL == nil 55 } 56 57 // Config configures a the alertmanager storage backend. 58 type Config struct { 59 bucket.Config `yaml:",inline"` 60 ConfigDB client.Config `yaml:"configdb"` 61 Local local.StoreConfig `yaml:"local"` 62 } 63 64 // RegisterFlags registers the backend storage config. 65 func (cfg *Config) RegisterFlags(f *flag.FlagSet) { 66 prefix := "alertmanager-storage." 67 68 cfg.ExtraBackends = []string{configdb.Name, local.Name} 69 cfg.ConfigDB.RegisterFlagsWithPrefix(prefix, f) 70 cfg.Local.RegisterFlagsWithPrefix(prefix, f) 71 cfg.RegisterFlagsWithPrefix(prefix, f) 72 } 73 74 // IsFullStateSupported returns if the given configuration supports access to FullState objects. 75 func (cfg *Config) IsFullStateSupported() bool { 76 for _, backend := range bucket.SupportedBackends { 77 if cfg.Backend == backend { 78 return true 79 } 80 } 81 return false 82 }