Skip to content

Conversation

zbbkeepgoing
Copy link
Contributor

@zbbkeepgoing zbbkeepgoing commented Aug 6, 2020

Signed-off-by: Binbin Zou [email protected]

What this PR does:
support azure storage of AzureChinaCloud,AzureGermanCloud,GerUSGovernment

Which issue(s) this PR fixes:
NONE

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Test Images:
721596709428_ pic
731596712929_ pic
741596715446_ pic

Signed-off-by: Binbin Zou <[email protected]>
@zbbkeepgoing zbbkeepgoing force-pushed the feature/azure-storage-others-cloud branch from 7350dd6 to 6c2ea12 Compare August 6, 2020 13:02
@zbbkeepgoing
Copy link
Contributor Author

Add support for other Azure Clouds On #1319

@zbbkeepgoing
Copy link
Contributor Author

@khaines Hi haines, please review if you are free.

Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zbbkeepgoing for working on this! ❤️

I left few comments. Most are minor things, but please be aware that CircleCI for this PR is failing to run: could you try to login to https://circleci.com/ with your GitHub account and follow the cortexproject there before submitting your next commit, please?

I'm marking this PR as "request changes" mainly to signal CI hasn't run.

// BlobStorageConfig defines the configurable flags that can be defined when using azure blob storage.
type BlobStorageConfig struct {
CloudEnvironment string `yaml:"cloud_environment"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we simply call it environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -41,6 +55,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.CloudEnvironment, prefix+"azure.cloud_environment", "AzureGlobal", "Environment of Azure Cloud. This value can be AzureGlobal, AzureChinaCloud, AzureGermanCloud, AzureUSGovernment.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a convention to use _ in YAML and - in CLI flags. Here it should be cloud-environment, even if I would suggest to just call it environment.

Also if you have a constant for AzureGlobal and the other environments and you create a global slice variable with all supported environments, then here you could dinamically generate it using strings.Join(supportedEnvironments, ",").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 21 to 22
const blobURLFmt = "https://%s.blob.core.windows.net/%s/%s"
const containerURLFmt = "https://%s.blob.core.windows.net/%s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you prefix these by global, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


func (b *BlobStorage) selectBlobUrlFmt() string {
switch b.cfg.CloudEnvironment {
case "AzureGlobal":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you create constants for these AzureGlobal, AzureChinaCloud, etc please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

CHANGELOG.md Outdated
@@ -46,6 +46,7 @@
- `-experimental.tsdb.flush-blocks-on-shutdown` changed to `-experimental.blocks-storage.tsdb.flush-blocks-on-shutdown`
* [CHANGE] Flags `-bigtable.grpc-use-gzip-compression`, `-ingester.client.grpc-use-gzip-compression`, `-querier.frontend-client.grpc-use-gzip-compression` are now deprecated. #2940
* [CHANGE] Limit errors reported by ingester during query-time now return HTTP status code 422. #2941
* [FEATURE] Add support for azure storage of AzureChinaCloud,AzureGermanCloud,AzureUSGovernment. #2988
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the CHANGELOG entry to the top, under "master / unrelease". This is the section for 1.3.0 which has already been cut. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"github.com/cortexproject/cortex/pkg/util/flagext"
)

func TestGetObject(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to run these tests locally, but looks failing with the error illegal base64 data at input byte 8. Also I'm not sure how they're supposed to work, considering the backend storage is not mocked 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it is difficult for me to mock azure storage, so I deleted the test file 😂

@pull-request-size pull-request-size bot added size/M and removed size/L labels Aug 8, 2020
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zbbkeepgoing for addressing my feedback. I left a last round of feedback and then we should be good to go. Thanks!


// Validate the config.
func (c *BlobStorageConfig) Validate() error {
if c.Environment != azureGlobal && c.Environment != azureChinaCloud && c.Environment != azureGermanCloud && c.Environment == azureUSGovernment {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use supportedEnvironments here:

if !util.StringsContain(supportedEnvironments, c.Environment) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Validate the config.
func (c *BlobStorageConfig) Validate() error {
if c.Environment != azureGlobal && c.Environment != azureChinaCloud && c.Environment != azureGermanCloud && c.Environment == azureUSGovernment {
return fmt.Errorf("unsupported environment: %s, please select one of: %s ", c.Environment, strings.Join(supportedEnvironments, ","))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("unsupported environment: %s, please select one of: %s ", c.Environment, strings.Join(supportedEnvironments, ","))
return fmt.Errorf("unsupported Azure blob storage environment: %s, please select one of: %s ", c.Environment, strings.Join(supportedEnvironments, ", "))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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("Environment of Azure Cloud. This value can be %s.", strings.Join(supportedEnvironments, ",")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f.StringVar(&c.Environment, prefix+"azure.environment", azureGlobal, fmt.Sprintf("Environment of Azure Cloud. This value can be %s.", strings.Join(supportedEnvironments, ",")))
f.StringVar(&c.Environment, prefix+"azure.environment", azureGlobal, fmt.Sprintf("Azure Cloud environment. Supported values are: %s.", strings.Join(supportedEnvironments, ", ")))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 36 to 39
)

// Environment
const (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge the two const please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@zbbkeepgoing zbbkeepgoing force-pushed the feature/azure-storage-others-cloud branch from f4fd5b9 to 492095a Compare August 10, 2020 09:37
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (modulo fixing the linter issue), thanks! @pstibrany could you take a second look, please?

Signed-off-by: Binbin Zou <[email protected]>
@zbbkeepgoing zbbkeepgoing force-pushed the feature/azure-storage-others-cloud branch from 492095a to c5d97d6 Compare August 10, 2020 10:16
Signed-off-by: Binbin Zou <[email protected]>
Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! I've left two non-blocking comments.

CHANGELOG.md Outdated
@@ -1,7 +1,7 @@
# Changelog

## master / unreleased

* [ENHANCEMENT] Add support for azure storage of AzureChinaCloud,AzureGermanCloud,AzureUSGovernment. #2988
Copy link
Contributor

@pstibrany pstibrany Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* [ENHANCEMENT] Add support for azure storage of AzureChinaCloud,AzureGermanCloud,AzureUSGovernment. #2988
* [ENHANCEMENT] Add support for azure storage in China, German and US Government environments. #2988

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 21 to 35
//Blob service endpoint of AzureGlobal
globalBlobURLFmt = "https://%s.blob.core.windows.net/%s/%s"
globalContainerURLFmt = "https://%s.blob.core.windows.net/%s"

// Blob service endpoint of AzureChinaCloud
chinaBlobURLFmt = "https://%s.blob.core.chinacloudapi.cn/%s/%s"
chinaContainerURLFmt = "https://%s.blob.core.chinacloudapi.cn/%s"

// Blob service endpoint of AzureGermanCloud
germanyBlobURLFmt = "https://%s.blob.core.cloudapi.de/%s/%s"
germanyContainerURLFmt = "https://%s.blob.core.cloudapi.de/%s"

// Blob service endpoint of AzureUSGovernment
govBlobURLFmt = "https://%s.blob.core.usgovcloudapi.net/%s/%s"
govContainerURLFmt = "https://%s.blob.core.usgovcloudapi.net/%s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to verify these endpoints, but cannot find authoritative summary documentation. Do you have any relevant link?

Would it make sense to use something like:

var endpoints = map[string]struct{blobURL, containerURL string} {
    azureGlobal: {
        blobURL: "https://%s.blob.core.windows.net/%s/%s",
        containerURL: "https://%s.blob.core.windows.net/%s",
    },

    azureChinaCloud: {
        blobURL: "https://%s.blob.core.chinacloudapi.cn/%s/%s",
        containerURL: "https://%s.blob.core.chinacloudapi.cn/%s",
    },

    // ...
}

and then use the map instead of selectBlobURLFmt and selectContainerURLFmt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to verify these endpoints, but cannot find authoritative summary documentation. Do you have any relevant link?

Would it make sense to use something like:

var endpoints = map[string]struct{blobURL, containerURL string} {
    azureGlobal: {
        blobURL: "https://%s.blob.core.windows.net/%s/%s",
        containerURL: "https://%s.blob.core.windows.net/%s",
    },

    azureChinaCloud: {
        blobURL: "https://%s.blob.core.chinacloudapi.cn/%s/%s",
        containerURL: "https://%s.blob.core.chinacloudapi.cn/%s",
    },

    // ...
}

and then use the map instead of selectBlobURLFmt and selectContainerURLFmt?

done

Signed-off-by: Binbin <[email protected]>
Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@pstibrany pstibrany merged commit 43cef5a into cortexproject:master Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants