`.
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-source "${OPENIM_ROOT}/scripts/lib/init.sh"
-
-# This sets up a clean GOPATH and makes sure we are currently in it.
-openim::golang::setup_env
-
-# Run the user-provided command.
-"${@}"
diff --git a/scripts/start-all.sh b/scripts/start-all.sh
deleted file mode 100755
index 6f4a6c574..000000000
--- a/scripts/start-all.sh
+++ /dev/null
@@ -1,109 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#FIXME This script is the startup script for multiple servers.
-#FIXME The full names of the shell scripts that need to be started are placed in the `need_to_start_server_shell` array.
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-source "${OPENIM_ROOT}/scripts/install/common.sh"
-
-# Function to execute the scripts.
-function execute_start_scripts() {
- for script_path in "${OPENIM_SERVER_SCRIPT_START_LIST[@]}"; do
- # Extract the script name without extension for argument generation.
- script_name_with_prefix=$(basename "$script_path" .sh)
-
- # Remove the "openim-" prefix.
- script_name=${script_name_with_prefix#openim-}
-
- # Construct the argument based on the script name.
- arg="openim::${script_name}::start"
-
- # Check if the script file exists and is executable.
- if [[ -x "$script_path" ]]; then
- openim::log::colorless "Starting script: ${script_path##*/}" # Log the script name.
- # Execute the script with the constructed argument.
- result=$("$script_path" "$arg")
- if [[ $? -ne 0 ]]; then
- openim::log::error "Start script: ${script_path##*/} failed"
- openim::log::error "$result"
- return 1
- fi
-
- else
- openim::log::errexit "Script ${script_path##*/} is missing or not executable."
- return 1
- fi
- done
-}
-
-if openim::util::is_running_in_container; then
- exec >> ${DOCKER_LOG_FILE} 2>&1
-fi
-
-openim::golang::check_openim_binaries
-if [[ $? -ne 0 ]]; then
- openim::log::error "OpenIM binaries are not found. Please run 'make build' to build binaries."
- "${OPENIM_ROOT}"/scripts/build-all-service.sh
-fi
-
-"${OPENIM_ROOT}"/scripts/init-config.sh --skip
-
-#openim::log::print_blue "Execute the following script in sequence: ${OPENIM_SERVER_SCRIPTARIES[@]}"
-
-# TODO Prelaunch tools, simple for now, can abstract functions later
-TOOLS_START_SCRIPTS_PATH=${START_SCRIPTS_PATH}/openim-tools.sh
-
-openim::log::status "Start the pre-start tools:"
-
-# if ! ${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start; then
-# openim::log::error "Start the pre-start tools, aborting!"
-# exit 1
-# fi
-
-openim::log::colorless "pre-start has been successfully completed!"
-
-result=$("${OPENIM_ROOT}"/scripts/stop-all.sh)
-if [[ $? -ne 0 ]]; then
- openim::log::error "View the error logs from this startup. ${LOG_FILE} \n"
- openim::log::error "Some programs have not exited; the start process is aborted .\n $result"
- exit 1
-fi
-
-openim::log::status "Start the OpenIM startup scripts: "
-execute_start_scripts
-openim::log::status "OpenIM startup scripts have been successfully completed!"
-
-sleep 2
-
-result=$(. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check)
-if [[ $? -ne 0 ]]; then
- openim::log::error "The OpenIM services may fail to start.\n $result"
- exit 1
-fi
-
-result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]})
-if [[ $? -ne 0 ]]; then
- openim::log::error "The OpenIM services may fail to start.\n $result"
- exit 1
-fi
-
-openim::log::status "Start the post-start tools:"
-# ${TOOLS_START_SCRIPTS_PATH} openim::tools::post-start
-openim::log::status "post-start has been successfully completed!"
-openim::util::find_ports_for_all_services ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}
-openim::util::find_ports_for_all_services ${OPENIM_MSGTRANSFER_BINARY[@]}
-
-openim::log::success "All OpenIM services have been successfully started!"
\ No newline at end of file
diff --git a/scripts/stop-all.sh b/scripts/stop-all.sh
deleted file mode 100755
index b2572f7d5..000000000
--- a/scripts/stop-all.sh
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# This script is stop all openim service
-#
-# Usage: `scripts/stop.sh`.
-# Encapsulated as: `make stop`.
-
-
-
-
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-
-source "${OPENIM_ROOT}/scripts/install/common.sh"
-
-openim::log::status "Begin to stop all openim service"
-
-openim::log::status "Stop all processes in the path ${OPENIM_OUTPUT_HOSTBIN}"
-
-openim::util::stop_services_with_name "${OPENIM_OUTPUT_HOSTBIN}"
-# todo OPENIM_ALL_SERVICE_LIBRARIES
-
-
-
-
-max_retries=15
-attempt=0
-
-while [[ $attempt -lt $max_retries ]]
-do
- result=$(openim::util::check_process_names_for_stop)
-
- if [[ $? -ne 0 ]]; then
- if [[ $attempt -ne 0 ]] ; then
- echo "+++ cat openim log file >>> ${LOG_FILE} " $attempt
- openim::log::error "stop process failed. continue waiting\n" "${result}"
- fi
- sleep 1
- ((attempt++))
- else
- openim::log::success " All openim processes to be stopped"
- exit 0
- fi
-done
-
-openim::log::error "openim processes stopped failed"
-exit 1
diff --git a/scripts/update-generated-docs.sh b/scripts/update-generated-docs.sh
deleted file mode 100755
index 4c1fbfccc..000000000
--- a/scripts/update-generated-docs.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-# This file is not intended to be run automatically. It is meant to be run
-# immediately before exporting docs. We do not want to check these documents in
-# by default.
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-source "${OPENIM_ROOT}/scripts/lib/init.sh"
-
-openim::golang::setup_env
-
-BINS=(
- gendocs
- genopenimdocs
- genman
- genyaml
-)
-make -C "${OPENIM_ROOT}" BINS="${BINS[*]}"
-
-openim::util::ensure-temp-dir
-
-openim::util::gen-docs "${OPENIM_TEMP}"
-
-# remove all of the old docs
-openim::util::remove-gen-docs
-
-# Copy fresh docs into the repo.
-# the shopt is so that we get docs/.generated_docs from the glob.
-shopt -s dotglob
-cp -af "${OPENIM_TEMP}"/* "${OPENIM_ROOT}"
-shopt -u dotglob
diff --git a/scripts/update-yamlfmt.sh b/scripts/update-yamlfmt.sh
deleted file mode 100755
index 8de0cc84c..000000000
--- a/scripts/update-yamlfmt.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-source "${OPENIM_ROOT}/scripts/lib/init.sh"
-
-openim::golang::setup_env
-
-cd "${OPENIM_ROOT}"
-
-find_files() {
- find . -not \( \
- \( \
- -wholename './output' \
- -o -wholename './.git' \
- -o -wholename './_output' \
- -o -wholename './_gopath' \
- -o -wholename './release' \
- -o -wholename './target' \
- -o -wholename '*/vendor/*' \
- \) -prune \
- \) -name 'OWNERS*'
-}
-
-export GO111MODULE=on
-find_files | xargs go run tools/yamlfmt/yamlfmt.go
\ No newline at end of file
diff --git a/scripts/verify-pkg-names.sh b/scripts/verify-pkg-names.sh
deleted file mode 100755
index be1acd015..000000000
--- a/scripts/verify-pkg-names.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-# This script verifies whether codes follow golang convention.
-# Usage: `scripts/verify-pkg-names.sh`.
-
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-source "${OPENIM_ROOT}/scripts/lib/init.sh"
-
-openim::golang::verify_go_version
-
-cd "${OPENIM_ROOT}"
-if git --no-pager grep -E $'^(import |\t)[a-z]+[A-Z_][a-zA-Z]* "[^"]+"$' -- '**/*.go' ':(exclude)vendor/*' ':(exclude)**/*.pb.go'; then
- openim::log::error "Some package aliases break go conventions."
- echo "To fix these errors, do not use capitalized or underlined characters"
- echo "in pkg aliases. Refer to https://blog.golang.org/package-names for more info."
- exit 1
-fi
diff --git a/scripts/verify-shellcheck.sh b/scripts/verify-shellcheck.sh
deleted file mode 100755
index 3e56038dd..000000000
--- a/scripts/verify-shellcheck.sh
+++ /dev/null
@@ -1,188 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-# This script lints each shell script by `shellcheck`.
-# Usage: `scripts/verify-shellcheck.sh`.
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-source "${OPENIM_ROOT}/scripts/lib/init.sh"
-
-# allow overriding docker cli, which should work fine for this script
-DOCKER="${DOCKER:-docker}"
-
-# required version for this script, if not installed on the host we will
-# use the official docker image instead. keep this in sync with SHELLCHECK_IMAGE
-SHELLCHECK_VERSION="0.8.0"
-SHELLCHECK_IMAGE="docker.io/koalaman/shellcheck-alpine:v0.8.0@sha256:f42fde76d2d14a645a848826e54a4d650150e151d9c81057c898da89a82c8a56"
-
-# disabled lints
-disabled=(
- # this lint disallows non-constant source, which we use extensively without
- # any known bugs
- 1090
- # this lint warns when shellcheck cannot find a sourced file
- # this wouldn't be a bad idea to warn on, but it fails on lots of path
- # dependent sourcing, so just disable enforcing it
- 1091
- # this lint prefers command -v to which, they are not the same
- 2230
- # Error SC2155 indicates that you should separate variable declaration and assignment to avoid masking the return value of the command.
- # In Bash scripts, when you declare and assign a local variable at the same time a command is executed, you only get the output of the command, but not the exit status (return value) of the command. #
- 2155
- # ShellCheck issues SC2086 warnings when you refer to a variable in a script but don't put it in double quotes.This can lead to unexpected behavior when scripts encounter Spaces,
- # newlines, and wildcards in file names or other data.
- 2086
- 2206
-
- # TODO: 需要修复,然后开启
- 2034
- 2048
- 2148
- 2059
- 2214
- 2145
- 2128
- 2550
- 2046
- 2181
- 1102
- 2045
- 2068
- 2145
- 2207
- 2231
- 2013
- 2154
- 2120
- 1083
- 2001
- 2012
- 2016
- 2164
- 2223
- 2166
- 2119
- 2162
- 2295
- 2002
- 2004
- 2202
- 2178
- 2064
- 2260
- 2261
- 2043
- 2178
- 2044
- 2153
-)
-# comma separate for passing to shellcheck
-join_by() {
- local IFS="$1";
- shift;
- echo "$*";
-}
-SHELLCHECK_DISABLED="$(join_by , "${disabled[@]}")"
-readonly SHELLCHECK_DISABLED
-
-# ensure we're linting the k8s source tree
-cd "${OPENIM_ROOT}"
-
-# Find all shell scripts excluding:
-# - Anything git-ignored - No need to lint untracked files.
-# - ./_* - No need to lint output directories.
-# - ./.git/* - Ignore anything in the git object store.
-# - ./vendor* - Vendored code should be fixed upstream instead.
-# - ./third_party/*, but re-include ./third_party/forked/* - only code we
-# forked should be linted and fixed.
-all_shell_scripts=()
-while IFS=$'\n' read -r script;
-do git check-ignore -q "$script" || all_shell_scripts+=("$script");
- done < <(find . -name "*.sh" \
- -not \( \
- -path ./_\* -o \
- -path ./.git\* -o \
- -path ./Godeps\* -o \
- -path ./_output\* -o \
- -path ./components\* -o \
- -path ./logs\* -o \
- -path ./vendor\* -o \
- \( -path ./third_party\* -a -not -path ./third_party/forked\* \) \
-\) -print 2>/dev/null)
-
-# detect if the host machine has the required shellcheck version installed
-# if so, we will use that instead.
-HAVE_SHELLCHECK=false
-if which shellcheck &>/dev/null; then
- detected_version="$(shellcheck --version | grep 'version: .*')"
- if [[ "${detected_version}" = "version: ${SHELLCHECK_VERSION}" ]]; then
- HAVE_SHELLCHECK=true
- fi
-fi
-
-# if KUBE_JUNIT_REPORT_DIR is set, disable colorized output.
-# Colorized output causes malformed XML in the JUNIT report.
-SHELLCHECK_COLORIZED_OUTPUT="auto"
-if [[ -n "${KUBE_JUNIT_REPORT_DIR:-}" ]]; then
- SHELLCHECK_COLORIZED_OUTPUT="never"
-fi
-
-# common arguments we'll pass to shellcheck
-SHELLCHECK_OPTIONS=(
- # allow following sourced files that are not specified in the command,
- # we need this because we specify one file at a time in order to trivially
- # detect which files are failing
- "--external-sources"
- # include our disabled lints
- "--exclude=${SHELLCHECK_DISABLED}"
- # set colorized output
- "--color=${SHELLCHECK_COLORIZED_OUTPUT}"
-)
-
-# tell the user which we've selected and lint all scripts
-# The shellcheck errors are printed to stdout by default, hence they need to be redirected
-# to stderr in order to be well parsed for Junit representation by juLog function
-res=0
-if ${HAVE_SHELLCHECK}; then
- openim::log::info "Using host shellcheck ${SHELLCHECK_VERSION} binary."
- shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" >&2 || res=$?
-else
- openim::log::info "Using shellcheck ${SHELLCHECK_VERSION} docker image."
- "${DOCKER}" run \
- --rm -v "${OPENIM_ROOT}:${OPENIM_ROOT}" -w "${OPENIM_ROOT}" \
- "${SHELLCHECK_IMAGE}" \
- shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}" >&2 || res=$?
-fi
-
-# print a message based on the result
-if [ $res -eq 0 ]; then
- echo 'Congratulations! All shell files are passing lint :-)'
-else
- {
- echo
- echo 'Please review the above warnings. You can test via "./scripts/verify-shellcheck.sh"'
- echo 'If the above warnings do not make sense, you can exempt this warning with a comment'
- echo ' (if your reviewer is okay with it).'
- echo 'In general please prefer to fix the error, we have already disabled specific lints'
- echo ' that the project chooses to ignore.'
- echo 'See: https://github.com/koalaman/shellcheck/wiki/Ignore#ignoring-one-specific-instance-in-a-file'
- echo
- } >&2
- exit 1
-fi
-
-# preserve the result
-exit $res
diff --git a/scripts/verify-spelling.sh b/scripts/verify-spelling.sh
deleted file mode 100755
index c718c1ad1..000000000
--- a/scripts/verify-spelling.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# This script checks commonly misspelled English words in all files in the
-# working directory by client9/misspell package.
-# Usage: `scripts/verify-spelling.sh`.
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-export OPENIM_ROOT
-source "${OPENIM_ROOT}/scripts/lib/init.sh"
-
-# Spell checking
-# All the skipping files are defined in scripts/.spelling_failures
-skipping_file="${OPENIM_ROOT}/scripts/.spelling_failures"
-failing_packages=$(sed "s| | -e |g" "${skipping_file}")
-git ls-files | grep -v -e "${failing_packages}" | xargs "$OPENIM_ROOT/_output/tools/misspell" -i "Creater,creater,ect" -error -o stderr
diff --git a/scripts/verify-standardizer.sh b/scripts/verify-standardizer.sh
deleted file mode 100755
index 08a13b9a2..000000000
--- a/scripts/verify-standardizer.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# This script does a fast type check of script srnetes code for all platforms.
-# Usage: `scripts/verify-standardizer.sh`.
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-source "${OPENIM_ROOT}/scripts/lib/init.sh"
-
-openim::golang::verify_go_version
-
-cd "${OPENIM_ROOT}"
-ret=0
-scripts/run-in-gopath.sh \
-make tools.verify.standardizer
-${OPENIM_ROOT}/_output/tools/standardizer || ret=$?
-if [[ $ret -ne 0 ]]; then
- openim::log::error "Failed to check the directory name or file name. Your name may not meet the specification. Please check the configuration file and the directory or file name." >&2
- openim::log::error "Please see https://github.com/kubecub/standardizer for more information." >&2
- exit 1
-fi
diff --git a/scripts/verify-typecheck.sh b/scripts/verify-typecheck.sh
deleted file mode 100755
index f6c14844f..000000000
--- a/scripts/verify-typecheck.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# This script does a fast type check of script srnetes code for all platforms.
-# Usage: `scripts/verify-typecheck.sh`.
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-source "${OPENIM_ROOT}/scripts/lib/init.sh"
-
-openim::golang::verify_go_version
-
-cd "${OPENIM_ROOT}"
-ret=0
-TYPECHECK_SERIAL="${TYPECHECK_SERIAL:-false}"
-scripts/run-in-gopath.sh \
-make tools.verify.typecheck
-${OPENIM_ROOT}/_output/tools/typecheck "$@" "--serial=$TYPECHECK_SERIAL" || ret=$?
-if [[ $ret -ne 0 ]]; then
- openim::log::error "Type Check has failed. This may cause cross platform build failures." >&2
- openim::log::error "Please see https://github.com/kubecub/typecheck for more information." >&2
- exit 1
-fi
diff --git a/scripts/verify-yamlfmt.sh b/scripts/verify-yamlfmt.sh
deleted file mode 100755
index a0aa583a8..000000000
--- a/scripts/verify-yamlfmt.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-# This script checks whether the OWNERS files need to be formatted or not by
-# `yamlfmt`. Run `scripts/update-yamlfmt.sh` to actually format sources.
-#
-# Usage: `scripts/verify-yamlfmt.sh`.
-
-OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
-source "${OPENIM_ROOT}/scripts/lib/init.sh"
-
-openim::util::ensure_clean_working_dir
-# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
-openim::golang::setup_env
-
-_tmpdir="$(openim::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
-git worktree add -f -q "${_tmpdir}" HEAD
-openim::util::trap_add "git worktree remove -f ${_tmpdir}" EXIT
-cd "${_tmpdir}"
-
-# Format YAML files
-scripts/update-yamlfmt.sh
-
-# Test for diffs
-diffs=$(git status --porcelain | wc -l)
-if [[ ${diffs} -gt 0 ]]; then
- echo "YAML files need to be formatted" >&2
- git diff
- echo "Please run 'scripts/update-yamlfmt.sh'" >&2
- exit 1
-fi
\ No newline at end of file
diff --git a/scripts/wait-for-it.sh b/scripts/wait-for-it.sh
deleted file mode 100755
index c05b85678..000000000
--- a/scripts/wait-for-it.sh
+++ /dev/null
@@ -1,191 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-WAITFORIT_cmdname=${0##*/}
-
-echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
-
-usage() {
- cat << USAGE >&2
-Usage:
- $WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args]
- -h HOST | --host=HOST Host or IP under test
- -p PORT | --port=PORT TCP port under test
- Alternatively, you specify the host and port as host:port
- -s | --strict Only execute subcommand if the test succeeds
- -q | --quiet Don't output any status messages
- -t TIMEOUT | --timeout=TIMEOUT
- Timeout in seconds, zero for no timeout
- -- COMMAND ARGS Execute command with args after the test finishes
-USAGE
- exit 1
-}
-
-wait_for() {
- if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
- echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
- else
- echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout"
- fi
- WAITFORIT_start_ts=$(date +%s)
- while :
- do
- if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then
- nc -z $WAITFORIT_HOST $WAITFORIT_PORT
- WAITFORIT_result=$?
- else
- (echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1
- WAITFORIT_result=$?
- fi
- if [[ $WAITFORIT_result -eq 0 ]]; then
- WAITFORIT_end_ts=$(date +%s)
- echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds"
- break
- fi
- sleep 1
- done
- return $WAITFORIT_result
-}
-
-wait_for_wrapper() {
- # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
- if [[ $WAITFORIT_QUIET -eq 1 ]]; then
- timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
- else
- timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT &
- fi
- WAITFORIT_PID=$!
- trap "kill -INT -$WAITFORIT_PID" INT
- wait $WAITFORIT_PID
- WAITFORIT_RESULT=$?
- if [[ $WAITFORIT_RESULT -ne 0 ]]; then
- echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT"
- fi
- return $WAITFORIT_RESULT
-}
-
-# process arguments
-while [[ $# -gt 0 ]]
-do
- case "$1" in
- *:* )
- WAITFORIT_hostport=(${1//:/ })
- WAITFORIT_HOST=${WAITFORIT_hostport[0]}
- WAITFORIT_PORT=${WAITFORIT_hostport[1]}
- shift 1
- ;;
- --child)
- WAITFORIT_CHILD=1
- shift 1
- ;;
- -q | --quiet)
- WAITFORIT_QUIET=1
- shift 1
- ;;
- -s | --strict)
- WAITFORIT_STRICT=1
- shift 1
- ;;
- -h)
- WAITFORIT_HOST="$2"
- if [[ $WAITFORIT_HOST == "" ]]; then break; fi
- shift 2
- ;;
- --host=*)
- WAITFORIT_HOST="${1#*=}"
- shift 1
- ;;
- -p)
- WAITFORIT_PORT="$2"
- if [[ $WAITFORIT_PORT == "" ]]; then break; fi
- shift 2
- ;;
- --port=*)
- WAITFORIT_PORT="${1#*=}"
- shift 1
- ;;
- -t)
- WAITFORIT_TIMEOUT="$2"
- if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi
- shift 2
- ;;
- --timeout=*)
- WAITFORIT_TIMEOUT="${1#*=}"
- shift 1
- ;;
- --)
- shift
- WAITFORIT_CLI=("$@")
- break
- ;;
- --help)
- usage
- ;;
- *)
- echoerr "Unknown argument: $1"
- usage
- ;;
- esac
-done
-
-if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then
- echoerr "Error: you need to provide a host and port to test."
- usage
-fi
-
-WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
-WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
-WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
-WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
-
-# Check to see if timeout is from busybox?
-WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
-WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
-
-WAITFORIT_BUSYTIMEFLAG=""
-if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
- WAITFORIT_ISBUSY=1
- # Check if busybox timeout uses -t flag
- # (recent Alpine versions don't support -t anymore)
- if timeout &>/dev/stdout | grep -q -e '-t '; then
- WAITFORIT_BUSYTIMEFLAG="-t"
- fi
-else
- WAITFORIT_ISBUSY=0
-fi
-
-if [[ $WAITFORIT_CHILD -gt 0 ]]; then
- wait_for
- WAITFORIT_RESULT=$?
- exit $WAITFORIT_RESULT
-else
- if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then
- wait_for_wrapper
- WAITFORIT_RESULT=$?
- else
- wait_for
- WAITFORIT_RESULT=$?
- fi
-fi
-
-if [[ $WAITFORIT_CLI != "" ]]; then
- if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then
- echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess"
- exit $WAITFORIT_RESULT
- fi
- exec "${WAITFORIT_CLI[@]}"
-else
- exit $WAITFORIT_RESULT
-fi
diff --git a/test/common.sh b/test/common.sh
deleted file mode 100644
index e583fe8b3..000000000
--- a/test/common.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
diff --git a/test/wrktest.sh b/test/wrktest.sh
deleted file mode 100755
index 10a41121f..000000000
--- a/test/wrktest.sh
+++ /dev/null
@@ -1,276 +0,0 @@
-#!/usr/bin/env bash
-# Copyright © 2023 OpenIM. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-: << EOF
-The API performance test script automatically executes wrk commands, collects data, analyzes it, and calls gnuplot to plot it
-
-Usage (to test API performance) :
-1. Start the openim-api(port 10002)
-2. Execute the test script: ./wrktest.sh
-
-The script will generate the data file.dat, each column meaning: concurrency QPS average response time success rate
-
-Usage (Compare the results of 2 tests)
-1. The performance test:. / wrktest. Sh openim apiserver - http://127.0.0.1:10002/healthz
-2. Execute the command:./wrktest.sh diff apiserver.dat http.dat
-
-> Note: Make sure you have wrk and gnuplot installed on your system
-
-EOF
-
-openim_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
-wrkdir="${openim_root}/_output/wrk"
-jobname="openim-api"
-duration="300s"
-threads=$((3 * $(grep -c processor /proc/cpuinfo)))
-
-source "${openim_root}/scripts/lib/color.sh"
-
-# Set wrk options
-openim::wrk::setup() {
- #concurrent="200 500 1000 3000 5000 10000 15000 20000 25000 50000 100000 200000 500000 1000000"
- concurrent="200 500 1000 3000 5000 10000 15000 20000 25000 50000"
- cmd="wrk -t${threads} -d${duration} -T30s --latency"
-}
-
-# Print usage
-openim::wrk::usage() {
- cat << EOF
-
-Usage: $0 [OPTION] [diff] URL
-Performance automation test script.
-
- URL HTTP request url, like: http://127.0.0.1:10002/healthz
- diff Compare two performance test results
-
-OPTIONS:
- -h Usage information
- -n Performance test task name, default: apiserver
- -d Directory used to store performance data and gnuplot graphic, default: _output/wrk
-
-Reprot bugs to <3293172751nss@gmail.com>.
-EOF
-}
-
-# Convert plot data to useable data
-function openim::wrk::convert_plot_data() {
- echo "$1" | awk -v datfile="${wrkdir}/${datfile}" ' {
- if ($0 ~ "Running") {
- common_time=$2
- }
-if ($0 ~ "connections") {
- connections=$4
- common_threads=$1
-}
-if ($0 ~ "Latency ") {
- avg_latency=convertLatency($2)
-}
-if ($0 ~ "50%") {
- p50=convertLatency($2)
-}
-if ($0 ~ "75%") {
- p75=convertLatency($2)
-}
-if ($0 ~ "90%") {
- p90=convertLatency($2)
-}
-if ($0 ~ "99%") {
- p99=convertLatency($2)
-}
-if ($0 ~ "Requests/sec") {
- qps=$2
-}
-if ($0 ~ "requests in") {
- allrequest=$1
-}
-if ($0 ~ "Socket errors") {
- err=$4+$6+$8+$10
-}
-}
-END {
-rate=sprintf("%.2f", (allrequest-err)*100/allrequest)
-print connections,qps,avg_latency,rate >> datfile
-}
-
-function convertLatency(s) {
- if (s ~ "us") {
- sub("us", "", s)
- return s/1000
- }
-if (s ~ "ms") {
- sub("ms", "", s)
- return s
-}
-if (s ~ "s") {
- sub("s", "", s)
- return s * 1000
-}
-}'
-}
-
-# Remove existing data file
-function openim::wrk::prepare() {
- rm -f "${wrkdir}"/"${datfile}"
-}
-
-# Plot according to gunplot data file
-function openim::wrk::plot() {
- gnuplot << EOF
-set terminal png enhanced #输出格式为png文件
-set ylabel 'QPS'
-set xlabel 'Concurrent'
-set y2label 'Average Latency (ms)'
-set key top left vertical noreverse spacing 1.2 box
-set tics out nomirror
-set border 3 front
-set style line 1 linecolor rgb '#00ff00' linewidth 2 linetype 3 pointtype 2
-set style line 2 linecolor rgb '#ff0000' linewidth 1 linetype 3 pointtype 2
-set style data linespoints
-
-set grid #显示网格
-set xtics nomirror rotate #by 90#只需要一个x轴
-set mxtics 5
-set mytics 5 #可以增加分刻度
-set ytics nomirror
-set y2tics
-
-set autoscale y
-set autoscale y2
-
-set output "${wrkdir}/${qpsttlb}" #指定数据文件名称
-set title "QPS & TTLB\nRunning: ${duration}\nThreads: ${threads}"
-plot "${wrkdir}/${datfile}" using 2:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE0000" axis x1y1 t "QPS","${wrkdir}/${datfile}" using 3:xticlabels(1) w lp pt 5 ps 1 lc rgbcolor "#0000CD" axis x2y2 t "Avg Latency (ms)"
-
-unset y2tics
-unset y2label
-set ytics nomirror
-set yrange[0:100]
-set output "${wrkdir}/${successrate}" #指定数据文件名称
-set title "Success Rate\nRunning: ${duration}\nThreads: ${threads}"
-plot "${wrkdir}/${datfile}" using 4:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#F62817" t "Success Rate"
-EOF
-}
-
-# Plot diff graphic
-function openim::wrk::plot_diff() {
- gnuplot << EOF
-set terminal png enhanced #输出格式为png文件
-set xlabel 'Concurrent'
-set ylabel 'QPS'
-set y2label 'Average Latency (ms)'
-set key below left vertical noreverse spacing 1.2 box autotitle columnheader
-set tics out nomirror
-set border 3 front
-set style line 1 linecolor rgb '#00ff00' linewidth 2 linetype 3 pointtype 2
-set style line 2 linecolor rgb '#ff0000' linewidth 1 linetype 3 pointtype 2
-set style data linespoints
-
-#set border 3 lt 3 lw 2 #这会让你的坐标图的border更好看
-set grid #显示网格
-set xtics nomirror rotate #by 90#只需要一个x轴
-set mxtics 5
-set mytics 5 #可以增加分刻度
-set ytics nomirror
-set y2tics
-
-#set pointsize 0.4 #点的像素大小
-#set datafile separator '\t' #数据文件的字段用\t分开
-
-set autoscale y
-set autoscale y2
-
-#设置图像的大小 为标准大小的2倍
-#set size 2.3,2
-
-set output "${wrkdir}/${t1}_${t2}.qps.ttlb.diff.png" #指定数据文件名称
-set title "QPS & TTLB\nRunning: ${duration}\nThreads: ${threads}"
-plot "/tmp/plot_diff.dat" using 2:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE0000" axis x1y1 t "${t1} QPS","/tmp/plot_diff.dat" using 5:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE82EE" axis x1y1 t "${t2} QPS","/tmp/plot_diff.dat" using 3:xticlabels(1) w lp pt 5 ps 1 lc rgbcolor "#0000CD" axis x2y2 t "${t1} Avg Latency (ms)", "/tmp/plot_diff.dat" using 6:xticlabels(1) w lp pt 5 ps 1 lc rgbcolor "#6495ED" axis x2y2 t "${t2} Avg Latency (ms)"
-
-unset y2tics
-unset y2label
-set ytics nomirror
-set yrange[0:100]
-set output "${wrkdir}/${t1}_${t2}.successrate.diff.png" #指定数据文件名称
-set title "Success Rate\nRunning: ${duration}\nThreads: ${threads}"
-plot "/tmp/plot_diff.dat" using 4:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE0000" t "${t1} Success Rate","/tmp/plot_diff.dat" using 7:xticlabels(1) w lp pt 7 ps 1 lc rgbcolor "#EE82EE" t "${t2} Success Rate"
-EOF
-}
-
-# Start API performance testing
-openim::wrk::start_performance_test() {
- openim::wrk::prepare
-
- for c in ${concurrent}
- do
- wrkcmd="${cmd} -c ${c} $1"
- echo "Running wrk command: ${wrkcmd}"
- result=$(eval "${wrkcmd}")
- openim::wrk::convert_plot_data "${result}"
- done
-
- echo -e "\nNow plot according to ${COLOR_MAGENTA}${wrkdir}/${datfile}${COLOR_NORMAL}"
- openim::wrk::plot &> /dev/null
- echo -e "QPS graphic file is: ${COLOR_MAGENTA}${wrkdir}/${qpsttlb}${COLOR_NORMAL}
-Success rate graphic file is: ${COLOR_MAGENTA}${wrkdir}/${successrate}${COLOR_NORMAL}"
-}
-
-while getopts "hd:n:" opt;do
- case ${opt} in
- d)
- wrkdir=${OPTARG}
- ;;
- n)
- jobname=${OPTARG}
- ;;
- ?)
- openim::wrk::usage
- exit 0
- ;;
- esac
-done
-
-shift $((OPTIND-1))
-
-mkdir -p "${wrkdir}"
-
-case $1 in
- "diff")
- if [ "$#" -lt 3 ];then
- openim::wrk::usage
- exit 0
- fi
-
- t1=$(basename $2|sed 's/.dat//g') # 对比图中红色线条名称
- t2=$(basename $3|sed 's/.dat//g') # 对比图中粉色线条名称
-
- join $2 $3 > /tmp/plot_diff.dat
- openim::wrk::plot_diff "$(basename "$2")" "$(basename "$3")"
- exit 0
- ;;
- *)
- if [ "$#" -lt 1 ];then
- openim::wrk::usage
- exit 0
- fi
- url="$1"
-
- qpsttlb="${jobname}_qps_ttlb.png"
- successrate="${jobname}_successrate.png"
- datfile="${jobname}.dat"
-
- openim::wrk::setup
- openim::wrk::start_performance_test "${url}"
- ;;
-esac
From 281e3a8d6c6503ef2b26c525a19a9b9a0da56b36 Mon Sep 17 00:00:00 2001
From: xuan <146319162+wxuanF@users.noreply.github.com>
Date: Sun, 28 Apr 2024 12:13:12 +0800
Subject: [PATCH 02/12] Auto close issue test (#2243)
* Update README.md
* Update README.md
* Update README.md
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 045d28f47..7c34664d6 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@
[](https://github.com/openimsdk/open-im-server/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22good+first+issue%22)
[](https://golang.org/)
-
+
Englist ·
中文 ·
@@ -131,7 +131,7 @@ Thank you for contributing to building a powerful instant messaging solution!
## :closed_book: License
-OpenIMSDK is available under the Apache License 2.0. See the [LICENSE file](https://github.com/openimsdk/open-im-server/blob/main/LICENSE) for more information.
+OpenIMSDK is available under the Apache License 2.0. See the [LICENSE file](https://github.com/openimsdk/open-im-server/blob/main/LICENSE) for more information.
From 879cf757436f4c8d160de992e82a4c5b0c62c625 Mon Sep 17 00:00:00 2001
From: skiffer-git <72860476+skiffer-git@users.noreply.github.com>
Date: Sun, 28 Apr 2024 14:35:46 +0800
Subject: [PATCH 03/12] fix bug: If there are uppercase letters in the
directory, 'mage start' encounters an error (#2253)
* fix bug:
If there are uppercase letters in the directory, 'mage start' encounters an error
* update go.mod
---
go.mod | 4 ++--
go.sum | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/go.mod b/go.mod
index 21eca956e..cc0de7614 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
module github.com/openimsdk/open-im-server/v3
-go 1.21
+go 1.21.2
require (
firebase.google.com/go v3.13.0+incompatible
@@ -34,7 +34,7 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/kelindar/bitmap v1.5.2
github.com/likexian/gokit v0.25.13
- github.com/openimsdk/gomake v0.0.9
+ github.com/openimsdk/gomake v0.0.11
github.com/redis/go-redis/v9 v9.4.0
github.com/robfig/cron/v3 v3.0.1
github.com/shirou/gopsutil v3.21.11+incompatible
diff --git a/go.sum b/go.sum
index aa851c74b..7c256c58d 100644
--- a/go.sum
+++ b/go.sum
@@ -279,8 +279,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
-github.com/openimsdk/gomake v0.0.9 h1:ouf25ygN2PMQ68Gfgns/EQRPiLPnp+77SIr68GfE+n4=
-github.com/openimsdk/gomake v0.0.9/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
+github.com/openimsdk/gomake v0.0.11 h1:jJ9286zKFfBeARkmfqMEcUYg9lJ+Cj9lylxP8W9uCFM=
+github.com/openimsdk/gomake v0.0.11/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
github.com/openimsdk/protocol v0.0.65 h1:SPT9qyUsFRTTKSKb/FjpS+xr6sxz/Kbnu+su1bxYagc=
github.com/openimsdk/protocol v0.0.65/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
github.com/openimsdk/tools v0.0.49-alpha.2 h1:8IfV6o2ySU7C54sh/MG7ctEp1h3lSNe03OCUDWSk5Ws=
From a2d6a624548411844d7e1fc7d693f994301d4774 Mon Sep 17 00:00:00 2001
From: xuan <146319162+wxuanF@users.noreply.github.com>
Date: Sun, 28 Apr 2024 14:35:48 +0800
Subject: [PATCH 04/12] Update action (#2256)
* Rename check-coverage.yml to check-coverage.bak
* Rename release.yml to release.bak
* Update .env
* Rename sync.yml to sync.bak
* Rename sync-release.yml to sync-release.bak
---
.env | 4 ++++
.github/workflows/{check-coverage.yml => check-coverage.bak} | 0
.github/workflows/{release.yml => release.bak} | 2 +-
.github/workflows/{sync-release.yml => sync-release.bak} | 2 +-
.github/workflows/{sync.yml => sync.bak} | 2 +-
5 files changed, 7 insertions(+), 3 deletions(-)
rename .github/workflows/{check-coverage.yml => check-coverage.bak} (100%)
rename .github/workflows/{release.yml => release.bak} (97%)
rename .github/workflows/{sync-release.yml => sync-release.bak} (97%)
rename .github/workflows/{sync.yml => sync.bak} (97%)
diff --git a/.env b/.env
index 6c2baa41d..d3ae0426a 100644
--- a/.env
+++ b/.env
@@ -9,5 +9,9 @@ MINIO_IMAGE=minio/minio:RELEASE.2024-01-11T07-46-16Z
OPENIM_WEB_FRONT_IMAGE=openim/openim-web-front:release-v3.5.1
OPENIM_ADMIN_FRONT_IMAGE=openim/openim-admin-front:release-v1.7
+#FRONT_IMAGE: use aliyun images
+#OPENIM_WEB_FRONT_IMAGE=registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-web-front:release-v3.5.1
+#OPENIM_ADMIN_FRONT_IMAGE=registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-admin-front:release-v1.7
+
DATA_DIR=./
diff --git a/.github/workflows/check-coverage.yml b/.github/workflows/check-coverage.bak
similarity index 100%
rename from .github/workflows/check-coverage.yml
rename to .github/workflows/check-coverage.bak
diff --git a/.github/workflows/release.yml b/.github/workflows/release.bak
similarity index 97%
rename from .github/workflows/release.yml
rename to .github/workflows/release.bak
index 9950bdabb..c15cff6a3 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.bak
@@ -78,4 +78,4 @@ jobs:
./_output/dist/*.rpm
./_output/dist/*.apk
key: ${{ github.ref }}
- - run: task goreleaser:test:${{ matrix.format }}
\ No newline at end of file
+ - run: task goreleaser:test:${{ matrix.format }}
diff --git a/.github/workflows/sync-release.yml b/.github/workflows/sync-release.bak
similarity index 97%
rename from .github/workflows/sync-release.yml
rename to .github/workflows/sync-release.bak
index e156e07d8..a85c74fde 100644
--- a/.github/workflows/sync-release.yml
+++ b/.github/workflows/sync-release.bak
@@ -41,4 +41,4 @@ jobs:
automerge
ASSIGNEES: |
kubbot
- continue-on-error: true
\ No newline at end of file
+ continue-on-error: true
diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.bak
similarity index 97%
rename from .github/workflows/sync.yml
rename to .github/workflows/sync.bak
index 77ed2f881..595cbbe2c 100644
--- a/.github/workflows/sync.yml
+++ b/.github/workflows/sync.bak
@@ -37,4 +37,4 @@ jobs:
automerge
ASSIGNEES: |
kubbot
- continue-on-error: true
\ No newline at end of file
+ continue-on-error: true
From 230c0dbb8be41909f9f0e692e6322abb7232b993 Mon Sep 17 00:00:00 2001
From: chao <48119764+withchao@users.noreply.github.com>
Date: Mon, 29 Apr 2024 17:02:46 +0800
Subject: [PATCH 05/12] fix: minio config build (#2263)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
---------
Co-authored-by: withchao
---
pkg/common/config/config.go | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go
index caf31036c..24d04d8cc 100644
--- a/pkg/common/config/config.go
+++ b/pkg/common/config/config.go
@@ -15,14 +15,13 @@
package config
import (
- "fmt"
"github.com/openimsdk/tools/db/mongoutil"
"github.com/openimsdk/tools/db/redisutil"
"github.com/openimsdk/tools/mq/kafka"
"github.com/openimsdk/tools/s3/cos"
"github.com/openimsdk/tools/s3/minio"
"github.com/openimsdk/tools/s3/oss"
- "net"
+ "strings"
"time"
)
@@ -473,25 +472,23 @@ func (k *Kafka) Build() *kafka.Config {
},
}
}
+
func (m *Minio) Build() *minio.Config {
- conf := minio.Config{
+ formatEndpoint := func(address string) string {
+ if strings.HasPrefix(address, "http://") || strings.HasPrefix(address, "https://") {
+ return address
+ }
+ return "http://" + address
+ }
+ return &minio.Config{
Bucket: m.Bucket,
AccessKeyID: m.AccessKeyID,
SecretAccessKey: m.SecretAccessKey,
SessionToken: m.SessionToken,
PublicRead: m.PublicRead,
+ Endpoint: formatEndpoint(m.InternalAddress),
+ SignEndpoint: formatEndpoint(m.ExternalAddress),
}
- if _, _, err := net.SplitHostPort(m.InternalAddress); err == nil {
- conf.Endpoint = fmt.Sprintf("http://%s", m.InternalAddress)
- } else {
- conf.Endpoint = m.InternalAddress
- }
- if _, _, err := net.SplitHostPort(m.ExternalAddress); err == nil {
- conf.SignEndpoint = fmt.Sprintf("http://%s", m.ExternalAddress)
- } else {
- conf.SignEndpoint = m.ExternalAddress
- }
- return &conf
}
func (c *Cos) Build() *cos.Config {
return &cos.Config{
From 691cf740af346ca17ebdc1cfc6a5f41a587e4d8a Mon Sep 17 00:00:00 2001
From: blooming <37789413+Bloomingg@users.noreply.github.com>
Date: Mon, 6 May 2024 16:37:52 +0800
Subject: [PATCH 06/12] fix: avoid frequent scheduled task (#2274)
---
.github/workflows/build-docker-image.yml | 3 +--
.github/workflows/{lock-issue.yml => lock-issue.bak} | 0
.github/workflows/stale.yml | 4 ++--
3 files changed, 3 insertions(+), 4 deletions(-)
rename .github/workflows/{lock-issue.yml => lock-issue.bak} (100%)
diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml
index 1e9711d2c..b4733116e 100644
--- a/.github/workflows/build-docker-image.yml
+++ b/.github/workflows/build-docker-image.yml
@@ -15,8 +15,6 @@
name: Publish Docker image
on:
- schedule:
- - cron: '30 2 * * *'
push:
branches:
- main
@@ -31,6 +29,7 @@ env:
jobs:
build-dockerhub:
+ if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true)
runs-on: ubuntu-latest
steps:
- name: Checkout
diff --git a/.github/workflows/lock-issue.yml b/.github/workflows/lock-issue.bak
similarity index 100%
rename from .github/workflows/lock-issue.yml
rename to .github/workflows/lock-issue.bak
diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml
index da44cb7f3..4445f6dda 100644
--- a/.github/workflows/stale.yml
+++ b/.github/workflows/stale.yml
@@ -21,7 +21,7 @@ name: Mark stale issues and pull requests
on:
schedule:
- - cron: '0 8 * * *'
+ - cron: '0 8 * * 1'
jobs:
stale:
@@ -36,7 +36,7 @@ jobs:
with:
repo-token: ${{ secrets.BOT_GITHUB_TOKEN }}
days-before-stale: 60
- days-before-close: 7
+ days-before-close: 305
stale-issue-message: 'This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.'
stale-pr-message: 'This issue is stale because it has been open 60 days with no activity.'
close-issue-message: 'This issue was closed because it has been stalled for 7 days with no activity.'
From 8d84e2f01f87e2f3e8d9338362ce5a7a4c286c2a Mon Sep 17 00:00:00 2001
From: skiffer-git <72860476+skiffer-git@users.noreply.github.com>
Date: Tue, 7 May 2024 21:05:41 +0800
Subject: [PATCH 07/12] Skip minio check (#2281)
* If MinIO is not being used, then do not perform the MinIO check.
* If MinIO is not being used, then do not perform the MinIO check.
* If MinIO is not being used, then do not perform the MinIO check.
* If MinIO is not being used, then do not perform the MinIO check.
* kill binary before build
* Stop the process before compiling.
* Stop the process before compiling.
---
docker-compose.yml | 3 +++
go.mod | 3 ++-
go.sum | 4 ++--
internal/tools/cron_task.go | 14 +-------------
magefile.go | 12 +-----------
tools/check-component/main.go | 20 ++++++++++++++++----
6 files changed, 25 insertions(+), 31 deletions(-)
diff --git a/docker-compose.yml b/docker-compose.yml
index 4acd00cdd..aeb53a417 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -51,6 +51,7 @@ services:
ports:
- "12181:2181"
environment:
+ #JVMFLAGS: "-Xms32m -Xmx128m"
TZ: "Asia/Shanghai"
ALLOW_ANONYMOUS_LOGIN: "yes"
restart: always
@@ -70,6 +71,7 @@ services:
command: >
bash -c "/opt/bitnami/scripts/kafka/run.sh & /opt/bitnami/kafka/create-topic.sh; wait"
environment:
+ #KAFKA_HEAP_OPTS: "-Xms128m -Xmx256m"
TZ: Asia/Shanghai
KAFKA_CFG_NODE_ID: 0
KAFKA_CFG_PROCESS_ROLES: controller,broker
@@ -119,3 +121,4 @@ services:
- openim
+
diff --git a/go.mod b/go.mod
index cc0de7614..b522065da 100644
--- a/go.mod
+++ b/go.mod
@@ -34,7 +34,7 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/kelindar/bitmap v1.5.2
github.com/likexian/gokit v0.25.13
- github.com/openimsdk/gomake v0.0.11
+ github.com/openimsdk/gomake v0.0.13
github.com/redis/go-redis/v9 v9.4.0
github.com/robfig/cron/v3 v3.0.1
github.com/shirou/gopsutil v3.21.11+incompatible
@@ -44,6 +44,7 @@ require (
golang.org/x/sync v0.6.0
)
+
require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
diff --git a/go.sum b/go.sum
index 7c256c58d..e2ecf7284 100644
--- a/go.sum
+++ b/go.sum
@@ -279,8 +279,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
-github.com/openimsdk/gomake v0.0.11 h1:jJ9286zKFfBeARkmfqMEcUYg9lJ+Cj9lylxP8W9uCFM=
-github.com/openimsdk/gomake v0.0.11/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
+github.com/openimsdk/gomake v0.0.13 h1:xLDe/moqgWpRoptHzI4packAWzs4C16b+sVY+txNJp0=
+github.com/openimsdk/gomake v0.0.13/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
github.com/openimsdk/protocol v0.0.65 h1:SPT9qyUsFRTTKSKb/FjpS+xr6sxz/Kbnu+su1bxYagc=
github.com/openimsdk/protocol v0.0.65/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
github.com/openimsdk/tools v0.0.49-alpha.2 h1:8IfV6o2ySU7C54sh/MG7ctEp1h3lSNe03OCUDWSk5Ws=
diff --git a/internal/tools/cron_task.go b/internal/tools/cron_task.go
index 7161f55fc..20baeffaf 100644
--- a/internal/tools/cron_task.go
+++ b/internal/tools/cron_task.go
@@ -25,8 +25,6 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"os"
- "os/signal"
- "syscall"
"time"
"github.com/openimsdk/tools/errs"
@@ -50,22 +48,12 @@ func Start(ctx context.Context, config *CronTaskConfig) error {
return errs.WrapMsg(err, "failed to register discovery service")
}
client.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()))
- ctx, exitBy := context.WithCancelCause(context.Background())
ctx = mcontext.SetOpUserID(ctx, config.Share.IMAdminUserID[0])
conn, err := client.GetConn(ctx, config.Share.RpcRegisterName.Msg)
if err != nil {
return err
}
cli := msg.NewMsgClient(conn)
- go func() {
- sigs := make(chan os.Signal, 1)
- signal.Notify(sigs, syscall.SIGTERM)
- select {
- case <-ctx.Done():
- case s := <-sigs:
- exitBy(fmt.Errorf("exit signal %s", s))
- }
- }()
crontab := cron.New()
clearFunc := func() {
now := time.Now()
@@ -84,5 +72,5 @@ func Start(ctx context.Context, config *CronTaskConfig) error {
log.ZInfo(ctx, "start cron task", "chatRecordsClearTime", config.CronTask.ChatRecordsClearTime)
crontab.Start()
<-ctx.Done()
- return context.Cause(ctx)
+ return nil
}
diff --git a/magefile.go b/magefile.go
index 98ffa48f3..a8a1c4040 100644
--- a/magefile.go
+++ b/magefile.go
@@ -6,22 +6,12 @@ package main
import (
"github.com/openimsdk/gomake/mageutil"
"os"
- "strings"
)
var Default = Build
func Build() {
- platforms := os.Getenv("PLATFORMS")
- if platforms == "" {
- platforms = mageutil.DetectPlatform()
- }
-
- for _, platform := range strings.Split(platforms, " ") {
- mageutil.CompileForPlatform(platform)
- }
-
- mageutil.PrintGreen("All binaries under cmd and tools were successfully compiled.")
+ mageutil.Build()
}
func Start() {
diff --git a/tools/check-component/main.go b/tools/check-component/main.go
index d3225abb8..7fe64d3c5 100644
--- a/tools/check-component/main.go
+++ b/tools/check-component/main.go
@@ -66,6 +66,7 @@ func initConfig(configDir string) (*config.Mongo, *config.Redis, *config.Kafka,
kafkaConfig = &config.Kafka{}
minioConfig = &config.Minio{}
zookeeperConfig = &config.ZooKeeper{}
+ thirdConfig = &config.Third{}
)
err := config.LoadConfig(filepath.Join(configDir, cmd.MongodbConfigFileName), cmd.ConfigEnvPrefixMap[cmd.MongodbConfigFileName], mongoConfig)
if err != nil {
@@ -82,11 +83,19 @@ func initConfig(configDir string) (*config.Mongo, *config.Redis, *config.Kafka,
return nil, nil, nil, nil, nil, err
}
- err = config.LoadConfig(filepath.Join(configDir, cmd.MinioConfigFileName), cmd.ConfigEnvPrefixMap[cmd.MinioConfigFileName], minioConfig)
+ err = config.LoadConfig(filepath.Join(configDir, cmd.OpenIMRPCThirdCfgFileName), cmd.ConfigEnvPrefixMap[cmd.OpenIMRPCThirdCfgFileName], thirdConfig)
if err != nil {
return nil, nil, nil, nil, nil, err
}
+ if thirdConfig.Object.Enable == "minio" {
+ err = config.LoadConfig(filepath.Join(configDir, cmd.MinioConfigFileName), cmd.ConfigEnvPrefixMap[cmd.MinioConfigFileName], minioConfig)
+ if err != nil {
+ return nil, nil, nil, nil, nil, err
+ }
+ } else {
+ minioConfig = nil
+ }
err = config.LoadConfig(filepath.Join(configDir, cmd.ZookeeperConfigFileName), cmd.ConfigEnvPrefixMap[cmd.ZookeeperConfigFileName], zookeeperConfig)
if err != nil {
return nil, nil, nil, nil, nil, err
@@ -131,14 +140,17 @@ func performChecks(ctx context.Context, mongoConfig *config.Mongo, redisConfig *
"Redis": func() error {
return CheckRedis(ctx, redisConfig)
},
- "MinIO": func() error {
- return CheckMinIO(ctx, minioConfig)
- },
"Kafka": func() error {
return CheckKafka(ctx, kafkaConfig)
},
}
+ if minioConfig != nil {
+ checks["MinIO"] = func() error {
+ return CheckMinIO(ctx, minioConfig)
+ }
+ }
+
for i := 0; i < maxRetry; i++ {
allSuccess := true
for name, check := range checks {
From 5ba5402bee04d73d46a04c3461ae15a711f9abce Mon Sep 17 00:00:00 2001
From: skiffer-git <72860476+skiffer-git@users.noreply.github.com>
Date: Wed, 8 May 2024 16:00:27 +0800
Subject: [PATCH 08/12] update gomake (#2286)
---
Dockerfile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Dockerfile b/Dockerfile
index 746dddf65..3f765805c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -43,7 +43,7 @@ COPY --from=builder $SERVER_DIR/start-config.yml $SERVER_DIR/
COPY --from=builder $SERVER_DIR/go.mod $SERVER_DIR/
COPY --from=builder $SERVER_DIR/go.sum $SERVER_DIR/
-RUN go get github.com/openimsdk/gomake@v0.0.9
+RUN go get github.com/openimsdk/gomake@v0.0.13
# Set the command to run when the container starts
ENTRYPOINT ["sh", "-c", "mage start && tail -f /dev/null"]
From 66426cd98b5784e94340a5c85a950416af24b9a2 Mon Sep 17 00:00:00 2001
From: chao <48119764+withchao@users.noreply.github.com>
Date: Wed, 8 May 2024 19:38:27 +0800
Subject: [PATCH 09/12] fix: search for messag (#2288)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* fix: SearchMessage
---------
Co-authored-by: withchao
---
pkg/common/db/mgo/msg.go | 122 +++++++++++++++++++++++----------------
1 file changed, 72 insertions(+), 50 deletions(-)
diff --git a/pkg/common/db/mgo/msg.go b/pkg/common/db/mgo/msg.go
index 6fe24536b..17e493d33 100644
--- a/pkg/common/db/mgo/msg.go
+++ b/pkg/common/db/mgo/msg.go
@@ -267,58 +267,80 @@ func (m *MsgMgo) MarkSingleChatMsgsAsRead(ctx context.Context, userID string, do
}
func (m *MsgMgo) SearchMessage(ctx context.Context, req *msg.SearchMessageReq) (int32, []*relation.MsgInfoModel, error) {
- var pipe mongo.Pipeline
- condition := bson.A{}
- if req.SendTime != "" {
- // Changed to keyed fields for bson.M to avoid govet errors
- condition = append(condition, bson.M{"$eq": bson.A{bson.M{"$dateToString": bson.M{"format": "%Y-%m-%d", "date": bson.M{"$toDate": "$$item.msg.send_time"}}}, req.SendTime}})
+ where := make(bson.A, 0, 6)
+ if req.RecvID != "" {
+ where = append(where, bson.M{"msgs.msg.recv_id": req.RecvID})
+ }
+ if req.SendID != "" {
+ where = append(where, bson.M{"msgs.msg.send_id": req.SendID})
}
if req.ContentType != 0 {
- condition = append(condition, bson.M{"$eq": bson.A{"$$item.msg.content_type", req.ContentType}})
+ where = append(where, bson.M{"msgs.msg.content_type": req.ContentType})
}
if req.SessionType != 0 {
- condition = append(condition, bson.M{"$eq": bson.A{"$$item.msg.session_type", req.SessionType}})
+ where = append(where, bson.M{"msgs.msg.session_type": req.SessionType})
}
- if req.RecvID != "" {
- condition = append(condition, bson.M{"$regexFind": bson.M{"input": "$$item.msg.recv_id", "regex": req.RecvID}})
+ if req.SendTime != "" {
+ sendTime, err := time.Parse(time.DateOnly, req.SendTime)
+ if err != nil {
+ return 0, nil, errs.ErrArgs.WrapMsg("invalid sendTime", "req", req.SendTime, "format", time.DateOnly, "cause", err.Error())
+ }
+ where = append(where,
+ bson.M{
+ "msgs.msg.send_time": bson.M{
+ "$gte": sendTime.UnixMilli(),
+ },
+ },
+ bson.M{
+ "msgs.msg.send_time": bson.M{
+ "$lt": sendTime.Add(time.Hour * 24).UnixMilli(),
+ },
+ },
+ )
}
- if req.SendID != "" {
- condition = append(condition, bson.M{"$regexFind": bson.M{"input": "$$item.msg.send_id", "regex": req.SendID}})
+ pipeline := bson.A{
+ bson.M{
+ "$unwind": "$msgs",
+ },
}
-
- or := bson.A{
- bson.M{"doc_id": bson.M{"$regex": "^si_", "$options": "i"}},
- bson.M{"doc_id": bson.M{"$regex": "^g_", "$options": "i"}},
- bson.M{"doc_id": bson.M{"$regex": "^sg_", "$options": "i"}},
+ if len(where) > 0 {
+ pipeline = append(pipeline, bson.M{
+ "$match": bson.M{"$and": where},
+ })
}
-
- // Use bson.D with keyed fields to specify the order explicitly
- pipe = mongo.Pipeline{
- {{"$match", bson.D{{Key: "$or", Value: or}}}},
- {{"$project", bson.D{
- {Key: "msgs", Value: bson.D{
- {Key: "$filter", Value: bson.D{
- {Key: "input", Value: "$msgs"},
- {Key: "as", Value: "item"},
- {Key: "cond", Value: bson.D{{Key: "$and", Value: condition}}},
- }},
- }},
- {Key: "doc_id", Value: 1},
- }}},
- {{"$unwind", bson.M{"path": "$msgs"}}},
- {{"$sort", bson.M{"msgs.msg.send_time": -1}}},
+ pipeline = append(pipeline,
+ bson.M{
+ "$project": bson.M{
+ "_id": 0,
+ "msg": "$msgs.msg",
+ },
+ },
+ bson.M{
+ "$count": "count",
+ },
+ )
+ count, err := mongoutil.Aggregate[int32](ctx, m.coll, pipeline)
+ if err != nil {
+ return 0, nil, err
}
- type docModel struct {
- DocID string `bson:"doc_id"`
- Msg *relation.MsgInfoModel `bson:"msgs"`
+ if len(count) == 0 || count[0] == 0 {
+ return 0, nil, nil
}
- msgsDocs, err := mongoutil.Aggregate[*docModel](ctx, m.coll, pipe)
+ pipeline = pipeline[:len(pipeline)-1]
+ pipeline = append(pipeline,
+ bson.M{
+ "$skip": (req.Pagination.GetPageNumber() - 1) * req.Pagination.GetShowNumber(),
+ },
+ bson.M{
+ "$limit": req.Pagination.GetShowNumber(),
+ },
+ )
+ msgs, err := mongoutil.Aggregate[*relation.MsgInfoModel](ctx, m.coll, pipeline)
if err != nil {
return 0, nil, err
}
- msgs := make([]*relation.MsgInfoModel, 0)
- for _, doc := range msgsDocs {
- msgInfo := doc.Msg
+ for i := range msgs {
+ msgInfo := msgs[i]
if msgInfo == nil || msgInfo.Msg == nil {
continue
}
@@ -350,17 +372,17 @@ func (m *MsgMgo) SearchMessage(ctx context.Context, req *msg.SearchMessageReq) (
}
msgs = append(msgs, msgInfo)
}
- start := (req.Pagination.PageNumber - 1) * req.Pagination.ShowNumber
- n := int32(len(msgs))
- if start >= n {
- return n, []*relation.MsgInfoModel{}, nil
- }
- if start+req.Pagination.ShowNumber < n {
- msgs = msgs[start : start+req.Pagination.ShowNumber]
- } else {
- msgs = msgs[start:]
- }
- return n, msgs, nil
+ //start := (req.Pagination.PageNumber - 1) * req.Pagination.ShowNumber
+ //n := int32(len(msgs))
+ //if start >= n {
+ // return n, []*relation.MsgInfoModel{}, nil
+ //}
+ //if start+req.Pagination.ShowNumber < n {
+ // msgs = msgs[start : start+req.Pagination.ShowNumber]
+ //} else {
+ // msgs = msgs[start:]
+ //}
+ return count[0], msgs, nil
}
func (m *MsgMgo) RangeUserSendCount(ctx context.Context, start time.Time, end time.Time, group bool, ase bool, pageNumber int32, showNumber int32) (msgCount int64, userCount int64, users []*relation.UserCount, dateCount map[string]int64, err error) {
From 961fb472ea7f776b8495fd639b9f77588b80e70c Mon Sep 17 00:00:00 2001
From: skiffer-git <72860476+skiffer-git@users.noreply.github.com>
Date: Fri, 10 May 2024 10:58:59 +0800
Subject: [PATCH 10/12] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 7c34664d6..d73d5749a 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@
## :busts_in_silhouette: Join Our Community
+ 💬 [Follow us on Twitter](https://twitter.com/founder_im63606)
-+ 🚀 [Join our Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-2hljfom5u-9ZuzP3NfEKW~BJKbpLm0Hw)
++ 🚀 [Join our Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-2ijy1ys1f-O0aEDCr7ExRZ7mwsHAVg9A)
+ :eyes: [Join our WeChat Group](https://openim-1253691595.cos.ap-nanjing.myqcloud.com/WechatIMG20.jpeg)
## Ⓜ️ About OpenIM
From 835ff3824f52c8f525927b7332ebbe6e122b8282 Mon Sep 17 00:00:00 2001
From: skiffer-git <72860476+skiffer-git@users.noreply.github.com>
Date: Tue, 14 May 2024 18:21:36 +0800
Subject: [PATCH 11/12] Etcd naming and discovery (#2300)
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* add etcd
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
* Add etcd as a service discovery mechanism
---
.env | 2 +-
config/discovery.yml | 13 +++++
config/share.yml | 1 -
config/zookeeper.yml | 6 ---
docker-compose.yml | 20 +++++++
go.mod | 10 ++--
go.sum | 19 +++++--
internal/api/init.go | 19 +++----
internal/api/router.go | 2 +-
internal/msggateway/client.go | 1 +
internal/msggateway/hub_server.go | 2 +-
internal/msggateway/init.go | 8 +--
internal/msggateway/n_ws_server.go | 7 ++-
internal/msgtransfer/init.go | 16 +++---
.../msgtransfer/online_history_msg_handler.go | 2 +-
.../online_msg_to_mongo_handler.go | 2 +-
internal/push/onlinepusher.go | 22 ++++----
internal/push/push.go | 2 +-
internal/push/push_handler.go | 2 +-
internal/rpc/auth/auth.go | 8 +--
internal/rpc/conversation/conversaion.go | 2 +-
internal/rpc/friend/friend.go | 9 ++--
internal/rpc/group/group.go | 2 +-
internal/rpc/msg/server.go | 2 +-
internal/rpc/third/third.go | 2 +-
internal/rpc/user/user.go | 2 +-
internal/tools/cron_task.go | 8 +--
pkg/common/cmd/api.go | 4 +-
pkg/common/cmd/auth.go | 4 +-
pkg/common/cmd/constant.go | 8 +--
pkg/common/cmd/conversation.go | 4 +-
pkg/common/cmd/cron_task.go | 2 +-
pkg/common/cmd/friend.go | 4 +-
pkg/common/cmd/group.go | 4 +-
pkg/common/cmd/msg.go | 4 +-
pkg/common/cmd/msg_gateway.go | 2 +-
pkg/common/cmd/msg_transfer.go | 2 +-
pkg/common/cmd/push.go | 4 +-
pkg/common/cmd/third.go | 4 +-
pkg/common/cmd/user.go | 4 +-
pkg/common/config/config.go | 14 ++++-
.../discoveryregister/discoveryregister.go | 34 ++++++------
pkg/common/discoveryregister/etcd/doc.go | 15 ++++++
.../discoveryregister/zookeeper/zookeeper.go | 44 ---------------
pkg/common/startrpc/start.go | 4 +-
tools/check-component/main.go | 54 ++++++++++++-------
46 files changed, 224 insertions(+), 182 deletions(-)
create mode 100644 config/discovery.yml
delete mode 100644 config/zookeeper.yml
create mode 100644 pkg/common/discoveryregister/etcd/doc.go
delete mode 100644 pkg/common/discoveryregister/zookeeper/zookeeper.go
diff --git a/.env b/.env
index d3ae0426a..1e7b1e11a 100644
--- a/.env
+++ b/.env
@@ -4,7 +4,7 @@ REDIS_IMAGE=redis:7.0.0
ZOOKEEPER_IMAGE=bitnami/zookeeper:3.8
KAFKA_IMAGE=bitnami/kafka:3.5.1
MINIO_IMAGE=minio/minio:RELEASE.2024-01-11T07-46-16Z
-
+ETCD_IMAGE=quay.io/coreos/etcd:v3.5.13
OPENIM_WEB_FRONT_IMAGE=openim/openim-web-front:release-v3.5.1
OPENIM_ADMIN_FRONT_IMAGE=openim/openim-admin-front:release-v1.7
diff --git a/config/discovery.yml b/config/discovery.yml
new file mode 100644
index 000000000..3d96ff9b6
--- /dev/null
+++ b/config/discovery.yml
@@ -0,0 +1,13 @@
+enable: "etcd"
+etcd:
+ rootDirectory: openim
+ address: [ localhost:12379 ]
+ username: ''
+ password: ''
+
+zookeeper:
+ schema: openim
+ address: [ localhost:12181 ]
+ username: ''
+ password: ''
+
diff --git a/config/share.yml b/config/share.yml
index 2abbb77a0..fc97b6a1f 100644
--- a/config/share.yml
+++ b/config/share.yml
@@ -1,5 +1,4 @@
secret: openIM123
-env: zookeeper
rpcRegisterName:
user: user
friend: friend
diff --git a/config/zookeeper.yml b/config/zookeeper.yml
deleted file mode 100644
index 33f52d7ca..000000000
--- a/config/zookeeper.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-schema: openim
-address: [ localhost:12181 ]
-username: ''
-password: ''
-
diff --git a/docker-compose.yml b/docker-compose.yml
index aeb53a417..d72c1a2fa 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -58,6 +58,26 @@ services:
networks:
- openim
+ etcd:
+ image: "${ETCD_IMAGE}"
+ container_name: etcd
+ ports:
+ - "12379:2379"
+ - "12380:2380"
+ environment:
+ - ETCD_NAME=s1
+ - ETCD_DATA_DIR=/etcd-data
+ - ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
+ - ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379
+ - ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
+ - ETCD_INITIAL_ADVERTISE_PEER_URLS=http://0.0.0.0:2380
+ - ETCD_INITIAL_CLUSTER=s1=http://0.0.0.0:2380
+ - ETCD_INITIAL_CLUSTER_TOKEN=tkn
+ - ETCD_INITIAL_CLUSTER_STATE=new
+ restart: always
+ networks:
+ - openim
+
kafka:
image: "${KAFKA_IMAGE}"
container_name: kafka
diff --git a/go.mod b/go.mod
index b522065da..e9777eaa8 100644
--- a/go.mod
+++ b/go.mod
@@ -14,7 +14,7 @@ require (
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
github.com/mitchellh/mapstructure v1.5.0
github.com/openimsdk/protocol v0.0.65
- github.com/openimsdk/tools v0.0.49-alpha.2
+ github.com/openimsdk/tools v0.0.49-alpha.18
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0
github.com/stretchr/testify v1.9.0
@@ -44,7 +44,6 @@ require (
golang.org/x/sync v0.6.0
)
-
require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
@@ -59,6 +58,8 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/clbanning/mxj v1.8.4 // indirect
+ github.com/coreos/go-semver v0.3.0 // indirect
+ github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
@@ -75,7 +76,7 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-zookeeper/zk v1.0.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
- github.com/golang/protobuf v1.5.3 // indirect
+ github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
@@ -138,6 +139,9 @@ require (
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
+ go.etcd.io/etcd/api/v3 v3.5.13 // indirect
+ go.etcd.io/etcd/client/pkg/v3 v3.5.13 // indirect
+ go.etcd.io/etcd/client/v3 v3.5.13 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect
diff --git a/go.sum b/go.sum
index e2ecf7284..3acb4709c 100644
--- a/go.sum
+++ b/go.sum
@@ -47,6 +47,10 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/PB79y4KOPYVyFYdROxgaCwdTQ=
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM=
+github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
+github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
+github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
+github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -111,6 +115,7 @@ github.com/go-zookeeper/zk v1.0.3 h1:7M2kwOsc//9VeeFiPtf+uSJlVpU66x9Ba5+8XK7/TDg
github.com/go-zookeeper/zk v1.0.3/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
+github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
@@ -132,8 +137,8 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
-github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
-github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
+github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
+github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -283,8 +288,8 @@ github.com/openimsdk/gomake v0.0.13 h1:xLDe/moqgWpRoptHzI4packAWzs4C16b+sVY+txNJ
github.com/openimsdk/gomake v0.0.13/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
github.com/openimsdk/protocol v0.0.65 h1:SPT9qyUsFRTTKSKb/FjpS+xr6sxz/Kbnu+su1bxYagc=
github.com/openimsdk/protocol v0.0.65/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
-github.com/openimsdk/tools v0.0.49-alpha.2 h1:8IfV6o2ySU7C54sh/MG7ctEp1h3lSNe03OCUDWSk5Ws=
-github.com/openimsdk/tools v0.0.49-alpha.2/go.mod h1:P4oGP1Pd+d4ctbLD5U/XQTgl8yu8Hd3skx640Fr69ko=
+github.com/openimsdk/tools v0.0.49-alpha.18 h1:ARQeCiRmExvtB6XYItegThuV63JGOTxddwhSLHYXd78=
+github.com/openimsdk/tools v0.0.49-alpha.18/go.mod h1:g7mkHXYUPi0/8aAX8VPMHpnb3hqdV69Jph+bXOGvvNM=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
@@ -378,6 +383,12 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
+go.etcd.io/etcd/api/v3 v3.5.13 h1:8WXU2/NBge6AUF1K1gOexB6e07NgsN1hXK0rSTtgSp4=
+go.etcd.io/etcd/api/v3 v3.5.13/go.mod h1:gBqlqkcMMZMVTMm4NDZloEVJzxQOQIls8splbqBDa0c=
+go.etcd.io/etcd/client/pkg/v3 v3.5.13 h1:RVZSAnWWWiI5IrYAXjQorajncORbS0zI48LQlE2kQWg=
+go.etcd.io/etcd/client/pkg/v3 v3.5.13/go.mod h1:XxHT4u1qU12E2+po+UVPrEeL94Um6zL58ppuJWXSAB8=
+go.etcd.io/etcd/client/v3 v3.5.13 h1:o0fHTNJLeO0MyVbc7I3fsCf6nrOqn5d+diSarKnB2js=
+go.etcd.io/etcd/client/v3 v3.5.13/go.mod h1:cqiAeY8b5DEEcpxvgWKsbLIWNM/8Wy2xJSDMtioMcoI=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
diff --git a/internal/api/init.go b/internal/api/init.go
index 6e784da9a..b49a14569 100644
--- a/internal/api/init.go
+++ b/internal/api/init.go
@@ -38,20 +38,17 @@ import (
)
type Config struct {
- RpcConfig config.API
- MongodbConfig config.Mongo
- ZookeeperConfig config.ZooKeeper
- NotificationConfig config.Notification
- Share config.Share
- MinioConfig config.Minio
+ API config.API
+ Share config.Share
+ Discovery config.Discovery
}
func Start(ctx context.Context, index int, config *Config) error {
- apiPort, err := datautil.GetElemByIndex(config.RpcConfig.Api.Ports, index)
+ apiPort, err := datautil.GetElemByIndex(config.API.Api.Ports, index)
if err != nil {
return err
}
- prometheusPort, err := datautil.GetElemByIndex(config.RpcConfig.Prometheus.Ports, index)
+ prometheusPort, err := datautil.GetElemByIndex(config.API.Prometheus.Ports, index)
if err != nil {
return err
}
@@ -59,7 +56,7 @@ func Start(ctx context.Context, index int, config *Config) error {
var client discovery.SvcDiscoveryRegistry
// Determine whether zk is passed according to whether it is a clustered deployment
- client, err = kdisc.NewDiscoveryRegister(&config.ZookeeperConfig, &config.Share)
+ client, err = kdisc.NewDiscoveryRegister(&config.Discovery, &config.Share)
if err != nil {
return errs.WrapMsg(err, "failed to register discovery service")
}
@@ -70,7 +67,7 @@ func Start(ctx context.Context, index int, config *Config) error {
)
router := newGinRouter(client, config)
- if config.RpcConfig.Prometheus.Enable {
+ if config.API.Prometheus.Enable {
go func() {
p := ginprom.NewPrometheus("app", prommetrics.GetGinCusMetrics("Api"))
p.SetListenAddress(fmt.Sprintf(":%d", prometheusPort))
@@ -81,7 +78,7 @@ func Start(ctx context.Context, index int, config *Config) error {
}()
}
- address := net.JoinHostPort(network.GetListenIP(config.RpcConfig.Api.ListenIP), strconv.Itoa(apiPort))
+ address := net.JoinHostPort(network.GetListenIP(config.API.Api.ListenIP), strconv.Itoa(apiPort))
server := http.Server{Addr: address, Handler: router}
log.CInfo(ctx, "API server is initializing", "address", address, "apiPort", apiPort, "prometheusPort", prometheusPort)
diff --git a/internal/api/router.go b/internal/api/router.go
index bd2de99db..1fbb33b09 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -34,7 +34,7 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En
messageRpc := rpcclient.NewMessage(disCov, config.Share.RpcRegisterName.Msg)
conversationRpc := rpcclient.NewConversation(disCov, config.Share.RpcRegisterName.Conversation)
authRpc := rpcclient.NewAuth(disCov, config.Share.RpcRegisterName.Auth)
- thirdRpc := rpcclient.NewThird(disCov, config.Share.RpcRegisterName.Third, config.RpcConfig.Prometheus.GrafanaURL)
+ thirdRpc := rpcclient.NewThird(disCov, config.Share.RpcRegisterName.Third, config.API.Prometheus.GrafanaURL)
u := NewUserApi(*userRpc)
m := NewMessageApi(messageRpc, userRpc, config.Share.IMAdminUserID)
diff --git a/internal/msggateway/client.go b/internal/msggateway/client.go
index af869dd85..0581a025b 100644
--- a/internal/msggateway/client.go
+++ b/internal/msggateway/client.go
@@ -286,6 +286,7 @@ func (c *Client) KickOnlineMessage() error {
resp := Resp{
ReqIdentifier: WSKickOnlineMsg,
}
+ log.ZDebug(c.ctx, "KickOnlineMessage debug ")
err := c.writeBinaryMsg(resp)
c.close()
return err
diff --git a/internal/msggateway/hub_server.go b/internal/msggateway/hub_server.go
index bfe81b602..f9bb699ed 100644
--- a/internal/msggateway/hub_server.go
+++ b/internal/msggateway/hub_server.go
@@ -35,7 +35,7 @@ func (s *Server) InitServer(ctx context.Context, config *Config, disCov discover
}
func (s *Server) Start(ctx context.Context, index int, conf *Config) error {
- return startrpc.Start(ctx, &conf.ZookeeperConfig, &conf.MsgGateway.Prometheus, conf.MsgGateway.ListenIP,
+ return startrpc.Start(ctx, &conf.Discovery, &conf.MsgGateway.Prometheus, conf.MsgGateway.ListenIP,
conf.MsgGateway.RPC.RegisterIP,
conf.MsgGateway.RPC.Ports, index,
conf.Share.RpcRegisterName.MessageGateway,
diff --git a/internal/msggateway/init.go b/internal/msggateway/init.go
index 727ade0af..ef24d1bf9 100644
--- a/internal/msggateway/init.go
+++ b/internal/msggateway/init.go
@@ -24,10 +24,10 @@ import (
)
type Config struct {
- MsgGateway config.MsgGateway
- ZookeeperConfig config.ZooKeeper
- Share config.Share
- WebhooksConfig config.Webhooks
+ MsgGateway config.MsgGateway
+ Share config.Share
+ WebhooksConfig config.Webhooks
+ Discovery config.Discovery
}
// Start run ws server.
diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go
index cf607d470..defec16df 100644
--- a/internal/msggateway/n_ws_server.go
+++ b/internal/msggateway/n_ws_server.go
@@ -211,7 +211,8 @@ func (ws *WsServer) sendUserOnlineInfoToOtherNode(ctx context.Context, client *C
// Online push user online message to other node
for _, v := range conns {
- v := v // safe closure var
+ v := v
+ log.ZDebug(ctx, " sendUserOnlineInfoToOtherNode conn ", "target", v.Target())
if v.Target() == ws.disCov.GetSelfConnTarget() {
log.ZDebug(ctx, "Filter out this node", "node", v.Target())
continue
@@ -267,7 +268,9 @@ func (ws *WsServer) registerClient(client *Client) {
}
wg := sync.WaitGroup{}
- if ws.msgGatewayConfig.Share.Env == "zookeeper" {
+ log.ZDebug(client.ctx, "ws.msgGatewayConfig.Discovery.Enable", ws.msgGatewayConfig.Discovery.Enable)
+
+ if ws.msgGatewayConfig.Discovery.Enable != "k8s" {
wg.Add(1)
go func() {
defer wg.Done()
diff --git a/internal/msgtransfer/init.go b/internal/msgtransfer/init.go
index 68d953e90..3384b8493 100644
--- a/internal/msgtransfer/init.go
+++ b/internal/msgtransfer/init.go
@@ -56,13 +56,13 @@ type MsgTransfer struct {
}
type Config struct {
- MsgTransfer config.MsgTransfer
- RedisConfig config.Redis
- MongodbConfig config.Mongo
- KafkaConfig config.Kafka
- ZookeeperConfig config.ZooKeeper
- Share config.Share
- WebhooksConfig config.Webhooks
+ MsgTransfer config.MsgTransfer
+ RedisConfig config.Redis
+ MongodbConfig config.Mongo
+ KafkaConfig config.Kafka
+ Share config.Share
+ WebhooksConfig config.Webhooks
+ Discovery config.Discovery
}
func Start(ctx context.Context, index int, config *Config) error {
@@ -76,7 +76,7 @@ func Start(ctx context.Context, index int, config *Config) error {
if err != nil {
return err
}
- client, err := kdisc.NewDiscoveryRegister(&config.ZookeeperConfig, &config.Share)
+ client, err := kdisc.NewDiscoveryRegister(&config.Discovery, &config.Share)
if err != nil {
return err
}
diff --git a/internal/msgtransfer/online_history_msg_handler.go b/internal/msgtransfer/online_history_msg_handler.go
index 8691e92ab..df2660804 100644
--- a/internal/msgtransfer/online_history_msg_handler.go
+++ b/internal/msgtransfer/online_history_msg_handler.go
@@ -83,7 +83,7 @@ type OnlineHistoryRedisConsumerHandler struct {
func NewOnlineHistoryRedisConsumerHandler(kafkaConf *config.Kafka, database controller.CommonMsgDatabase,
conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient) (*OnlineHistoryRedisConsumerHandler, error) {
- historyConsumerGroup, err := kafka.NewMConsumerGroup(kafkaConf.Build(), kafkaConf.ToRedisGroupID, []string{kafkaConf.ToRedisTopic})
+ historyConsumerGroup, err := kafka.NewMConsumerGroup(kafkaConf.Build(), kafkaConf.ToRedisGroupID, []string{kafkaConf.ToRedisTopic}, true)
if err != nil {
return nil, err
}
diff --git a/internal/msgtransfer/online_msg_to_mongo_handler.go b/internal/msgtransfer/online_msg_to_mongo_handler.go
index 978302e76..c9c035893 100644
--- a/internal/msgtransfer/online_msg_to_mongo_handler.go
+++ b/internal/msgtransfer/online_msg_to_mongo_handler.go
@@ -33,7 +33,7 @@ type OnlineHistoryMongoConsumerHandler struct {
}
func NewOnlineHistoryMongoConsumerHandler(kafkaConf *config.Kafka, database controller.CommonMsgDatabase) (*OnlineHistoryMongoConsumerHandler, error) {
- historyConsumerGroup, err := kafka.NewMConsumerGroup(kafkaConf.Build(), kafkaConf.ToMongoGroupID, []string{kafkaConf.ToMongoTopic})
+ historyConsumerGroup, err := kafka.NewMConsumerGroup(kafkaConf.Build(), kafkaConf.ToMongoGroupID, []string{kafkaConf.ToMongoTopic}, true)
if err != nil {
return nil, err
}
diff --git a/internal/push/onlinepusher.go b/internal/push/onlinepusher.go
index 30bdf3e2e..a61399fb6 100644
--- a/internal/push/onlinepusher.go
+++ b/internal/push/onlinepusher.go
@@ -12,11 +12,6 @@ import (
"sync"
)
-const (
- KUBERNETES = "k8s"
- ZOOKEEPER = "zookeeper"
-)
-
type OnlinePusher interface {
GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData,
pushToUserIDs []string) (wsResults []*msggateway.SingleMsgToUserResults, err error)
@@ -42,10 +37,12 @@ func (u emptyOnlinePUsher) GetOnlinePushFailedUserIDs(ctx context.Context, msg *
}
func NewOnlinePusher(disCov discovery.SvcDiscoveryRegistry, config *Config) OnlinePusher {
- switch config.Share.Env {
- case KUBERNETES:
+ switch config.Discovery.Enable {
+ case "k8s":
return NewK8sStaticConsistentHash(disCov, config)
- case ZOOKEEPER:
+ case "zookeeper":
+ return NewDefaultAllNode(disCov, config)
+ case "etcd":
return NewDefaultAllNode(disCov, config)
default:
return newEmptyOnlinePUsher()
@@ -64,7 +61,12 @@ func NewDefaultAllNode(disCov discovery.SvcDiscoveryRegistry, config *Config) *D
func (d *DefaultAllNode) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData,
pushToUserIDs []string) (wsResults []*msggateway.SingleMsgToUserResults, err error) {
conns, err := d.disCov.GetConns(ctx, d.config.Share.RpcRegisterName.MessageGateway)
- log.ZDebug(ctx, "get gateway conn", "conn length", len(conns))
+ if len(conns) == 0 {
+ log.ZWarn(ctx, "get gateway conn 0 ", nil)
+ } else {
+ log.ZDebug(ctx, "get gateway conn", "conn length", len(conns))
+ }
+
if err != nil {
return nil, err
}
@@ -85,10 +87,12 @@ func (d *DefaultAllNode) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.M
// Online push message
for _, conn := range conns {
conn := conn // loop var safe
+ ctx := ctx
wg.Go(func() error {
msgClient := msggateway.NewMsgGatewayClient(conn)
reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(ctx, input)
if err != nil {
+ log.ZError(ctx, "SuperGroupOnlineBatchPushOneMsg ", err, "req:", input.String())
return nil
}
diff --git a/internal/push/push.go b/internal/push/push.go
index 18012a864..2e5c4e526 100644
--- a/internal/push/push.go
+++ b/internal/push/push.go
@@ -24,11 +24,11 @@ type Config struct {
RedisConfig config.Redis
MongodbConfig config.Mongo
KafkaConfig config.Kafka
- ZookeeperConfig config.ZooKeeper
NotificationConfig config.Notification
Share config.Share
WebhooksConfig config.Webhooks
LocalCacheConfig config.LocalCache
+ Discovery config.Discovery
}
func (p pushServer) PushMsg(ctx context.Context, req *pbpush.PushMsgReq) (*pbpush.PushMsgResp, error) {
diff --git a/internal/push/push_handler.go b/internal/push/push_handler.go
index 3a9a696f6..bf0ede375 100644
--- a/internal/push/push_handler.go
+++ b/internal/push/push_handler.go
@@ -60,7 +60,7 @@ func NewConsumerHandler(config *Config, offlinePusher offlinepush.OfflinePusher,
var consumerHandler ConsumerHandler
var err error
consumerHandler.pushConsumerGroup, err = kafka.NewMConsumerGroup(config.KafkaConfig.Build(), config.KafkaConfig.ToPushGroupID,
- []string{config.KafkaConfig.ToPushTopic})
+ []string{config.KafkaConfig.ToPushTopic}, true)
if err != nil {
return nil, err
}
diff --git a/internal/rpc/auth/auth.go b/internal/rpc/auth/auth.go
index c6d236b21..ddb655398 100644
--- a/internal/rpc/auth/auth.go
+++ b/internal/rpc/auth/auth.go
@@ -45,10 +45,10 @@ type authServer struct {
}
type Config struct {
- RpcConfig config.Auth
- RedisConfig config.Redis
- ZookeeperConfig config.ZooKeeper
- Share config.Share
+ RpcConfig config.Auth
+ RedisConfig config.Redis
+ Share config.Share
+ Discovery config.Discovery
}
func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryRegistry, server *grpc.Server) error {
diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go
index 96d2a403f..4c7828610 100644
--- a/internal/rpc/conversation/conversaion.go
+++ b/internal/rpc/conversation/conversaion.go
@@ -51,10 +51,10 @@ type Config struct {
RpcConfig config.Conversation
RedisConfig config.Redis
MongodbConfig config.Mongo
- ZookeeperConfig config.ZooKeeper
NotificationConfig config.Notification
Share config.Share
LocalCacheConfig config.LocalCache
+ Discovery config.Discovery
}
func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryRegistry, server *grpc.Server) error {
diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go
index bffda3c04..b49490f26 100644
--- a/internal/rpc/friend/friend.go
+++ b/internal/rpc/friend/friend.go
@@ -50,14 +50,15 @@ type friendServer struct {
}
type Config struct {
- RpcConfig config.Friend
- RedisConfig config.Redis
- MongodbConfig config.Mongo
- ZookeeperConfig config.ZooKeeper
+ RpcConfig config.Friend
+ RedisConfig config.Redis
+ MongodbConfig config.Mongo
+ //ZookeeperConfig config.ZooKeeper
NotificationConfig config.Notification
Share config.Share
WebhooksConfig config.Webhooks
LocalCacheConfig config.LocalCache
+ Discovery config.Discovery
}
func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryRegistry, server *grpc.Server) error {
diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go
index 13bd7f9be..551554c23 100644
--- a/internal/rpc/group/group.go
+++ b/internal/rpc/group/group.go
@@ -68,11 +68,11 @@ type Config struct {
RpcConfig config.Group
RedisConfig config.Redis
MongodbConfig config.Mongo
- ZookeeperConfig config.ZooKeeper
NotificationConfig config.Notification
Share config.Share
WebhooksConfig config.Webhooks
LocalCacheConfig config.LocalCache
+ Discovery config.Discovery
}
func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryRegistry, server *grpc.Server) error {
diff --git a/internal/rpc/msg/server.go b/internal/rpc/msg/server.go
index 3f4df8d4b..5d7c0b297 100644
--- a/internal/rpc/msg/server.go
+++ b/internal/rpc/msg/server.go
@@ -59,11 +59,11 @@ type (
RedisConfig config.Redis
MongodbConfig config.Mongo
KafkaConfig config.Kafka
- ZookeeperConfig config.ZooKeeper
NotificationConfig config.Notification
Share config.Share
WebhooksConfig config.Webhooks
LocalCacheConfig config.LocalCache
+ Discovery config.Discovery
}
)
diff --git a/internal/rpc/third/third.go b/internal/rpc/third/third.go
index 9bf8cafa9..a3d9085d3 100644
--- a/internal/rpc/third/third.go
+++ b/internal/rpc/third/third.go
@@ -46,11 +46,11 @@ type Config struct {
RpcConfig config.Third
RedisConfig config.Redis
MongodbConfig config.Mongo
- ZookeeperConfig config.ZooKeeper
NotificationConfig config.Notification
Share config.Share
MinioConfig config.Minio
LocalCacheConfig config.LocalCache
+ Discovery config.Discovery
}
func Start(ctx context.Context, config *Config, client discovery.SvcDiscoveryRegistry, server *grpc.Server) error {
diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go
index c453ac9f8..a28fa24e2 100644
--- a/internal/rpc/user/user.go
+++ b/internal/rpc/user/user.go
@@ -61,11 +61,11 @@ type Config struct {
RedisConfig config.Redis
MongodbConfig config.Mongo
KafkaConfig config.Kafka
- ZookeeperConfig config.ZooKeeper
NotificationConfig config.Notification
Share config.Share
WebhooksConfig config.Webhooks
LocalCacheConfig config.LocalCache
+ Discovery config.Discovery
}
func Start(ctx context.Context, config *Config, client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
diff --git a/internal/tools/cron_task.go b/internal/tools/cron_task.go
index 20baeffaf..bf037b694 100644
--- a/internal/tools/cron_task.go
+++ b/internal/tools/cron_task.go
@@ -33,9 +33,9 @@ import (
)
type CronTaskConfig struct {
- CronTask config.CronTask
- ZookeeperConfig config.ZooKeeper
- Share config.Share
+ CronTask config.CronTask
+ Share config.Share
+ Discovery config.Discovery
}
func Start(ctx context.Context, config *CronTaskConfig) error {
@@ -43,7 +43,7 @@ func Start(ctx context.Context, config *CronTaskConfig) error {
if config.CronTask.RetainChatRecords < 1 {
return errs.New("msg destruct time must be greater than 1").Wrap()
}
- client, err := kdisc.NewDiscoveryRegister(&config.ZookeeperConfig, &config.Share)
+ client, err := kdisc.NewDiscoveryRegister(&config.Discovery, &config.Share)
if err != nil {
return errs.WrapMsg(err, "failed to register discovery service")
}
diff --git a/pkg/common/cmd/api.go b/pkg/common/cmd/api.go
index 022fb1097..ecdb0dd3a 100644
--- a/pkg/common/cmd/api.go
+++ b/pkg/common/cmd/api.go
@@ -33,9 +33,9 @@ func NewApiCmd() *ApiCmd {
var apiConfig api.Config
ret := &ApiCmd{apiConfig: &apiConfig}
ret.configMap = map[string]any{
- OpenIMAPICfgFileName: &apiConfig.RpcConfig,
- ZookeeperConfigFileName: &apiConfig.ZookeeperConfig,
+ OpenIMAPICfgFileName: &apiConfig.API,
ShareFileName: &apiConfig.Share,
+ DiscoveryConfigFilename: &apiConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
diff --git a/pkg/common/cmd/auth.go b/pkg/common/cmd/auth.go
index 5ed02ffd0..7d75a7da6 100644
--- a/pkg/common/cmd/auth.go
+++ b/pkg/common/cmd/auth.go
@@ -36,8 +36,8 @@ func NewAuthRpcCmd() *AuthRpcCmd {
ret.configMap = map[string]any{
OpenIMRPCAuthCfgFileName: &authConfig.RpcConfig,
RedisConfigFileName: &authConfig.RedisConfig,
- ZookeeperConfigFileName: &authConfig.ZookeeperConfig,
ShareFileName: &authConfig.Share,
+ DiscoveryConfigFilename: &authConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
@@ -53,7 +53,7 @@ func (a *AuthRpcCmd) Exec() error {
}
func (a *AuthRpcCmd) runE() error {
- return startrpc.Start(a.ctx, &a.authConfig.ZookeeperConfig, &a.authConfig.RpcConfig.Prometheus, a.authConfig.RpcConfig.RPC.ListenIP,
+ return startrpc.Start(a.ctx, &a.authConfig.Discovery, &a.authConfig.RpcConfig.Prometheus, a.authConfig.RpcConfig.RPC.ListenIP,
a.authConfig.RpcConfig.RPC.RegisterIP, a.authConfig.RpcConfig.RPC.Ports,
a.Index(), a.authConfig.Share.RpcRegisterName.Auth, &a.authConfig.Share, a.authConfig, auth.Start)
}
diff --git a/pkg/common/cmd/constant.go b/pkg/common/cmd/constant.go
index 55eb4a069..45dbcafda 100644
--- a/pkg/common/cmd/constant.go
+++ b/pkg/common/cmd/constant.go
@@ -26,7 +26,6 @@ var (
LocalCacheConfigFileName string
KafkaConfigFileName string
RedisConfigFileName string
- ZookeeperConfigFileName string
MongodbConfigFileName string
MinioConfigFileName string
LogConfigFileName string
@@ -42,6 +41,7 @@ var (
OpenIMRPCMsgCfgFileName string
OpenIMRPCThirdCfgFileName string
OpenIMRPCUserCfgFileName string
+ DiscoveryConfigFilename string
)
var ConfigEnvPrefixMap map[string]string
@@ -54,7 +54,6 @@ func init() {
LocalCacheConfigFileName = "local-cache.yml"
KafkaConfigFileName = "kafka.yml"
RedisConfigFileName = "redis.yml"
- ZookeeperConfigFileName = "zookeeper.yml"
MongodbConfigFileName = "mongodb.yml"
MinioConfigFileName = "minio.yml"
LogConfigFileName = "log.yml"
@@ -70,16 +69,17 @@ func init() {
OpenIMRPCMsgCfgFileName = "openim-rpc-msg.yml"
OpenIMRPCThirdCfgFileName = "openim-rpc-third.yml"
OpenIMRPCUserCfgFileName = "openim-rpc-user.yml"
+ DiscoveryConfigFilename = "discovery.yml"
ConfigEnvPrefixMap = make(map[string]string)
fileNames := []string{
FileName, NotificationFileName, ShareFileName, WebhooksConfigFileName,
- KafkaConfigFileName, RedisConfigFileName, ZookeeperConfigFileName,
+ KafkaConfigFileName, RedisConfigFileName,
MongodbConfigFileName, MinioConfigFileName, LogConfigFileName,
OpenIMAPICfgFileName, OpenIMCronTaskCfgFileName, OpenIMMsgGatewayCfgFileName,
OpenIMMsgTransferCfgFileName, OpenIMPushCfgFileName, OpenIMRPCAuthCfgFileName,
OpenIMRPCConversationCfgFileName, OpenIMRPCFriendCfgFileName, OpenIMRPCGroupCfgFileName,
- OpenIMRPCMsgCfgFileName, OpenIMRPCThirdCfgFileName, OpenIMRPCUserCfgFileName,
+ OpenIMRPCMsgCfgFileName, OpenIMRPCThirdCfgFileName, OpenIMRPCUserCfgFileName, DiscoveryConfigFilename,
}
for _, fileName := range fileNames {
diff --git a/pkg/common/cmd/conversation.go b/pkg/common/cmd/conversation.go
index 0a617c729..57ffa52bc 100644
--- a/pkg/common/cmd/conversation.go
+++ b/pkg/common/cmd/conversation.go
@@ -36,11 +36,11 @@ func NewConversationRpcCmd() *ConversationRpcCmd {
ret.configMap = map[string]any{
OpenIMRPCConversationCfgFileName: &conversationConfig.RpcConfig,
RedisConfigFileName: &conversationConfig.RedisConfig,
- ZookeeperConfigFileName: &conversationConfig.ZookeeperConfig,
MongodbConfigFileName: &conversationConfig.MongodbConfig,
ShareFileName: &conversationConfig.Share,
NotificationFileName: &conversationConfig.NotificationConfig,
LocalCacheConfigFileName: &conversationConfig.LocalCacheConfig,
+ DiscoveryConfigFilename: &conversationConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
@@ -55,7 +55,7 @@ func (a *ConversationRpcCmd) Exec() error {
}
func (a *ConversationRpcCmd) runE() error {
- return startrpc.Start(a.ctx, &a.conversationConfig.ZookeeperConfig, &a.conversationConfig.RpcConfig.Prometheus, a.conversationConfig.RpcConfig.RPC.ListenIP,
+ return startrpc.Start(a.ctx, &a.conversationConfig.Discovery, &a.conversationConfig.RpcConfig.Prometheus, a.conversationConfig.RpcConfig.RPC.ListenIP,
a.conversationConfig.RpcConfig.RPC.RegisterIP, a.conversationConfig.RpcConfig.RPC.Ports,
a.Index(), a.conversationConfig.Share.RpcRegisterName.Conversation, &a.conversationConfig.Share, a.conversationConfig, conversation.Start)
}
diff --git a/pkg/common/cmd/cron_task.go b/pkg/common/cmd/cron_task.go
index be26f5af3..fd4447524 100644
--- a/pkg/common/cmd/cron_task.go
+++ b/pkg/common/cmd/cron_task.go
@@ -34,8 +34,8 @@ func NewCronTaskCmd() *CronTaskCmd {
ret := &CronTaskCmd{cronTaskConfig: &cronTaskConfig}
ret.configMap = map[string]any{
OpenIMCronTaskCfgFileName: &cronTaskConfig.CronTask,
- ZookeeperConfigFileName: &cronTaskConfig.ZookeeperConfig,
ShareFileName: &cronTaskConfig.Share,
+ DiscoveryConfigFilename: &cronTaskConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
diff --git a/pkg/common/cmd/friend.go b/pkg/common/cmd/friend.go
index b8d46f77e..8be1f7745 100644
--- a/pkg/common/cmd/friend.go
+++ b/pkg/common/cmd/friend.go
@@ -36,12 +36,12 @@ func NewFriendRpcCmd() *FriendRpcCmd {
ret.configMap = map[string]any{
OpenIMRPCFriendCfgFileName: &friendConfig.RpcConfig,
RedisConfigFileName: &friendConfig.RedisConfig,
- ZookeeperConfigFileName: &friendConfig.ZookeeperConfig,
MongodbConfigFileName: &friendConfig.MongodbConfig,
ShareFileName: &friendConfig.Share,
NotificationFileName: &friendConfig.NotificationConfig,
WebhooksConfigFileName: &friendConfig.WebhooksConfig,
LocalCacheConfigFileName: &friendConfig.LocalCacheConfig,
+ DiscoveryConfigFilename: &friendConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
@@ -56,7 +56,7 @@ func (a *FriendRpcCmd) Exec() error {
}
func (a *FriendRpcCmd) runE() error {
- return startrpc.Start(a.ctx, &a.friendConfig.ZookeeperConfig, &a.friendConfig.RpcConfig.Prometheus, a.friendConfig.RpcConfig.RPC.ListenIP,
+ return startrpc.Start(a.ctx, &a.friendConfig.Discovery, &a.friendConfig.RpcConfig.Prometheus, a.friendConfig.RpcConfig.RPC.ListenIP,
a.friendConfig.RpcConfig.RPC.RegisterIP, a.friendConfig.RpcConfig.RPC.Ports,
a.Index(), a.friendConfig.Share.RpcRegisterName.Friend, &a.friendConfig.Share, a.friendConfig, friend.Start)
}
diff --git a/pkg/common/cmd/group.go b/pkg/common/cmd/group.go
index 8bf977824..f158b8c62 100644
--- a/pkg/common/cmd/group.go
+++ b/pkg/common/cmd/group.go
@@ -36,12 +36,12 @@ func NewGroupRpcCmd() *GroupRpcCmd {
ret.configMap = map[string]any{
OpenIMRPCGroupCfgFileName: &groupConfig.RpcConfig,
RedisConfigFileName: &groupConfig.RedisConfig,
- ZookeeperConfigFileName: &groupConfig.ZookeeperConfig,
MongodbConfigFileName: &groupConfig.MongodbConfig,
ShareFileName: &groupConfig.Share,
NotificationFileName: &groupConfig.NotificationConfig,
WebhooksConfigFileName: &groupConfig.WebhooksConfig,
LocalCacheConfigFileName: &groupConfig.LocalCacheConfig,
+ DiscoveryConfigFilename: &groupConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
@@ -56,7 +56,7 @@ func (a *GroupRpcCmd) Exec() error {
}
func (a *GroupRpcCmd) runE() error {
- return startrpc.Start(a.ctx, &a.groupConfig.ZookeeperConfig, &a.groupConfig.RpcConfig.Prometheus, a.groupConfig.RpcConfig.RPC.ListenIP,
+ return startrpc.Start(a.ctx, &a.groupConfig.Discovery, &a.groupConfig.RpcConfig.Prometheus, a.groupConfig.RpcConfig.RPC.ListenIP,
a.groupConfig.RpcConfig.RPC.RegisterIP, a.groupConfig.RpcConfig.RPC.Ports,
a.Index(), a.groupConfig.Share.RpcRegisterName.Group, &a.groupConfig.Share, a.groupConfig, group.Start)
}
diff --git a/pkg/common/cmd/msg.go b/pkg/common/cmd/msg.go
index a3b521b4b..91f7931fb 100644
--- a/pkg/common/cmd/msg.go
+++ b/pkg/common/cmd/msg.go
@@ -36,13 +36,13 @@ func NewMsgRpcCmd() *MsgRpcCmd {
ret.configMap = map[string]any{
OpenIMRPCMsgCfgFileName: &msgConfig.RpcConfig,
RedisConfigFileName: &msgConfig.RedisConfig,
- ZookeeperConfigFileName: &msgConfig.ZookeeperConfig,
MongodbConfigFileName: &msgConfig.MongodbConfig,
KafkaConfigFileName: &msgConfig.KafkaConfig,
ShareFileName: &msgConfig.Share,
NotificationFileName: &msgConfig.NotificationConfig,
WebhooksConfigFileName: &msgConfig.WebhooksConfig,
LocalCacheConfigFileName: &msgConfig.LocalCacheConfig,
+ DiscoveryConfigFilename: &msgConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
@@ -57,7 +57,7 @@ func (a *MsgRpcCmd) Exec() error {
}
func (a *MsgRpcCmd) runE() error {
- return startrpc.Start(a.ctx, &a.msgConfig.ZookeeperConfig, &a.msgConfig.RpcConfig.Prometheus, a.msgConfig.RpcConfig.RPC.ListenIP,
+ return startrpc.Start(a.ctx, &a.msgConfig.Discovery, &a.msgConfig.RpcConfig.Prometheus, a.msgConfig.RpcConfig.RPC.ListenIP,
a.msgConfig.RpcConfig.RPC.RegisterIP, a.msgConfig.RpcConfig.RPC.Ports,
a.Index(), a.msgConfig.Share.RpcRegisterName.Msg, &a.msgConfig.Share, a.msgConfig, msg.Start)
}
diff --git a/pkg/common/cmd/msg_gateway.go b/pkg/common/cmd/msg_gateway.go
index 897fd7008..78004094c 100644
--- a/pkg/common/cmd/msg_gateway.go
+++ b/pkg/common/cmd/msg_gateway.go
@@ -36,9 +36,9 @@ func NewMsgGatewayCmd() *MsgGatewayCmd {
ret := &MsgGatewayCmd{msgGatewayConfig: &msgGatewayConfig}
ret.configMap = map[string]any{
OpenIMMsgGatewayCfgFileName: &msgGatewayConfig.MsgGateway,
- ZookeeperConfigFileName: &msgGatewayConfig.ZookeeperConfig,
ShareFileName: &msgGatewayConfig.Share,
WebhooksConfigFileName: &msgGatewayConfig.WebhooksConfig,
+ DiscoveryConfigFilename: &msgGatewayConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
diff --git a/pkg/common/cmd/msg_transfer.go b/pkg/common/cmd/msg_transfer.go
index 86f42dc56..0d48281e5 100644
--- a/pkg/common/cmd/msg_transfer.go
+++ b/pkg/common/cmd/msg_transfer.go
@@ -37,9 +37,9 @@ func NewMsgTransferCmd() *MsgTransferCmd {
RedisConfigFileName: &msgTransferConfig.RedisConfig,
MongodbConfigFileName: &msgTransferConfig.MongodbConfig,
KafkaConfigFileName: &msgTransferConfig.KafkaConfig,
- ZookeeperConfigFileName: &msgTransferConfig.ZookeeperConfig,
ShareFileName: &msgTransferConfig.Share,
WebhooksConfigFileName: &msgTransferConfig.WebhooksConfig,
+ DiscoveryConfigFilename: &msgTransferConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
diff --git a/pkg/common/cmd/push.go b/pkg/common/cmd/push.go
index 0140ced23..3e7c4c249 100644
--- a/pkg/common/cmd/push.go
+++ b/pkg/common/cmd/push.go
@@ -36,13 +36,13 @@ func NewPushRpcCmd() *PushRpcCmd {
ret.configMap = map[string]any{
OpenIMPushCfgFileName: &pushConfig.RpcConfig,
RedisConfigFileName: &pushConfig.RedisConfig,
- ZookeeperConfigFileName: &pushConfig.ZookeeperConfig,
MongodbConfigFileName: &pushConfig.MongodbConfig,
KafkaConfigFileName: &pushConfig.KafkaConfig,
ShareFileName: &pushConfig.Share,
NotificationFileName: &pushConfig.NotificationConfig,
WebhooksConfigFileName: &pushConfig.WebhooksConfig,
LocalCacheConfigFileName: &pushConfig.LocalCacheConfig,
+ DiscoveryConfigFilename: &pushConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
@@ -57,7 +57,7 @@ func (a *PushRpcCmd) Exec() error {
}
func (a *PushRpcCmd) runE() error {
- return startrpc.Start(a.ctx, &a.pushConfig.ZookeeperConfig, &a.pushConfig.RpcConfig.Prometheus, a.pushConfig.RpcConfig.RPC.ListenIP,
+ return startrpc.Start(a.ctx, &a.pushConfig.Discovery, &a.pushConfig.RpcConfig.Prometheus, a.pushConfig.RpcConfig.RPC.ListenIP,
a.pushConfig.RpcConfig.RPC.RegisterIP, a.pushConfig.RpcConfig.RPC.Ports,
a.Index(), a.pushConfig.Share.RpcRegisterName.Push, &a.pushConfig.Share, a.pushConfig, push.Start)
}
diff --git a/pkg/common/cmd/third.go b/pkg/common/cmd/third.go
index 0dfa7d5be..b6731f1ff 100644
--- a/pkg/common/cmd/third.go
+++ b/pkg/common/cmd/third.go
@@ -36,12 +36,12 @@ func NewThirdRpcCmd() *ThirdRpcCmd {
ret.configMap = map[string]any{
OpenIMRPCThirdCfgFileName: &thirdConfig.RpcConfig,
RedisConfigFileName: &thirdConfig.RedisConfig,
- ZookeeperConfigFileName: &thirdConfig.ZookeeperConfig,
MongodbConfigFileName: &thirdConfig.MongodbConfig,
ShareFileName: &thirdConfig.Share,
NotificationFileName: &thirdConfig.NotificationConfig,
MinioConfigFileName: &thirdConfig.MinioConfig,
LocalCacheConfigFileName: &thirdConfig.LocalCacheConfig,
+ DiscoveryConfigFilename: &thirdConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
@@ -56,7 +56,7 @@ func (a *ThirdRpcCmd) Exec() error {
}
func (a *ThirdRpcCmd) runE() error {
- return startrpc.Start(a.ctx, &a.thirdConfig.ZookeeperConfig, &a.thirdConfig.RpcConfig.Prometheus, a.thirdConfig.RpcConfig.RPC.ListenIP,
+ return startrpc.Start(a.ctx, &a.thirdConfig.Discovery, &a.thirdConfig.RpcConfig.Prometheus, a.thirdConfig.RpcConfig.RPC.ListenIP,
a.thirdConfig.RpcConfig.RPC.RegisterIP, a.thirdConfig.RpcConfig.RPC.Ports,
a.Index(), a.thirdConfig.Share.RpcRegisterName.Third, &a.thirdConfig.Share, a.thirdConfig, third.Start)
}
diff --git a/pkg/common/cmd/user.go b/pkg/common/cmd/user.go
index 315b93256..674f9e3a6 100644
--- a/pkg/common/cmd/user.go
+++ b/pkg/common/cmd/user.go
@@ -36,13 +36,13 @@ func NewUserRpcCmd() *UserRpcCmd {
ret.configMap = map[string]any{
OpenIMRPCUserCfgFileName: &userConfig.RpcConfig,
RedisConfigFileName: &userConfig.RedisConfig,
- ZookeeperConfigFileName: &userConfig.ZookeeperConfig,
MongodbConfigFileName: &userConfig.MongodbConfig,
KafkaConfigFileName: &userConfig.KafkaConfig,
ShareFileName: &userConfig.Share,
NotificationFileName: &userConfig.NotificationConfig,
WebhooksConfigFileName: &userConfig.WebhooksConfig,
LocalCacheConfigFileName: &userConfig.LocalCacheConfig,
+ DiscoveryConfigFilename: &userConfig.Discovery,
}
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
@@ -57,7 +57,7 @@ func (a *UserRpcCmd) Exec() error {
}
func (a *UserRpcCmd) runE() error {
- return startrpc.Start(a.ctx, &a.userConfig.ZookeeperConfig, &a.userConfig.RpcConfig.Prometheus, a.userConfig.RpcConfig.RPC.ListenIP,
+ return startrpc.Start(a.ctx, &a.userConfig.Discovery, &a.userConfig.RpcConfig.Prometheus, a.userConfig.RpcConfig.RPC.ListenIP,
a.userConfig.RpcConfig.RPC.RegisterIP, a.userConfig.RpcConfig.RPC.Ports,
a.Index(), a.userConfig.Share.RpcRegisterName.User, &a.userConfig.Share, a.userConfig, user.Start)
}
diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go
index 24d04d8cc..12c4f7f78 100644
--- a/pkg/common/config/config.go
+++ b/pkg/common/config/config.go
@@ -345,7 +345,6 @@ type AfterConfig struct {
type Share struct {
Secret string `mapstructure:"secret"`
- Env string `mapstructure:"env"`
RpcRegisterName RpcRegisterName `mapstructure:"rpcRegisterName"`
IMAdminUserID []string `mapstructure:"imAdminUserID"`
}
@@ -432,6 +431,19 @@ type ZooKeeper struct {
Password string `mapstructure:"password"`
}
+type Discovery struct {
+ Enable string `mapstructure:"enable"`
+ Etcd Etcd `mapstructure:"etcd"`
+ ZooKeeper ZooKeeper `mapstructure:"zooKeeper"`
+}
+
+type Etcd struct {
+ RootDirectory string `mapstructure:"rootDirectory"`
+ Address []string `mapstructure:"address"`
+ Username string `mapstructure:"username"`
+ Password string `mapstructure:"password"`
+}
+
func (m *Mongo) Build() *mongoutil.Config {
return &mongoutil.Config{
Uri: m.URI,
diff --git a/pkg/common/discoveryregister/discoveryregister.go b/pkg/common/discoveryregister/discoveryregister.go
index 38d7382fa..559c937c1 100644
--- a/pkg/common/discoveryregister/discoveryregister.go
+++ b/pkg/common/discoveryregister/discoveryregister.go
@@ -18,36 +18,34 @@ import (
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister/kubernetes"
"github.com/openimsdk/tools/discovery"
+ "github.com/openimsdk/tools/discovery/etcd"
"github.com/openimsdk/tools/discovery/zookeeper"
"github.com/openimsdk/tools/errs"
"time"
)
-const (
- zookeeperConst = "zookeeper"
- kubenetesConst = "k8s"
- directConst = "direct"
-)
-
// NewDiscoveryRegister creates a new service discovery and registry client based on the provided environment type.
-func NewDiscoveryRegister(zookeeperConfig *config.ZooKeeper, share *config.Share) (discovery.SvcDiscoveryRegistry, error) {
- switch share.Env {
- case zookeeperConst:
-
+func NewDiscoveryRegister(discovery *config.Discovery, share *config.Share) (discovery.SvcDiscoveryRegistry, error) {
+ switch discovery.Enable {
+ case "zookeeper":
return zookeeper.NewZkClient(
- zookeeperConfig.Address,
- zookeeperConfig.Schema,
+ discovery.ZooKeeper.Address,
+ discovery.ZooKeeper.Schema,
zookeeper.WithFreq(time.Hour),
- zookeeper.WithUserNameAndPassword(zookeeperConfig.Username, zookeeperConfig.Password),
+ zookeeper.WithUserNameAndPassword(discovery.ZooKeeper.Username, discovery.ZooKeeper.Password),
zookeeper.WithRoundRobin(),
zookeeper.WithTimeout(10),
)
- case kubenetesConst:
+ case "k8s":
return kubernetes.NewK8sDiscoveryRegister(share.RpcRegisterName.MessageGateway)
- case directConst:
- //return direct.NewConnDirect(config)
+ case "etcd":
+ return etcd.NewSvcDiscoveryRegistry(
+ discovery.Etcd.RootDirectory,
+ discovery.Etcd.Address,
+ etcd.WithDialTimeout(10*time.Second),
+ etcd.WithMaxCallSendMsgSize(20*1024*1024),
+ etcd.WithUsernameAndPassword(discovery.Etcd.Username, discovery.Etcd.Password))
default:
- return nil, errs.New("unsupported discovery type", "type", share.Env).Wrap()
+ return nil, errs.New("unsupported discovery type", "type", discovery.Enable).Wrap()
}
- return nil, nil
}
diff --git a/pkg/common/discoveryregister/etcd/doc.go b/pkg/common/discoveryregister/etcd/doc.go
new file mode 100644
index 000000000..1da7508a1
--- /dev/null
+++ b/pkg/common/discoveryregister/etcd/doc.go
@@ -0,0 +1,15 @@
+// Copyright © 2024 OpenIM. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package kubernetes // import "github.com/openimsdk/open-im-server/v3/pkg/common/discoveryregister/etcd"
diff --git a/pkg/common/discoveryregister/zookeeper/zookeeper.go b/pkg/common/discoveryregister/zookeeper/zookeeper.go
deleted file mode 100644
index 1d11414b6..000000000
--- a/pkg/common/discoveryregister/zookeeper/zookeeper.go
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright © 2023 OpenIM. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package zookeeper
-
-import (
- "os"
- "strings"
-)
-
-// getEnv returns the value of an environment variable if it exists, otherwise it returns the fallback value.
-func getEnv(key, fallback string) string {
- if value, exists := os.LookupEnv(key); exists {
- return value
- }
- return fallback
-}
-
-// getZkAddrFromEnv returns the Zookeeper addresses combined from the ZOOKEEPER_ADDRESS and ZOOKEEPER_PORT environment variables.
-// If the environment variables are not set, it returns the fallback value.
-func getZkAddrFromEnv(fallback []string) []string {
- address, addrExists := os.LookupEnv("ZOOKEEPER_ADDRESS")
- port, portExists := os.LookupEnv("ZOOKEEPER_PORT")
-
- if addrExists && portExists {
- addresses := strings.Split(address, ",")
- for i, addr := range addresses {
- addresses[i] = addr + ":" + port
- }
- return addresses
- }
- return fallback
-}
diff --git a/pkg/common/startrpc/start.go b/pkg/common/startrpc/start.go
index ebcd5aa7c..a36bcfe1c 100644
--- a/pkg/common/startrpc/start.go
+++ b/pkg/common/startrpc/start.go
@@ -44,7 +44,7 @@ import (
)
// Start rpc server.
-func Start[T any](ctx context.Context, zookeeperConfig *config2.ZooKeeper, prometheusConfig *config2.Prometheus, listenIP,
+func Start[T any](ctx context.Context, discovery *config2.Discovery, prometheusConfig *config2.Prometheus, listenIP,
registerIP string, rpcPorts []int, index int, rpcRegisterName string, share *config2.Share, config T, rpcFn func(ctx context.Context,
config T, client discovery.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption) error {
@@ -68,7 +68,7 @@ func Start[T any](ctx context.Context, zookeeperConfig *config2.ZooKeeper, prome
}
defer listener.Close()
- client, err := kdisc.NewDiscoveryRegister(zookeeperConfig, share)
+ client, err := kdisc.NewDiscoveryRegister(discovery, share)
if err != nil {
return err
}
diff --git a/tools/check-component/main.go b/tools/check-component/main.go
index 7fe64d3c5..5fa84ac36 100644
--- a/tools/check-component/main.go
+++ b/tools/check-component/main.go
@@ -22,6 +22,7 @@ import (
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/tools/db/mongoutil"
"github.com/openimsdk/tools/db/redisutil"
+ "github.com/openimsdk/tools/discovery/etcd"
"github.com/openimsdk/tools/discovery/zookeeper"
"github.com/openimsdk/tools/mq/kafka"
"github.com/openimsdk/tools/s3/minio"
@@ -43,6 +44,14 @@ func CheckZookeeper(ctx context.Context, config *config.ZooKeeper) error {
return zookeeper.Check(ctx, config.Address, config.Schema, zookeeper.WithUserNameAndPassword(config.Username, config.Password))
}
+func CheckEtcd(ctx context.Context, config *config.Etcd) error {
+ return etcd.Check(ctx, config.Address, "/check_openim_component",
+ true,
+ etcd.WithDialTimeout(10*time.Second),
+ etcd.WithMaxCallSendMsgSize(20*1024*1024),
+ etcd.WithUsernameAndPassword(config.Username, config.Password))
+}
+
func CheckMongo(ctx context.Context, config *config.Mongo) error {
return mongoutil.Check(ctx, config.Build())
}
@@ -59,14 +68,14 @@ func CheckKafka(ctx context.Context, conf *config.Kafka) error {
return kafka.Check(ctx, conf.Build(), []string{conf.ToMongoTopic, conf.ToRedisTopic, conf.ToPushTopic})
}
-func initConfig(configDir string) (*config.Mongo, *config.Redis, *config.Kafka, *config.Minio, *config.ZooKeeper, error) {
+func initConfig(configDir string) (*config.Mongo, *config.Redis, *config.Kafka, *config.Minio, *config.Discovery, error) {
var (
- mongoConfig = &config.Mongo{}
- redisConfig = &config.Redis{}
- kafkaConfig = &config.Kafka{}
- minioConfig = &config.Minio{}
- zookeeperConfig = &config.ZooKeeper{}
- thirdConfig = &config.Third{}
+ mongoConfig = &config.Mongo{}
+ redisConfig = &config.Redis{}
+ kafkaConfig = &config.Kafka{}
+ minioConfig = &config.Minio{}
+ discovery = &config.Discovery{}
+ thirdConfig = &config.Third{}
)
err := config.LoadConfig(filepath.Join(configDir, cmd.MongodbConfigFileName), cmd.ConfigEnvPrefixMap[cmd.MongodbConfigFileName], mongoConfig)
if err != nil {
@@ -96,11 +105,11 @@ func initConfig(configDir string) (*config.Mongo, *config.Redis, *config.Kafka,
} else {
minioConfig = nil
}
- err = config.LoadConfig(filepath.Join(configDir, cmd.ZookeeperConfigFileName), cmd.ConfigEnvPrefixMap[cmd.ZookeeperConfigFileName], zookeeperConfig)
+ err = config.LoadConfig(filepath.Join(configDir, cmd.DiscoveryConfigFilename), cmd.ConfigEnvPrefixMap[cmd.DiscoveryConfigFilename], discovery)
if err != nil {
return nil, nil, nil, nil, nil, err
}
- return mongoConfig, redisConfig, kafkaConfig, minioConfig, zookeeperConfig, nil
+ return mongoConfig, redisConfig, kafkaConfig, minioConfig, discovery, nil
}
func main() {
@@ -127,35 +136,40 @@ func main() {
}
}
-func performChecks(ctx context.Context, mongoConfig *config.Mongo, redisConfig *config.Redis, kafkaConfig *config.Kafka, minioConfig *config.Minio, zookeeperConfig *config.ZooKeeper, maxRetry int) error {
+func performChecks(ctx context.Context, mongoConfig *config.Mongo, redisConfig *config.Redis, kafkaConfig *config.Kafka, minioConfig *config.Minio, discovery *config.Discovery, maxRetry int) error {
checksDone := make(map[string]bool)
- checks := map[string]func() error{
- "Zookeeper": func() error {
- return CheckZookeeper(ctx, zookeeperConfig)
- },
- "Mongo": func() error {
+ checks := map[string]func(ctx context.Context) error{
+ "Mongo": func(ctx context.Context) error {
return CheckMongo(ctx, mongoConfig)
},
- "Redis": func() error {
+ "Redis": func(ctx context.Context) error {
return CheckRedis(ctx, redisConfig)
},
- "Kafka": func() error {
+ "Kafka": func(ctx context.Context) error {
return CheckKafka(ctx, kafkaConfig)
},
}
-
if minioConfig != nil {
- checks["MinIO"] = func() error {
+ checks["MinIO"] = func(ctx context.Context) error {
return CheckMinIO(ctx, minioConfig)
}
}
+ if discovery.Enable == "etcd" {
+ checks["Etcd"] = func(ctx context.Context) error {
+ return CheckEtcd(ctx, &discovery.Etcd)
+ }
+ } else if discovery.Enable == "zookeeper" {
+ checks["Zookeeper"] = func(ctx context.Context) error {
+ return CheckZookeeper(ctx, &discovery.ZooKeeper)
+ }
+ }
for i := 0; i < maxRetry; i++ {
allSuccess := true
for name, check := range checks {
if !checksDone[name] {
- if err := check(); err != nil {
+ if err := check(ctx); err != nil {
fmt.Printf("%s check failed: %v\n", name, err)
allSuccess = false
} else {
From 2bcc65a24b15768d21796ab7844a0def3f98edd7 Mon Sep 17 00:00:00 2001
From: chao <48119764+withchao@users.noreply.github.com>
Date: Wed, 15 May 2024 11:43:20 +0800
Subject: [PATCH 12/12] fix: s3 config (#2303)
* fix: GroupApplicationAcceptedNotification
* fix: GroupApplicationAcceptedNotification
* fix: NotificationUserInfoUpdate
* cicd: robot automated Change
* fix: component
* fix: getConversationInfo
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* feat: cron task
* fix: minio config url recognition error
* fix: SearchMessage
* fix: s3 config
* fix: oss panic
* kafka
* go.sum
---------
Co-authored-by: withchao
---
config/openim-rpc-third.yml | 17 +----------------
go.mod | 2 +-
go.sum | 4 ++--
3 files changed, 4 insertions(+), 19 deletions(-)
diff --git a/config/openim-rpc-third.yml b/config/openim-rpc-third.yml
index bb41c93ae..bde38ccc4 100644
--- a/config/openim-rpc-third.yml
+++ b/config/openim-rpc-third.yml
@@ -29,19 +29,4 @@ object:
accessKeyID: ''
accessKeySecret: ''
sessionToken: ''
- publicRead: false
- kodo:
- endpoint: "webhook://s3.cn-east-1.qiniucs.com"
- bucket: "demo-9999999"
- bucketURL: "webhook://your.domain.com"
- accessKeyID: ''
- accessKeySecret: ''
- sessionToken: ''
- publicRead: false
- aws:
- endpoint: "''"
- region: "us-east-1"
- bucket: "demo-9999999"
- accessKeyID: ''
- accessKeySecret: ''
- publicRead: false
+ publicRead: false
\ No newline at end of file
diff --git a/go.mod b/go.mod
index e9777eaa8..54e8a8e0e 100644
--- a/go.mod
+++ b/go.mod
@@ -14,7 +14,7 @@ require (
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
github.com/mitchellh/mapstructure v1.5.0
github.com/openimsdk/protocol v0.0.65
- github.com/openimsdk/tools v0.0.49-alpha.18
+ github.com/openimsdk/tools v0.0.49-alpha.19
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0
github.com/stretchr/testify v1.9.0
diff --git a/go.sum b/go.sum
index 3acb4709c..5611a6ca6 100644
--- a/go.sum
+++ b/go.sum
@@ -288,8 +288,8 @@ github.com/openimsdk/gomake v0.0.13 h1:xLDe/moqgWpRoptHzI4packAWzs4C16b+sVY+txNJ
github.com/openimsdk/gomake v0.0.13/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
github.com/openimsdk/protocol v0.0.65 h1:SPT9qyUsFRTTKSKb/FjpS+xr6sxz/Kbnu+su1bxYagc=
github.com/openimsdk/protocol v0.0.65/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
-github.com/openimsdk/tools v0.0.49-alpha.18 h1:ARQeCiRmExvtB6XYItegThuV63JGOTxddwhSLHYXd78=
-github.com/openimsdk/tools v0.0.49-alpha.18/go.mod h1:g7mkHXYUPi0/8aAX8VPMHpnb3hqdV69Jph+bXOGvvNM=
+github.com/openimsdk/tools v0.0.49-alpha.19 h1:CbASL0yefRSVAmWPVeRnhF7wZKd6umLfz31CIhEgrBs=
+github.com/openimsdk/tools v0.0.49-alpha.19/go.mod h1:g7mkHXYUPi0/8aAX8VPMHpnb3hqdV69Jph+bXOGvvNM=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=