-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
store: azure: allow passing an endpoint parameter for specific regions #980
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package azure | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/improbable-eng/thanos/pkg/testutil" | ||
) | ||
|
||
func TestConfig_validate(t *testing.T) { | ||
type fields struct { | ||
StorageAccountName string | ||
StorageAccountKey string | ||
ContainerName string | ||
Endpoint string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
wantErr bool | ||
wantEndpoint string | ||
}{ | ||
{ | ||
name: "valid global configuration", | ||
fields: fields{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "bar", | ||
ContainerName: "roo", | ||
}, | ||
wantErr: false, | ||
wantEndpoint: azureDefaultEndpoint, | ||
}, | ||
{ | ||
name: "valid custom endpoint", | ||
fields: fields{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "bar", | ||
ContainerName: "roo", | ||
Endpoint: "blob.core.chinacloudapi.cn", | ||
}, | ||
wantErr: false, | ||
wantEndpoint: "blob.core.chinacloudapi.cn", | ||
}, | ||
{ | ||
name: "no account key but account name", | ||
fields: fields{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "", | ||
ContainerName: "roo", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "no account name but account key", | ||
fields: fields{ | ||
StorageAccountName: "", | ||
StorageAccountKey: "bar", | ||
ContainerName: "roo", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "no container name", | ||
fields: fields{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "bar", | ||
ContainerName: "", | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
conf := &Config{ | ||
StorageAccountName: tt.fields.StorageAccountName, | ||
StorageAccountKey: tt.fields.StorageAccountKey, | ||
ContainerName: tt.fields.ContainerName, | ||
Endpoint: tt.fields.Endpoint, | ||
} | ||
err := conf.validate() | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("Config.validate() error = %v, wantErr %v", err, tt.wantErr) | ||
} else { | ||
testutil.Equals(t, tt.wantEndpoint, conf.Endpoint) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package azure | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/improbable-eng/thanos/pkg/testutil" | ||
) | ||
|
||
func Test_getContainerURL(t *testing.T) { | ||
type args struct { | ||
conf Config | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "default", | ||
args: args{ | ||
conf: Config{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "Zm9vCg==", | ||
ContainerName: "roo", | ||
Endpoint: azureDefaultEndpoint, | ||
}, | ||
}, | ||
want: "https://foo.blob.core.windows.net/roo", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "azure china", | ||
args: args{ | ||
conf: Config{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "Zm9vCg==", | ||
ContainerName: "roo", | ||
Endpoint: "blob.core.chinacloudapi.cn", | ||
}, | ||
}, | ||
want: "https://foo.blob.core.chinacloudapi.cn/roo", | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctx := context.Background() | ||
got, err := getContainerURL(ctx, tt.args.conf) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("getContainerURL() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
testutil.Equals(t, tt.want, got.String()) | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add https://github.com/Azure/azure-storage-blob-go/blob/HEAD/azblob/zc_pipeline.go#L13
Timeout options from context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be another PR backed by an issue ? Not sure what values we should put in there. You already have defaults here: https://github.com/Azure/azure-storage-blob-go/blob/HEAD/azblob/zc_policy_retry.go#L70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really as you removed context args everywhere.
ctx.Deadline() gives you time.Time & ok flag
You could just put that into you could put that into time.Now()- deadline into
TryTimeout
and IMO this would be good enough,There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@povilasv Done ! Thanks for the feedback 😄 I learned something.