From 668b73c0d727d5b1ab667135e1c70908709e0128 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw)" <3293172751nss@gmail.com> Date: Fri, 12 Jan 2024 17:26:04 +0800 Subject: [PATCH] feat: set openim lint Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> --- .../CHANGELOG-3.5.0+2.e0bd54f-4-g87f685b17.md | 0 CHANGELOG/CHANGELOG-3.5.0.md | 15 --- scripts/lib/release.sh | 5 +- scripts/make-rules/tools.mk | 2 +- tools/component/component.go | 107 +++++++++++------- 5 files changed, 72 insertions(+), 57 deletions(-) delete mode 100644 CHANGELOG/CHANGELOG-3.5.0+2.e0bd54f-4-g87f685b17.md delete mode 100644 CHANGELOG/CHANGELOG-3.5.0.md diff --git a/CHANGELOG/CHANGELOG-3.5.0+2.e0bd54f-4-g87f685b17.md b/CHANGELOG/CHANGELOG-3.5.0+2.e0bd54f-4-g87f685b17.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/CHANGELOG/CHANGELOG-3.5.0.md b/CHANGELOG/CHANGELOG-3.5.0.md deleted file mode 100644 index 063b1885d..000000000 --- a/CHANGELOG/CHANGELOG-3.5.0.md +++ /dev/null @@ -1,15 +0,0 @@ -# Version logging for OpenIM - - - - - - -## [Unreleased] - - - -## [v3.5.0+5.950e970] - 2024-01-12 - -[Unreleased]: https://github.com/openimsdk/open-im-server/compare/v3.5.0+5.950e970...HEAD -[v3.5.0+5.950e970]: https://github.com/openimsdk/open-im-server/compare/v3.5.0+2.e0bd54f...v3.5.0+5.950e970 diff --git a/scripts/lib/release.sh b/scripts/lib/release.sh index 4d0c26cf9..16f2cd97a 100755 --- a/scripts/lib/release.sh +++ b/scripts/lib/release.sh @@ -129,8 +129,8 @@ function openim::release::upload_tarballs() { ${TOOLS_DIR}/coscli cp "${file}" "cos://${BUCKET}/${COS_RELEASE_DIR}/${OPENIM_GIT_VERSION}/${file##*/}" ${TOOLS_DIR}/coscli cp "${file}" "cos://${BUCKET}/${COS_RELEASE_DIR}/latest/${file##*/}" else - ${TOOLS_DIR}/coscmd upload "${file}" "${COS_RELEASE_DIR}/${OPENIM_GIT_VERSION}/" - ${TOOLS_DIR}/coscmd upload "${file}" "${COS_RELEASE_DIR}/latest/" + coscmd upload "${file}" "${COS_RELEASE_DIR}/${OPENIM_GIT_VERSION}/" + coscmd upload "${file}" "${COS_RELEASE_DIR}/latest/" fi done } @@ -641,7 +641,6 @@ function openim::release::github_release() { --user ${OPENIM_GITHUB_ORG} \ --repo ${OPENIM_GITHUB_REPO} \ --tag ${OPENIM_GIT_VERSION} \ - --label "openim-${OPENIM_GIT_VERSION}" \ --name "${filename}" \ --file "${file}" fi diff --git a/scripts/make-rules/tools.mk b/scripts/make-rules/tools.mk index 7fe7305fb..5f076d6e7 100644 --- a/scripts/make-rules/tools.mk +++ b/scripts/make-rules/tools.mk @@ -146,7 +146,7 @@ install.github-release: # amd64 .PHONY: install.coscli install.coscli: - @wget -q https://ghproxy.com/https://github.com/tencentyun/coscli/releases/download/v0.13.0-beta/coscli-linux -O ${TOOLS_DIR}/coscli + @wget -q https://github.com/tencentyun/coscli/releases/download/v0.19.0-beta/coscli-linux -O ${TOOLS_DIR}/coscli @chmod +x ${TOOLS_DIR}/coscli ## install.coscmd: Install coscmd, used to upload files to cos diff --git a/tools/component/component.go b/tools/component/component.go index 62f2c60ac..9d991861a 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -33,19 +33,22 @@ import ( "github.com/openimsdk/open-im-server/v3/pkg/common/config" - "github.com/minio/minio-go/v7/pkg/credentials" "github.com/minio/minio-go/v7" - "github.com/redis/go-redis/v9" - "gopkg.in/yaml.v3" + "github.com/minio/minio-go/v7/pkg/credentials" + "github.com/redis/go-redis/v9" + "gopkg.in/yaml.v3" ) const ( // defaultCfgPath is the default path of the configuration file. defaultCfgPath = "../../../../../config/config.yaml" minioHealthCheckDuration = 1 - maxRetry = 100 + maxRetry = 10 componentStartErrCode = 6000 configErrCode = 6001 + mongoConnTimeout = 10 * time.Second + + redisConnTimeout = 5 * time.Second // Connection timeout for Redis ) const ( @@ -55,8 +58,7 @@ const ( ) var ( - cfgPath = flag.String("c", defaultCfgPath, "Path to the configuration file") - + cfgPath = flag.String("c", defaultCfgPath, "Path to the configuration file") ErrComponentStart = errs.NewCodeError(componentStartErrCode, "ComponentStartErr") ErrConfig = errs.NewCodeError(configErrCode, "Config file is incorrect") ) @@ -141,22 +143,38 @@ func getEnv(key, fallback string) string { return fallback } -// checkMongo checks the MongoDB connection +// checkMongo checks the MongoDB connection with retries and timeout func checkMongo() (string, error) { - // Use environment variables or fallback to config uri := getEnv("MONGO_URI", buildMongoURI()) + var client *mongo.Client + var err error + + for attempt := 0; attempt <= maxRetry; attempt++ { + ctx, cancel := context.WithTimeout(context.Background(), mongoConnTimeout) + defer cancel() - client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) - str := "ths addr is:" + strings.Join(config.Config.Mongo.Address, ",") + client, err = mongo.Connect(ctx, options.Client().ApplyURI(uri)) + if err == nil { + break + } + if attempt < maxRetry { + fmt.Printf("Failed to connect to MongoDB, retrying: %s\n", err) + time.Sleep(time.Second * time.Duration(attempt+1)) // Exponential backoff + } + } if err != nil { - return "", errs.Wrap(errStr(err, str)) + return "", err // Wrap or handle the error as needed } - defer client.Disconnect(context.TODO()) + defer client.Disconnect(context.Background()) - if err = client.Ping(context.TODO(), nil); err != nil { - return "", errs.Wrap(errStr(err, str)) + ctx, cancel := context.WithTimeout(context.Background(), mongoConnTimeout) + defer cancel() + + if err = client.Ping(ctx, nil); err != nil { + return "", err // Wrap or handle the error as needed } + str := "The addr is: " + strings.Join(config.Config.Mongo.Address, ",") return str, nil } @@ -222,8 +240,8 @@ func checkMinio() (string, error) { defer cancel() if minioClient.IsOffline() { - // str := fmt.Sprintf("Minio server is offline;%s", str) - // return "", ErrComponentStart.Wrap(str) + str := fmt.Sprintf("Minio server is offline;%s", str) + return "", ErrComponentStart.Wrap(str) } // Check for localhost in API URL and Minio SignEndpoint @@ -234,9 +252,8 @@ func checkMinio() (string, error) { return str, nil } -// checkRedis checks the Redis connection +// checkRedis checks the Redis connection with retries and timeout func checkRedis() (string, error) { - // Prioritize environment variables address := getEnv("REDIS_ADDRESS", strings.Join(config.Config.Redis.Address, ",")) username := getEnv("REDIS_USERNAME", config.Config.Redis.Username) password := getEnv("REDIS_PASSWORD", config.Config.Redis.Password) @@ -245,30 +262,44 @@ func checkRedis() (string, error) { redisAddresses := strings.Split(address, ",") var redisClient redis.UniversalClient - if len(redisAddresses) > 1 { - // Use cluster client for multiple addresses - redisClient = redis.NewClusterClient(&redis.ClusterOptions{ - Addrs: redisAddresses, - Username: username, - Password: password, - }) - } else { - // Use regular client for single address - redisClient = redis.NewClient(&redis.Options{ - Addr: redisAddresses[0], - Username: username, - Password: password, - }) - } - defer redisClient.Close() + var err error + + for attempt := 0; attempt <= maxRetry; attempt++ { + if len(redisAddresses) > 1 { + // Use cluster client for multiple addresses + redisClient = redis.NewClusterClient(&redis.ClusterOptions{ + Addrs: redisAddresses, + Username: username, + Password: password, + }) + } else { + // Use regular client for single address + redisClient = redis.NewClient(&redis.Options{ + Addr: redisAddresses[0], + Username: username, + Password: password, + }) + } + + ctx, cancel := context.WithTimeout(context.Background(), redisConnTimeout) + defer cancel() - // Ping Redis to check connectivity - _, err := redisClient.Ping(context.Background()).Result() - str := "the addr is:" + strings.Join(redisAddresses, ",") + // Ping Redis to check connectivity + _, err = redisClient.Ping(ctx).Result() + if err == nil { + break + } + if attempt < maxRetry { + fmt.Printf("Failed to connect to Redis, retrying: %s\n", err) + time.Sleep(time.Second * time.Duration(attempt+1)) // Exponential backoff + } + } if err != nil { - return "", errs.Wrap(errStr(err, str)) + return "", err // Wrap or handle the error as needed } + defer redisClient.Close() + str := "The addr is: " + strings.Join(redisAddresses, ",") return str, nil }