Skip to content

Commit

Permalink
curvefs/client: make user agent configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Ziy1-Tan <ajb459684460@gmail.com>
  • Loading branch information
Ziy1-Tan authored and Cyber-SiKu committed Jul 24, 2023
1 parent c30eff0 commit 0346d82
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion conf/s3.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ s3.region=us-east-1
# http = 0, https = 1
s3.http_scheme=0
s3.verify_SSL=false
s3.user_agent_conf=S3 Browser
s3.user_agent=S3 Browser
s3.maxConnections=32
s3.connectTimeout=60000
s3.requestTimeout=10000
Expand Down
1 change: 1 addition & 0 deletions curvefs/conf/client.conf
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ s3.readCacheThreads=5
# http = 0, https = 1
s3.http_scheme=0
s3.verify_SSL=False
s3.user_agent=S3 Browser
s3.region=us-east-1
s3.maxConnections=500
s3.connectTimeout=60000
Expand Down
1 change: 1 addition & 0 deletions curvefs/conf/mds.conf
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ mds.fsmanager.client.timeoutSec=20
# http = 0, https = 1
s3.http_scheme=0
s3.verify_SSL=False
s3.user_agent=S3 Browser
s3.region=us-east-1
s3.maxConnections=32
s3.connectTimeout=60000
Expand Down
1 change: 1 addition & 0 deletions curvefs/conf/metaserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ s3.enableDeleteObjects=False
# http = 0, https = 1
s3.http_scheme=0
s3.verify_SSL=False
s3.user_agent=S3 Browser
s3.region=us-east-1
s3.maxConnections=32
s3.connectTimeout=60000
Expand Down
18 changes: 14 additions & 4 deletions curvefs/test/client/client_s3_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ class ClientS3Test : public testing::Test {
Aws::SDKOptions awsOptions_;
};

TEST_F(ClientS3Test, init_s3Adapter_userAgent) {
std::string userAgent = "S3 Browser";
curve::common::S3AdapterOption option;
option.userAgent = userAgent;

curve::common::S3Adapter s3Adapter;
s3Adapter.Init(option);
ASSERT_STREQ(userAgent.c_str(), s3Adapter.GetConfig()->userAgent.c_str());
}

TEST_F(ClientS3Test, upload) {
const std::string obj("test");
uint64_t len = 1024;
Expand All @@ -69,7 +79,7 @@ TEST_F(ClientS3Test, upload) {
.WillOnce(Return(-1));
ASSERT_EQ(0, client_->Upload(obj, buf, len));
ASSERT_EQ(-1, client_->Upload(obj, buf, len));
delete buf;
delete[] buf;
}

TEST_F(ClientS3Test, download) {
Expand All @@ -90,7 +100,7 @@ TEST_F(ClientS3Test, download) {
ASSERT_EQ(0, client_->Download(obj, buf, offset, len));
ASSERT_EQ(-1, client_->Download(obj, buf, offset, len));
ASSERT_EQ(-2, client_->Download(obj, buf, offset, len));
delete buf;
delete[] buf;
}

TEST_F(ClientS3Test, uploadync) {
Expand All @@ -106,7 +116,7 @@ TEST_F(ClientS3Test, uploadync) {
EXPECT_CALL(*s3Client_, PutObjectAsync(_))
.WillOnce(Return());
client_->UploadAsync(context);
delete buf;
delete[] buf;
}

TEST_F(ClientS3Test, downloadAsync) {
Expand All @@ -124,7 +134,7 @@ TEST_F(ClientS3Test, downloadAsync) {
EXPECT_CALL(*s3Client_, GetObjectAsync(_))
.WillOnce(Return());
client_->DownloadAsync(context);
delete buf;
delete[] buf;
}


Expand Down
2 changes: 2 additions & 0 deletions curvefs/test/client/test_fuse_s3_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class TestFuseS3Client : public ::testing::Test {
InitOptionBasic(&fuseClientOption_);
InitFSInfo(client_);
fuseClientOption_.s3Opt.s3AdaptrOpt.asyncThreadNum = 1;
fuseClientOption_.s3Opt.s3AdaptrOpt.userAgent = "S3 Browser";
fuseClientOption_.dummyServerStartPort = 5000;
fuseClientOption_.fileSystemOption.maxNameLength = 20u;
fuseClientOption_.listDentryThreads = 2;
Expand Down Expand Up @@ -170,6 +171,7 @@ class TestFuseS3Client : public ::testing::Test {
opt->s3Opt.s3ClientAdaptorOpt.readCacheThreads = 2;
opt->s3Opt.s3ClientAdaptorOpt.writeCacheMaxByte = 838860800;
opt->s3Opt.s3AdaptrOpt.asyncThreadNum = 1;
opt->s3Opt.s3AdaptrOpt.userAgent = "S3 Browser";
opt->dummyServerStartPort = 5000;
opt->fileSystemOption.maxNameLength = 20u;
opt->listDentryThreads = 2;
Expand Down
1 change: 1 addition & 0 deletions curvefs/test/metaserver/s3compact/s3compact_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ TEST_F(S3CompactTest, test_S3AdapterManager) {
opt.bucketName = "";
opt.scheme = 0;
opt.verifySsl = false;
opt.userAgent = "S3 Browser";
opt.maxConnections = 32;
opt.connectTimeout = 60000;
opt.requestTimeout = 10000;
Expand Down
4 changes: 2 additions & 2 deletions src/common/s3_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void InitS3AdaptorOptionExceptS3InfoOption(Configuration* conf,
LOG_IF(FATAL, !conf->GetStringValue("s3.logPrefix", &s3Opt->logPrefix));
LOG_IF(FATAL, !conf->GetIntValue("s3.http_scheme", &s3Opt->scheme));
LOG_IF(FATAL, !conf->GetBoolValue("s3.verify_SSL", &s3Opt->verifySsl));
LOG_IF(FATAL, !conf->GetStringValue("s3.user_agent", &s3Opt->userAgent));
LOG_IF(FATAL, !conf->GetIntValue("s3.maxConnections",
&s3Opt->maxConnections));
LOG_IF(FATAL, !conf->GetIntValue("s3.connectTimeout",
Expand Down Expand Up @@ -149,8 +150,7 @@ void S3Adapter::Init(const S3AdapterOption &option) {
clientCfg_ = Aws::New<Aws::Client::ClientConfiguration>(AWS_ALLOCATE_TAG);
clientCfg_->scheme = Aws::Http::Scheme(option.scheme);
clientCfg_->verifySSL = option.verifySsl;
//clientCfg_->userAgent = conf_.GetStringValue("s3.user_agent_conf").c_str(); //NOLINT
clientCfg_->userAgent = "S3 Browser";
clientCfg_->userAgent = option.userAgent.c_str();
clientCfg_->region = option.region.c_str();
clientCfg_->maxConnections = option.maxConnections;
clientCfg_->connectTimeoutMs = option.connectTimeout;
Expand Down
3 changes: 3 additions & 0 deletions src/common/s3_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct S3AdapterOption {
std::string logPrefix;
int scheme;
bool verifySsl;
std::string userAgent;
int maxConnections;
int connectTimeout;
int requestTimeout;
Expand Down Expand Up @@ -314,6 +315,8 @@ class S3Adapter {
void SetBucketName(const Aws::String &name) { bucketName_ = name; }
Aws::String GetBucketName() { return bucketName_; }

Aws::Client::ClientConfiguration *GetConfig() { return clientCfg_; }

private:
class AsyncRequestInflightBytesThrottle {
public:
Expand Down

0 comments on commit 0346d82

Please sign in to comment.