Skip to content

Commit 0c9148e

Browse files
committed
feat: Alertmanger support for azure blob storage
This adds configuration for Azure blob storage to back alertmanager's rule storage. It also reorders the object storage implementations to match the order of the ruler's. Signed-off-by: Christian Simon <[email protected]>
1 parent 6614def commit 0c9148e

File tree

3 files changed

+69
-12
lines changed

3 files changed

+69
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* [ENHANCEMENT] Ruler: Add `cortex_prometheus_last_evaluation_samples` to expose the number of samples generated by a rule group per tenant. #3582
2020
* [ENHANCEMENT] Memberlist: add status page (/memberlist) with available details about memberlist-based KV store and memberlist cluster. It's also possible to view KV values in Go struct or JSON format, or download for inspection. #3575
2121
* [ENHANCEMENT] Memberlist: client can now keep a size-bounded buffer with sent and received messages and display them in the admin UI (/memberlist) for troubleshooting. #3581 #3602
22+
* [ENHANCEMENT] Alertmanager: Add support for Azure blob storage. #3634
2223
* [BUGFIX] Allow `-querier.max-query-lookback` use `y|w|d` suffix like deprecated `-store.max-look-back-period`. #3598
2324
* [BUGFIX] Query-Frontend: `cortex_query_seconds_total` now return seconds not nanoseconds. #3589
2425
* [BUGFIX] Memberlist: Entry in the ring should now not appear again after using "Forget" feature (unless it's still heartbeating). #3603

docs/configuration/config-file-reference.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,10 +1522,52 @@ storage:
15221522
# The CLI flags prefix for this block config is: alertmanager
15231523
[configdb: <configstore_config>]
15241524
1525-
local:
1526-
# Path at which alertmanager configurations are stored.
1527-
# CLI flag: -alertmanager.storage.local.path
1528-
[path: <string> | default = ""]
1525+
azure:
1526+
# Azure Cloud environment. Supported values are: AzureGlobal,
1527+
# AzureChinaCloud, AzureGermanCloud, AzureUSGovernment.
1528+
# CLI flag: -alertmanager.storage.azure.environment
1529+
[environment: <string> | default = "AzureGlobal"]
1530+
1531+
# Name of the blob container used to store chunks. This container must be
1532+
# created before running cortex.
1533+
# CLI flag: -alertmanager.storage.azure.container-name
1534+
[container_name: <string> | default = "cortex"]
1535+
1536+
# The Microsoft Azure account name to be used
1537+
# CLI flag: -alertmanager.storage.azure.account-name
1538+
[account_name: <string> | default = ""]
1539+
1540+
# The Microsoft Azure account key to use.
1541+
# CLI flag: -alertmanager.storage.azure.account-key
1542+
[account_key: <string> | default = ""]
1543+
1544+
# Preallocated buffer size for downloads.
1545+
# CLI flag: -alertmanager.storage.azure.download-buffer-size
1546+
[download_buffer_size: <int> | default = 512000]
1547+
1548+
# Preallocated buffer size for uploads.
1549+
# CLI flag: -alertmanager.storage.azure.upload-buffer-size
1550+
[upload_buffer_size: <int> | default = 256000]
1551+
1552+
# Number of buffers used to used to upload a chunk.
1553+
# CLI flag: -alertmanager.storage.azure.download-buffer-count
1554+
[upload_buffer_count: <int> | default = 1]
1555+
1556+
# Timeout for requests made against azure blob storage.
1557+
# CLI flag: -alertmanager.storage.azure.request-timeout
1558+
[request_timeout: <duration> | default = 30s]
1559+
1560+
# Number of retries for a request which times out.
1561+
# CLI flag: -alertmanager.storage.azure.max-retries
1562+
[max_retries: <int> | default = 5]
1563+
1564+
# Minimum time to wait before retrying a request.
1565+
# CLI flag: -alertmanager.storage.azure.min-retry-delay
1566+
[min_retry_delay: <duration> | default = 10ms]
1567+
1568+
# Maximum time to wait before retrying a request.
1569+
# CLI flag: -alertmanager.storage.azure.max-retry-delay
1570+
[max_retry_delay: <duration> | default = 500ms]
15291571
15301572
gcs:
15311573
# Name of GCS bucket. Please refer to
@@ -1602,6 +1644,11 @@ storage:
16021644
# CLI flag: -alertmanager.storage.s3.signature-version
16031645
[signature_version: <string> | default = "v4"]
16041646

1647+
local:
1648+
# Path at which alertmanager configurations are stored.
1649+
# CLI flag: -alertmanager.storage.local.path
1650+
[path: <string> | default = ""]
1651+
16051652
# Enable the experimental alertmanager config api.
16061653
# CLI flag: -experimental.alertmanager.enable-api
16071654
[enable_api: <boolean> | default = false]

pkg/alertmanager/storage.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/cortexproject/cortex/pkg/alertmanager/alerts/objectclient"
1414
"github.com/cortexproject/cortex/pkg/chunk"
1515
"github.com/cortexproject/cortex/pkg/chunk/aws"
16+
"github.com/cortexproject/cortex/pkg/chunk/azure"
1617
"github.com/cortexproject/cortex/pkg/chunk/gcp"
1718
"github.com/cortexproject/cortex/pkg/configs/client"
1819
)
@@ -27,26 +28,32 @@ type AlertStore interface {
2728

2829
// AlertStoreConfig configures the alertmanager backend
2930
type AlertStoreConfig struct {
30-
Type string `yaml:"type"`
31-
ConfigDB client.Config `yaml:"configdb"`
32-
Local local.StoreConfig `yaml:"local"`
31+
Type string `yaml:"type"`
32+
ConfigDB client.Config `yaml:"configdb"`
3333

34-
GCS gcp.GCSConfig `yaml:"gcs"`
35-
S3 aws.S3Config `yaml:"s3"`
34+
// Object Storage Configs
35+
Azure azure.BlobStorageConfig `yaml:"azure"`
36+
GCS gcp.GCSConfig `yaml:"gcs"`
37+
S3 aws.S3Config `yaml:"s3"`
38+
Local local.StoreConfig `yaml:"local"`
3639
}
3740

3841
// RegisterFlags registers flags.
3942
func (cfg *AlertStoreConfig) RegisterFlags(f *flag.FlagSet) {
40-
cfg.Local.RegisterFlags(f)
4143
cfg.ConfigDB.RegisterFlagsWithPrefix("alertmanager.", f)
4244
f.StringVar(&cfg.Type, "alertmanager.storage.type", "configdb", "Type of backend to use to store alertmanager configs. Supported values are: \"configdb\", \"gcs\", \"s3\", \"local\".")
4345

46+
cfg.Azure.RegisterFlagsWithPrefix("alertmanager.storage.", f)
4447
cfg.GCS.RegisterFlagsWithPrefix("alertmanager.storage.", f)
4548
cfg.S3.RegisterFlagsWithPrefix("alertmanager.storage.", f)
49+
cfg.Local.RegisterFlags(f)
4650
}
4751

4852
// Validate config and returns error on failure
4953
func (cfg *AlertStoreConfig) Validate() error {
54+
if err := cfg.Azure.Validate(); err != nil {
55+
return errors.Wrap(err, "invalid Azure Storage config")
56+
}
5057
if err := cfg.S3.Validate(); err != nil {
5158
return errors.Wrap(err, "invalid S3 Storage config")
5259
}
@@ -62,12 +69,14 @@ func NewAlertStore(cfg AlertStoreConfig) (AlertStore, error) {
6269
return nil, err
6370
}
6471
return configdb.NewStore(c), nil
65-
case "local":
66-
return local.NewStore(cfg.Local)
72+
case "azure":
73+
return newObjAlertStore(azure.NewBlobStorage(&cfg.Azure))
6774
case "gcs":
6875
return newObjAlertStore(gcp.NewGCSObjectClient(context.Background(), cfg.GCS))
6976
case "s3":
7077
return newObjAlertStore(aws.NewS3ObjectClient(cfg.S3))
78+
case "local":
79+
return local.NewStore(cfg.Local)
7180
default:
7281
return nil, fmt.Errorf("unrecognized alertmanager storage backend %v, choose one of: azure, configdb, gcs, local, s3", cfg.Type)
7382
}

0 commit comments

Comments
 (0)