Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* `cortex_ingester_received_files`
* `cortex_ingester_received_bytes_total`
* `cortex_ingester_sent_bytes_total`
* [ENHANCEMENT] Add support for azure storage in China, German and US Government environments. #2988
* [ENHANCEMENT] Query-tee: added a small tolerance to floating point sample values comparison. #2994
* [BUGFIX] Query-frontend: Fixed rounding for incoming query timestamps, to be 100% Prometheus compatible. #2990

Expand Down
10 changes: 10 additions & 0 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,11 @@ storage:
[configdb: <configstore_config>]

azure:
# Azure Cloud environment. Supported values are: AzureGlobal,
# AzureChinaCloud, AzureGermanCloud, AzureUSGovernment.
# CLI flag: -ruler.storage.azure.environment
[environment: <string> | default = "AzureGlobal"]

# Name of the blob container used to store chunks. This container must be
# created before running cortex.
# CLI flag: -ruler.storage.azure.container-name
Expand Down Expand Up @@ -1716,6 +1721,11 @@ aws:
[insecure_skip_verify: <boolean> | default = false]

azure:
# Azure Cloud environment. Supported values are: AzureGlobal, AzureChinaCloud,
# AzureGermanCloud, AzureUSGovernment.
# CLI flag: -azure.environment
[environment: <string> | default = "AzureGlobal"]

# Name of the blob container used to store chunks. This container must be
# created before running cortex.
# CLI flag: -azure.container-name
Expand Down
53 changes: 49 additions & 4 deletions pkg/chunk/azure/blob_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,39 @@ import (
"github.com/cortexproject/cortex/pkg/util/flagext"
)

const blobURLFmt = "https://%s.blob.core.windows.net/%s/%s"
const containerURLFmt = "https://%s.blob.core.windows.net/%s"
const (
// Environment
azureGlobal = "AzureGlobal"
azureChinaCloud = "AzureChinaCloud"
azureGermanCloud = "AzureGermanCloud"
azureUSGovernment = "AzureUSGovernment"
)

var (
supportedEnvironments = []string{azureGlobal, azureChinaCloud, azureGermanCloud, azureUSGovernment}
endpoints = map[string]struct{ blobURLFmt, containerURLFmt string }{
azureGlobal: {
"https://%s.blob.core.windows.net/%s/%s",
"https://%s.blob.core.windows.net/%s",
},
azureChinaCloud: {
"https://%s.blob.core.chinacloudapi.cn/%s/%s",
"https://%s.blob.core.chinacloudapi.cn/%s",
},
azureGermanCloud: {
"https://%s.blob.core.cloudapi.de/%s/%s",
"https://%s.blob.core.cloudapi.de/%s",
},
azureUSGovernment: {
"https://%s.blob.core.usgovcloudapi.net/%s/%s",
"https://%s.blob.core.usgovcloudapi.net/%s",
},
}
)

// BlobStorageConfig defines the configurable flags that can be defined when using azure blob storage.
type BlobStorageConfig struct {
Environment string `yaml:"environment"`
ContainerName string `yaml:"container_name"`
AccountName string `yaml:"account_name"`
AccountKey flagext.Secret `yaml:"account_key"`
Expand All @@ -41,6 +69,7 @@ func (c *BlobStorageConfig) RegisterFlags(f *flag.FlagSet) {

// RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet
func (c *BlobStorageConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.StringVar(&c.Environment, prefix+"azure.environment", azureGlobal, fmt.Sprintf("Azure Cloud environment. Supported values are: %s.", strings.Join(supportedEnvironments, ", ")))
f.StringVar(&c.ContainerName, prefix+"azure.container-name", "cortex", "Name of the blob container used to store chunks. This container must be created before running cortex.")
f.StringVar(&c.AccountName, prefix+"azure.account-name", "", "The Microsoft Azure account name to be used")
f.Var(&c.AccountKey, prefix+"azure.account-key", "The Microsoft Azure account key to use.")
Expand Down Expand Up @@ -123,7 +152,7 @@ func (b *BlobStorage) getBlobURL(blobID string) (azblob.BlockBlobURL, error) {
blobID = strings.Replace(blobID, ":", "-", -1)

//generate url for new chunk blob
u, err := url.Parse(fmt.Sprintf(blobURLFmt, b.cfg.AccountName, b.cfg.ContainerName, blobID))
u, err := url.Parse(fmt.Sprintf(b.selectBlobURLFmt(), b.cfg.AccountName, b.cfg.ContainerName, blobID))
if err != nil {
return azblob.BlockBlobURL{}, err
}
Expand All @@ -137,7 +166,7 @@ func (b *BlobStorage) getBlobURL(blobID string) (azblob.BlockBlobURL, error) {
}

func (b *BlobStorage) buildContainerURL() (azblob.ContainerURL, error) {
u, err := url.Parse(fmt.Sprintf(containerURLFmt, b.cfg.AccountName, b.cfg.ContainerName))
u, err := url.Parse(fmt.Sprintf(b.selectContainerURLFmt(), b.cfg.AccountName, b.cfg.ContainerName))
if err != nil {
return azblob.ContainerURL{}, err
}
Expand Down Expand Up @@ -214,3 +243,19 @@ func (b *BlobStorage) DeleteObject(ctx context.Context, blobID string) error {
func (b *BlobStorage) PathSeparator() string {
return b.delimiter
}

// Validate the config.
func (c *BlobStorageConfig) Validate() error {
if !util.StringsContain(supportedEnvironments, c.Environment) {
return fmt.Errorf("unsupported Azure blob storage environment: %s, please select one of: %s ", c.Environment, strings.Join(supportedEnvironments, ", "))
}
return nil
}

func (b *BlobStorage) selectBlobURLFmt() string {
return endpoints[b.cfg.Environment].blobURLFmt
}

func (b *BlobStorage) selectContainerURLFmt() string {
return endpoints[b.cfg.Environment].containerURLFmt
}
3 changes: 3 additions & 0 deletions pkg/chunk/storage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (cfg *Config) Validate() error {
if err := cfg.IndexQueriesCacheConfig.Validate(); err != nil {
return errors.Wrap(err, "invalid Index Queries Cache config")
}
if err := cfg.AzureStorageConfig.Validate(); err != nil {
return errors.Wrap(err, "invalid Azure Storage config")
}
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/ruler/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (cfg *RuleStoreConfig) Validate() error {
if err := cfg.Swift.Validate(); err != nil {
return errors.Wrap(err, "invalid Swift Storage config")
}
if err := cfg.Azure.Validate(); err != nil {
return errors.Wrap(err, "invalid Azure Storage config")
}
return nil
}

Expand Down