From f3318fb1fb2c4ced977f79aeba7d2bd4938d341d Mon Sep 17 00:00:00 2001 From: anatoly32322 Date: Tue, 19 Mar 2024 21:33:11 +0300 Subject: [PATCH] Add CI flow Rename codegeneration.go -> main.go --- .github/workflows/check-codegen.yml | 6 ++++++ CHANGELOG.md | 3 ++- internal/cmd/gstack/{codegeneration.go => main.go} | 13 ++++++++++--- internal/cmd/gstack/utils/utils.go | 3 +++ 4 files changed, 21 insertions(+), 4 deletions(-) rename internal/cmd/gstack/{codegeneration.go => main.go} (98%) diff --git a/.github/workflows/check-codegen.yml b/.github/workflows/check-codegen.yml index 6ef0f1ed1..b7ee4d936 100644 --- a/.github/workflows/check-codegen.yml +++ b/.github/workflows/check-codegen.yml @@ -32,6 +32,7 @@ jobs: - name: Build run: | go install ./internal/cmd/gtrace + go build ./internal/cmd/gstack go install go.uber.org/mock/mockgen@v0.4.0 - name: Clean and re-generate *_gtrace.go files @@ -40,5 +41,10 @@ jobs: go generate ./trace go generate ./... + - name: Re-generate stack.FunctionID calls + run: | + go run ./gstack . + rm ./gstack + - name: Check repository diff run: bash ./.github/scripts/check-work-copy-equals-to-committed.sh "code-generation not equal with committed" diff --git a/CHANGELOG.md b/CHANGELOG.md index d36d2f2dd..9ebfd0b38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ * Added query pool metrics * Fixed logic of query session pool * Changed initialization of internal driver clients to lazy -* Disabled the logic of background grpc-connection parking +* Disabled the logic of background grpc-connection parking +* Added codegarator for filling FunctionID with value from call stack ## v3.58.2 * Added `trace.Query.OnSessionBegin` event diff --git a/internal/cmd/gstack/codegeneration.go b/internal/cmd/gstack/main.go similarity index 98% rename from internal/cmd/gstack/codegeneration.go rename to internal/cmd/gstack/main.go index 9badc7b0f..5f7e287ed 100644 --- a/internal/cmd/gstack/codegeneration.go +++ b/internal/cmd/gstack/main.go @@ -47,6 +47,7 @@ func getCallExpressionsFromExpr(expr ast.Expr) (listOfCalls []*ast.CallExpr) { case *ast.FuncLit: listOfCalls = append(listOfCalls, getListOfCallExpressionsFromBlockStmt(expr.Body)...) } + return listOfCalls } @@ -57,11 +58,10 @@ func getExprFromDeclStmt(statement *ast.DeclStmt) (listOfExpressions []ast.Expr) } for _, spec := range decl.Specs { if spec, ok := spec.(*ast.ValueSpec); ok { - for _, expr := range spec.Values { - listOfExpressions = append(listOfExpressions, expr) - } + listOfExpressions = append(listOfExpressions, spec.Values...) } } + return listOfExpressions } @@ -93,6 +93,7 @@ func getCallExpressionsFromStmt(statement ast.Stmt) (listOfCallExpressions []*as getListOfCallExpressionsFromBlockStmt(body)..., ) } + return listOfCallExpressions } @@ -113,6 +114,7 @@ func getListOfCallExpressionsFromBlockStmt(block *ast.BlockStmt) (listOfCallExpr listOfCallExpressions = append(listOfCallExpressions, getCallExpressionsFromStmt(statement)...) } } + return listOfCallExpressions } @@ -145,8 +147,10 @@ func format(src []byte, fset *token.FileSet, file ast.File) ([]byte, error) { if err != nil { return nil, err } + return fixed, nil } + return src, nil } @@ -157,6 +161,7 @@ func main() { if len(args) != 1 { flag.Usage() + return } _, err := os.Stat(args[0]) @@ -197,8 +202,10 @@ func main() { if err != nil { return err } + return nil } + return nil }) if err != nil { diff --git a/internal/cmd/gstack/utils/utils.go b/internal/cmd/gstack/utils/utils.go index f92176342..a820eefbf 100644 --- a/internal/cmd/gstack/utils/utils.go +++ b/internal/cmd/gstack/utils/utils.go @@ -35,6 +35,7 @@ func ReadFile(filename string, info fs.FileInfo) ([]byte, error) { } else if n > size { return nil, fmt.Errorf("error: size of %s changed during reading (from %d to >=%d bytes)", filename, size, len(src)) } + return src, nil } @@ -48,6 +49,7 @@ func FixSource(src []byte, listOfArgs []FunctionIDArg) ([]byte, error) { previousArgEnd = args.ArgEnd } fixed = append(fixed, src[previousArgEnd:]...) + return fixed, nil } @@ -63,5 +65,6 @@ func WriteFile(filename string, formatted []byte, perm fs.FileMode) error { if err != nil { return err } + return nil }