feat(main): 🚀 Database Name Correction and S3 Module Int32 Overflow Fix with Go Routine Integration for Automated Checks and Script Optimization (#1799)

* feat: replace mongo database openIM_v3 to openim_v3

* openim-building-an-efficient-version-control-and-testing-workflow

* feat: complete openim source deployment rpc start timeout

* feat: optimize config

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>

* feat: add scripts format

* feat: use scripts format code

* fix cos and minio etc to typecheck

* feat: scripts make verify check ci

* fix: make file verify spelling

* fix: make file verify spelling

* Concurrent Type Checking and Cross-Platform Development in Go

* feat: add copyright make lint and format

* feat: add config examples file

Signed-off-by: Xinwei Xiong <3293172751@qq.com>

* feat: add config examples file

Signed-off-by: Xinwei Xiong <3293172751@qq.com>

---------

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
Signed-off-by: Xinwei Xiong <3293172751@qq.com>
This commit is contained in:
Xinwei Xiong
2024-01-26 10:02:53 +08:00
committed by GitHub
parent fa55c44113
commit d356f7a035
107 changed files with 3056 additions and 3869 deletions
+43 -18
View File
@@ -1,27 +1,52 @@
# OpenIM Typecheck
# OpenIM Typecheck: Cross-Platform Source Code Type Checking for Go
OpenIM Typecheck 为所有 Go 构建平台进行跨平台源代码类型检查。
## Introduction
## 优点
OpenIM Typecheck is a robust tool designed for cross-platform source code type checking across all Go build platforms. This utility leverages Gos built-in parsing and type-check libraries (`go/parser` and `go/types`) to deliver efficient and reliable code analysis.
- **速度**:OpenIM 完整编译大约需要 3 分钟,而使用 Typecheck 只需数秒。
- **资源消耗**:与需要 >40GB 的 RAM 不同,Typecheck 只需 <8GB 的 RAM。
## Advantages
## 实现
- **Speed**: A complete compilation with OpenIM can take approximately 3 minutes. In contrast, OpenIM Typecheck achieves this in mere seconds, significantly enhancing productivity.
- **Resource Efficiency**: Unlike the typical requirement of over 40GB of RAM for standard processes, Typecheck operates effectively with less than 8GB of RAM. This reduction in resource consumption makes it highly suitable for a variety of systems, reducing overheads and facilitating smoother operations.
OpenIM Typecheck 使用 Go 内置的解析和类型检查库 (`go/parser``go/types`)。然而,这些库并不是 go 编译器所使用的。偶尔会出现不匹配的情况,但总的来说,它们是相当接近的。
## Implementation
## 错误处理
OpenIM Typecheck employs Go's native parsing and type-checking libraries (`go/parser` and `go/types`). However, it's important to note that these libraries aren't identical to those used by the Go compiler. While occasional mismatches may occur, these libraries generally provide close approximations to the compiler's functionality, offering a reliable basis for type checking.
如果错误不会阻止构建,可以忽略。
## Error Handling
**`go/types` 报告的错误,但 `go build` 不会**
- **真正的错误**(根据规范):
- 应尽量修复。如果无法修复或正在进行中(例如,已被外部引用的代码),则可以忽略。
- 例如:闭包中的未使用变量
- **不真实的错误**
- 应忽略并在适当的情况下向上游报告。
- 例如:staging 和 generated 类型之间的类型检查不匹配
Typecheck's approach to error handling is pragmatic, focusing on practicality and build continuity.
**`go build` 报告的错误,但我们不会**
- CGo 错误,包括语法和链接器错误。
**Errors reported by `go/types` but not by `go build`**:
- **Actual Errors** (as per the specification):
- These should ideally be rectified. If rectification is not feasible, such as in cases of ongoing work or external dependencies in the code, these errors can be overlooked.
- Example: Unused variables within a closure.
- **False Positives**:
- These errors should be ignored and, where appropriate, reported upstream for resolution.
- Example: Type mismatches between staging and generated types.
**Errors reported by `go build` but not by us**:
- CGo-related errors, including both syntax and linker issues, are outside our scope.
## Usage
### Locally
To run Typecheck locally, simply use the following command:
```bash
make verify
```
### Continuous Integration (CI)
In CI environments, Typecheck can be integrated into the workflow as follows:
```yaml
- name: Typecheck
run: make verify
```
This streamlined process facilitates efficient error detection and resolution, ensuring a robust and reliable build pipeline.
More to learn about typecheck [share blog](https://nsddd.top/posts/concurrent-type-checking-and-cross-platform-development-in-go/)
+5 -10
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// do a fast type check of kubernetes code, for all platforms.
// do a fast type check of openim code, for all platforms.
package main
import (
@@ -47,14 +47,12 @@ var (
crossPlatforms = []string{
"linux/amd64", "windows/386",
"darwin/amd64", "darwin/arm64",
"linux/386",
"linux/386", "linux/arm",
"windows/amd64", "linux/arm64",
"linux/ppc64le", "linux/s390x",
"windows/arm64",
}
// "linux/arm",
// directories we always ignore
standardIgnoreDirs = []string{
// Staging code is symlinked from vendor/k8s.io, and uses import
@@ -62,17 +60,14 @@ var (
// inside of staging/, but works when typechecked as part of vendor/.
"staging",
"components",
"logs",
// OS-specific vendor code tends to be imported by OS-specific
// packages. We recursively typecheck imported vendored packages for
// each OS, but don't typecheck everything for every OS.
"vendor",
"test",
"_output",
"OpenIMSKD/tools",
// This is a weird one. /testdata/ is *mostly* ignored by Go,
// and this translates to kubernetes/vendor not working.
// edit/record.go doesn't compile without gopkg.in/yaml.v2
// in $GOSRC/$GOROOT (both typecheck and the shell script).
"pkg/kubectl/cmd/testdata/edit",
"*/mw/rpc_server_interceptor.go",
// Tools we use for maintaining the code base but not necessarily
// ship as part of the release
"sopenim::golang::setup_env:tools/yamlfmt/yamlfmt.go:tools",
+7 -6
View File
@@ -34,7 +34,7 @@ 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`))
threads=$((3 * $(grep -c processor /proc/cpuinfo)))
source "${openim_root}/scripts/lib/color.sh"
@@ -122,7 +122,7 @@ if (s ~ "s") {
# Remove existing data file
function openim::wrk::prepare() {
rm -f ${wrkdir}/${datfile}
rm -f "${wrkdir}"/"${datfile}"
}
# Plot according to gunplot data file
@@ -216,7 +216,7 @@ openim::wrk::start_performance_test() {
do
wrkcmd="${cmd} -c ${c} $1"
echo "Running wrk command: ${wrkcmd}"
result=`eval ${wrkcmd}`
result=$(eval "${wrkcmd}")
openim::wrk::convert_plot_data "${result}"
done
@@ -241,9 +241,10 @@ while getopts "hd:n:" opt;do
esac
done
shift $(($OPTIND-1))
shift $((OPTIND-1))
mkdir -p "${wrkdir}"
mkdir -p ${wrkdir}
case $1 in
"diff")
if [ "$#" -lt 3 ];then
@@ -255,7 +256,7 @@ case $1 in
t2=$(basename $3|sed 's/.dat//g') # 对比图中粉色线条名称
join $2 $3 > /tmp/plot_diff.dat
openim::wrk::plot_diff `basename $2` `basename $3`
openim::wrk::plot_diff "$(basename "$2")" "$(basename "$3")"
exit 0
;;
*)