Skip to content
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

oss-perf: modify default protocol for ossfs URL #972

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions pkg/oss/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis

regionID, _ := utils.GetRegionID()
if regionID == "" {
log.Warnf("Failed to get region id from both env and metadata, use original URL: %s", opt.URL)
} else if strings.Contains(opt.URL, regionID) && !strings.Contains(opt.URL, "internal") && !utils.IsPrivateCloud() {
originUrl := opt.URL
opt.URL = strings.ReplaceAll(originUrl, regionID, regionID+"-internal")
log.Warnf("NodePublishVolume:: failed to get region id from both env and metadata, use original URL: %s", opt.URL)
} else if url, done := modifiedURL(opt.URL, regionID); done {
log.Warnf("NodePublishVolume:: modified URL from %s to %s", opt.URL, url)
opt.URL = url
}

if opt.UseSharedPath {
Expand Down
15 changes: 15 additions & 0 deletions pkg/oss/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,18 @@ func doMount(mounter mountutils.Interface, target string, opts Options, mountOpt
logger.Info("mounted successfully")
return nil
}

func modifiedURL(originURL, regionID string) (URL string, modified bool) {
AlbeeSo marked this conversation as resolved.
Show resolved Hide resolved
URL = originURL
if strings.Contains(originURL, regionID) && !strings.Contains(originURL, "internal") && !utils.IsPrivateCloud() {
URL = strings.ReplaceAll(originURL, regionID, regionID+"-internal")
modified = true
}
if strings.HasPrefix(URL, "http://") || strings.HasPrefix(URL, "https://") {
return
}
if strings.HasSuffix(URL, "-internal.aliyuncs.com") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think at least URL like oss-cn-beijing-internal.aliyuncs.com/ is vaild. Paths other than '/' should be considered too. scheme and hostname parts of URL are case insensitive, and should be considered.

I think we may parse the URL with net/url package.

Copy link
Member Author

@AlbeeSo AlbeeSo Feb 20, 2024

Choose a reason for hiding this comment

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

https://help.aliyun.com/zh/oss/user-guide/regions-and-endpoints?spm=a2c4g.11186623.0.0.1e2030f0DijQDq#section-oao-7ao-11f
Endpoint not matches "(http://,https://)oss-{{region}}-{{pub/internal/null}}-aliyuncs.com" is invalid to access OSS by ossfs. Use the raw URL or the modified one will both cause an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get it. The provided link shows endpoint, which is only the hostname part of URL. URL is a term defined by rfc3986. Case insensitivity of scheme should be supported:

Although schemes are case-
insensitive, the canonical form is lowercase and documents that
specify schemes must do so with lowercase letters. An implementation
should accept uppercase letters as equivalent to lowercase in scheme
names (e.g., allow "HTTP" as well as "http") for the sake of
robustness but should only produce lowercase scheme names for
consistency.

DNS name should also be case insensitive (see rfc4343).

As for the path component. I've verified that oss-cn-beijing-internal.aliyuncs.com/ this URL works currently. We may also want to support this too.

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact, value of -ourl= for s3fs/ossfs is little bit different from a real URL. It's for the Endpoint part of Host, which is equal to BucketName.Endpoint. So 'URL' here can only be endpoint or the endpoint with protocol. I fixed case like oss-cn-beijing-internal.aliyuncs.com/ .
https://help.aliyun.com/zh/oss/developer-reference/common-http-headers?spm=a2c4g.11186623.0.0.3b2b3864sI0iwV#section-eq1-b2y-wdb

return "http://" + URL, true
}
return "https://" + URL, true
}