From 512a63a3683accdcc04af894346158579bbfee46 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Thu, 4 Jul 2024 15:12:14 +0530 Subject: [PATCH 01/10] feat: Async ArgoCd app refresh operation --- Wire.go | 3 + .../argocdServer/ArgoClientWrapperService.go | 28 +++++-- .../argocdServer/application/Application.go | 10 +-- go.mod | 4 +- go.sum | 12 +-- .../devtron-labs/common-lib/async/async.go | 75 +++++++++++++++++++ .../common-lib/constants/constants.go | 11 ++- vendor/modules.txt | 3 +- 8 files changed, 125 insertions(+), 21 deletions(-) create mode 100644 vendor/github.com/devtron-labs/common-lib/async/async.go diff --git a/Wire.go b/Wire.go index 08f44eeab9..09342c3daf 100644 --- a/Wire.go +++ b/Wire.go @@ -21,6 +21,7 @@ package main import ( "github.com/devtron-labs/authenticator/middleware" + "github.com/devtron-labs/common-lib/async" cloudProviderIdentifier "github.com/devtron-labs/common-lib/cloud-provider-identifier" pubsub1 "github.com/devtron-labs/common-lib/pubsub-lib" util4 "github.com/devtron-labs/common-lib/utils/k8s" @@ -229,6 +230,8 @@ func InitializeApp() (*App, error) { wire.Bind(new(router.PProfRouter), new(*router.PProfRouterImpl)), // ---- pprof end ---- + async.NewAsync, // ---- goroutine async wrapper service + sql.NewTransactionUtilImpl, wire.Bind(new(sql.TransactionWrapper), new(*sql.TransactionUtilImpl)), diff --git a/client/argocdServer/ArgoClientWrapperService.go b/client/argocdServer/ArgoClientWrapperService.go index bfc32f0cf9..044afe90de 100644 --- a/client/argocdServer/ArgoClientWrapperService.go +++ b/client/argocdServer/ArgoClientWrapperService.go @@ -24,6 +24,8 @@ import ( repository2 "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" "github.com/caarlos0/env" + "github.com/devtron-labs/common-lib/async" + commonConst "github.com/devtron-labs/common-lib/constants" "github.com/devtron-labs/devtron/client/argocdServer/adapter" "github.com/devtron-labs/devtron/client/argocdServer/application" "github.com/devtron-labs/devtron/client/argocdServer/bean" @@ -102,11 +104,12 @@ type ArgoClientWrapperServiceImpl struct { repositoryService repository.ServiceClient gitOpsConfigReadService config.GitOpsConfigReadService gitOperationService git.GitOperationService + async *async.Async } func NewArgoClientWrapperServiceImpl(logger *zap.SugaredLogger, acdClient application.ServiceClient, ACDConfig *ACDConfig, repositoryService repository.ServiceClient, gitOpsConfigReadService config.GitOpsConfigReadService, - gitOperationService git.GitOperationService) *ArgoClientWrapperServiceImpl { + gitOperationService git.GitOperationService, async *async.Async) *ArgoClientWrapperServiceImpl { return &ArgoClientWrapperServiceImpl{ logger: logger, acdClient: acdClient, @@ -114,13 +117,16 @@ func NewArgoClientWrapperServiceImpl(logger *zap.SugaredLogger, acdClient applic repositoryService: repositoryService, gitOpsConfigReadService: gitOpsConfigReadService, gitOperationService: gitOperationService, + async: async, } } -func (impl *ArgoClientWrapperServiceImpl) GetArgoAppWithNormalRefresh(context context.Context, argoAppName string) error { +func (impl *ArgoClientWrapperServiceImpl) GetArgoAppWithNormalRefresh(ctx context.Context, argoAppName string) error { + newCtx, span := otel.Tracer("orchestrator").Start(ctx, "ArgoClientWrapperServiceImpl.GetArgoAppWithNormalRefresh") + defer span.End() refreshType := bean.RefreshTypeNormal impl.logger.Debugw("trying to normal refresh application through get ", "argoAppName", argoAppName) - _, err := impl.acdClient.Get(context, &application2.ApplicationQuery{Name: &argoAppName, Refresh: &refreshType}) + _, err := impl.acdClient.Get(newCtx, &application2.ApplicationQuery{Name: &argoAppName, Refresh: &refreshType}) if err != nil { internalMsg := fmt.Sprintf("%s, err:- %s", constants.CannotGetAppWithRefreshErrMsg, err.Error()) clientCode, _ := util.GetClientDetailedError(err) @@ -175,10 +181,20 @@ func (impl *ArgoClientWrapperServiceImpl) SyncArgoCDApplicationIfNeededAndRefres } impl.logger.Infow("ArgoCd sync completed", "argoAppName", argoAppName) } - refreshErr := impl.GetArgoAppWithNormalRefresh(newCtx, argoAppName) - if refreshErr != nil { - impl.logger.Errorw("error in refreshing argo app", "err", refreshErr) + + callback := func() { + // running ArgoCd app refresh in asynchronous mode + refreshErr := impl.GetArgoAppWithNormalRefresh(newCtx, argoAppName) + if refreshErr != nil { + impl.logger.Errorw("error in refreshing argo app", "err", refreshErr) + } } + impl.async.Run(callback, + async.RunningMicroService(commonConst.OrchestratorMicroService), + async.RunningInterface("ArgoClientWrapperServiceImpl"), + async.RunningMethod("SyncArgoCDApplicationIfNeededAndRefresh"), + ) + return nil } diff --git a/client/argocdServer/application/Application.go b/client/argocdServer/application/Application.go index 75dd8750c5..b59c3dc269 100644 --- a/client/argocdServer/application/Application.go +++ b/client/argocdServer/application/Application.go @@ -82,17 +82,17 @@ func (c ServiceClientImpl) Patch(ctxt context.Context, query *application.Applic return resp, err } -func (c ServiceClientImpl) Get(ctxt context.Context, query *application.ApplicationQuery) (*v1alpha1.Application, error) { - ctx, cancel := context.WithTimeout(ctxt, argoApplication.TimeoutFast) - defer cancel() - token, ok := ctxt.Value("token").(string) +func (c ServiceClientImpl) Get(ctx context.Context, query *application.ApplicationQuery) (*v1alpha1.Application, error) { + token, ok := ctx.Value("token").(string) if !ok { return nil, errors.New("Unauthorized") } + newCtx, cancel := context.WithTimeout(ctx, argoApplication.TimeoutFast) + defer cancel() conn := c.argoCDConnectionManager.GetConnection(token) defer util.Close(conn, c.logger) asc := application.NewApplicationServiceClient(conn) - resp, err := asc.Get(ctx, query) + resp, err := asc.Get(newCtx, query) return resp, err } diff --git a/go.mod b/go.mod index 91835940e1..46ba893684 100644 --- a/go.mod +++ b/go.mod @@ -17,11 +17,12 @@ require ( github.com/casbin/casbin v1.9.1 github.com/casbin/casbin/v2 v2.97.0 github.com/casbin/xorm-adapter v1.0.1-0.20190716004226-a317737a1007 + github.com/casbin/xorm-adapter/v2 v2.5.1 github.com/coreos/go-oidc v2.2.1+incompatible github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 - github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00 + github.com/devtron-labs/common-lib v0.0.22-0.20240704082255-60727fb3517d github.com/devtron-labs/go-bitbucket v0.9.60-beta github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 github.com/evanphx/json-patch v5.7.0+incompatible @@ -130,7 +131,6 @@ require ( github.com/bombsimon/logrusr/v2 v2.0.1 // indirect github.com/bradleyfalzon/ghinstallation/v2 v2.5.0 // indirect github.com/casbin/govaluate v1.1.0 // indirect - github.com/casbin/xorm-adapter/v2 v2.5.1 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chai2010/gettext-go v1.0.2 // indirect diff --git a/go.sum b/go.sum index d6f609c200..3446ea3114 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,7 @@ cloud.google.com/go/storage v1.30.1 h1:uOdMxAs8HExqBlnLtnQyP0YkvbiDpdGShGKtx6U/o cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7BiccwkR7+P7gN8E= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= github.com/Azure/azure-pipeline-go v0.2.3 h1:7U9HBg1JFK3jHl5qmo4CTZKFTVgMwdFHMVtCdfBE21U= github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k= @@ -191,13 +192,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= -github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADGYw5LqMnHqSkyIELsHCGF6PkrmM31V8rF7o= github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM= +github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzqk8QCaRC4os14xoKDdbHqqlJtJA0oc1ZAjg= github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc= -github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00 h1:xSZulEz0PaTA7tL4Es/uNFUmgjD6oAv8gxJV49GPWHk= -github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= +github.com/devtron-labs/common-lib v0.0.22-0.20240704082255-60727fb3517d h1:JS0kKNMqKAhuuHzPnIDraTrZjoiCibg53cVSo0c3pRA= +github.com/devtron-labs/common-lib v0.0.22-0.20240704082255-60727fb3517d/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM= @@ -317,7 +318,6 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= -github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:9wScpmSP5A3Bk8V3XHWUcJmYTh+ZnlHVyc+A4oZYS3Y= github.com/go-xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:56xuuqnHyryaerycW3BfssRdxQstACi0Epw/yC5E2xM= github.com/go-xorm/xorm v0.7.9 h1:LZze6n1UvRmM5gpL9/U9Gucwqo6aWlFVlfcHKH10qA0= github.com/go-xorm/xorm v0.7.9/go.mod h1:XiVxrMMIhFkwSkh96BW7PACl7UhLtx2iJIHMdmjh5sQ= @@ -331,6 +331,7 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= @@ -593,8 +594,8 @@ github.com/mattn/go-ieproxy v0.0.1 h1:qiyop7gCflfhwCzGyeT0gro3sF9AIg9HU98JORTkqf github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E= github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA= github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= @@ -1303,7 +1304,6 @@ sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= upper.io/db.v3 v3.8.0+incompatible h1:XNeEO2vQRVqq70M98ghzq6M30F5Bzo+99ess5v+eVYw= upper.io/db.v3 v3.8.0+incompatible/go.mod h1:FgTdD24eBjJAbPKsQSiHUNgXjOR4Lub3u1UMHSIh82Y= -xorm.io/builder v0.3.6 h1:ha28mQ2M+TFx96Hxo+iq6tQgnkC9IZkM6D8w9sKHHF8= xorm.io/builder v0.3.6/go.mod h1:LEFAPISnRzG+zxaxj2vPicRwz67BdhFreKg8yv8/TgU= xorm.io/builder v0.3.7 h1:2pETdKRK+2QG4mLX4oODHEhn5Z8j1m8sXa7jfu+/SZI= xorm.io/builder v0.3.7/go.mod h1:aUW0S9eb9VCaPohFCH3j7czOx1PMW3i1HrSzbLYGBSE= diff --git a/vendor/github.com/devtron-labs/common-lib/async/async.go b/vendor/github.com/devtron-labs/common-lib/async/async.go new file mode 100644 index 0000000000..2448502861 --- /dev/null +++ b/vendor/github.com/devtron-labs/common-lib/async/async.go @@ -0,0 +1,75 @@ +package async + +import ( + "fmt" + "github.com/devtron-labs/common-lib/constants" + "github.com/devtron-labs/common-lib/pubsub-lib/metrics" + "go.uber.org/zap" + "log" + "runtime/debug" +) + +type Async struct { + logger *zap.SugaredLogger +} + +type RunAsyncMetaData struct { + MicroServiceName string + InterfaceName string + MethodName string +} + +func NewAsync(logger *zap.SugaredLogger) *Async { + return &Async{ + logger: logger, + } +} + +func NewRunAsyncMetaData() *RunAsyncMetaData { + return &RunAsyncMetaData{} +} + +func RunningMicroService(microServiceName string) NewUpdateMetaData { + return func(m *RunAsyncMetaData) { + m.MicroServiceName = microServiceName + } +} + +func RunningInterface(interfaceName string) NewUpdateMetaData { + return func(m *RunAsyncMetaData) { + m.InterfaceName = interfaceName + } +} + +func RunningMethod(methodName string) NewUpdateMetaData { + return func(m *RunAsyncMetaData) { + m.MethodName = methodName + } +} + +type NewUpdateMetaData func(*RunAsyncMetaData) + +func (impl *Async) Run(fn func(), metadataOpts ...NewUpdateMetaData) { + metaData := NewRunAsyncMetaData() + for _, metadataOpt := range metadataOpts { + // updating meta data + if metadataOpt != nil { + metadataOpt(metaData) + } + } + go func() { + defer func() { + if r := recover(); r != nil { + metrics.IncPanicRecoveryCount("go-routine", metaData.MicroServiceName, metaData.InterfaceName, metaData.MethodName) + if impl.logger == nil { + log.Println(constants.GoRoutinePanicMsgLogPrefix, "go-routine recovered from panic", "err:", r, "stack:", string(debug.Stack())) + } else { + impl.logger.Errorw(fmt.Sprintf("%s %s", constants.GoRoutinePanicMsgLogPrefix, "go-routine recovered from panic"), "err", r, "stack", string(debug.Stack())) + } + } + }() + if fn != nil { + fn() + } + }() +} diff --git a/vendor/github.com/devtron-labs/common-lib/constants/constants.go b/vendor/github.com/devtron-labs/common-lib/constants/constants.go index 7a51abeb85..9dde20bf0d 100644 --- a/vendor/github.com/devtron-labs/common-lib/constants/constants.go +++ b/vendor/github.com/devtron-labs/common-lib/constants/constants.go @@ -16,7 +16,16 @@ package constants -const PanicLogIdentifier = "DEVTRON_PANIC_RECOVER" +const ( + PanicLogIdentifier = "DEVTRON_PANIC_RECOVER" + GoRoutinePanicMsgLogPrefix = "GO_ROUTINE_PANIC_LOG:" +) + +// microservice names constant + +const ( + OrchestratorMicroService = "ORCHESTRATOR" +) // metrics name constants diff --git a/vendor/modules.txt b/vendor/modules.txt index caa4a434af..fd167a9ef0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -402,8 +402,9 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.21-0.20240628105542-603b4f777e00 +# github.com/devtron-labs/common-lib v0.0.22-0.20240704082255-60727fb3517d ## explicit; go 1.21 +github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage github.com/devtron-labs/common-lib/cloud-provider-identifier github.com/devtron-labs/common-lib/cloud-provider-identifier/bean From 15c984c803edfd426bd168e9c42398d101469ac9 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Fri, 5 Jul 2024 14:21:25 +0530 Subject: [PATCH 02/10] feat: updated async wrapper --- Wire.go | 6 ++- WiringNilCheck.go | 10 +--- .../argocdServer/ArgoClientWrapperService.go | 16 ++---- env_gen.md | 3 ++ go.mod | 2 +- go.sum | 4 +- pkg/asyncWrapper/RunAsyncGoFunc.go | 31 ++++++++++++ pkg/asyncWrapper/wire_asyncWrapperSerive.go | 10 ++++ util/reflectUtil/ReflectUtil.go | 24 +++++++++ util/runTimeUtil/GetCallerFrames.go | 50 +++++++++++++++++++ .../devtron-labs/common-lib/async/async.go | 35 ++++++------- .../common-lib/pubsub-lib/JetStreamUtil.go | 19 +++++-- .../common-lib/pubsub-lib/NatsClient.go | 7 ++- .../pubsub-lib/PubSubClientService.go | 25 ++++++++-- .../common-lib/utils/k8s/K8sUtil.go | 9 +--- .../devtron-labs/common-lib/utils/k8s/bean.go | 10 ++++ vendor/modules.txt | 2 +- wire_gen.go | 4 +- 18 files changed, 207 insertions(+), 60 deletions(-) create mode 100644 pkg/asyncWrapper/RunAsyncGoFunc.go create mode 100644 pkg/asyncWrapper/wire_asyncWrapperSerive.go create mode 100644 util/reflectUtil/ReflectUtil.go create mode 100644 util/runTimeUtil/GetCallerFrames.go diff --git a/Wire.go b/Wire.go index 09342c3daf..b9e7b73d98 100644 --- a/Wire.go +++ b/Wire.go @@ -21,7 +21,6 @@ package main import ( "github.com/devtron-labs/authenticator/middleware" - "github.com/devtron-labs/common-lib/async" cloudProviderIdentifier "github.com/devtron-labs/common-lib/cloud-provider-identifier" pubsub1 "github.com/devtron-labs/common-lib/pubsub-lib" util4 "github.com/devtron-labs/common-lib/utils/k8s" @@ -113,6 +112,7 @@ import ( "github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/deploymentTypeChange" "github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/resource" "github.com/devtron-labs/devtron/pkg/appWorkflow" + "github.com/devtron-labs/devtron/pkg/asyncWrapper" "github.com/devtron-labs/devtron/pkg/attributes" "github.com/devtron-labs/devtron/pkg/build" "github.com/devtron-labs/devtron/pkg/bulkAction" @@ -230,7 +230,9 @@ func InitializeApp() (*App, error) { wire.Bind(new(router.PProfRouter), new(*router.PProfRouterImpl)), // ---- pprof end ---- - async.NewAsync, // ---- goroutine async wrapper service + // ---- goroutine async wrapper service start ---- + asyncWrapper.ServiceWire, + // ---- goroutine async wrapper service end ---- sql.NewTransactionUtilImpl, wire.Bind(new(sql.TransactionWrapper), new(*sql.TransactionUtilImpl)), diff --git a/WiringNilCheck.go b/WiringNilCheck.go index 90d719b868..946b154d92 100755 --- a/WiringNilCheck.go +++ b/WiringNilCheck.go @@ -18,6 +18,7 @@ package main import ( "fmt" + "github.com/devtron-labs/devtron/util/reflectUtil" "log" "os" "reflect" @@ -81,14 +82,7 @@ func checkNilFields(obj interface{}, nilObjMap map[string]bool) { } func canFieldTypeBeNil(field reflect.Value) bool { - kind := field.Kind() - switch kind { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.UnsafePointer, - reflect.Interface, reflect.Slice: - return true - default: //other types can not be nil - return false - } + return reflectUtil.IsNullableValue(field) } func canSkipFieldStructCheck(fieldName, valName string) bool { diff --git a/client/argocdServer/ArgoClientWrapperService.go b/client/argocdServer/ArgoClientWrapperService.go index 044afe90de..c12e07ede5 100644 --- a/client/argocdServer/ArgoClientWrapperService.go +++ b/client/argocdServer/ArgoClientWrapperService.go @@ -24,14 +24,13 @@ import ( repository2 "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" "github.com/caarlos0/env" - "github.com/devtron-labs/common-lib/async" - commonConst "github.com/devtron-labs/common-lib/constants" "github.com/devtron-labs/devtron/client/argocdServer/adapter" "github.com/devtron-labs/devtron/client/argocdServer/application" "github.com/devtron-labs/devtron/client/argocdServer/bean" "github.com/devtron-labs/devtron/client/argocdServer/repository" "github.com/devtron-labs/devtron/internal/constants" "github.com/devtron-labs/devtron/internal/util" + "github.com/devtron-labs/devtron/pkg/asyncWrapper" "github.com/devtron-labs/devtron/pkg/deployment/gitOps/config" "github.com/devtron-labs/devtron/pkg/deployment/gitOps/git" "github.com/devtron-labs/devtron/util/retryFunc" @@ -104,12 +103,12 @@ type ArgoClientWrapperServiceImpl struct { repositoryService repository.ServiceClient gitOpsConfigReadService config.GitOpsConfigReadService gitOperationService git.GitOperationService - async *async.Async + asyncGoFuncService asyncWrapper.AsyncGoFuncService } func NewArgoClientWrapperServiceImpl(logger *zap.SugaredLogger, acdClient application.ServiceClient, ACDConfig *ACDConfig, repositoryService repository.ServiceClient, gitOpsConfigReadService config.GitOpsConfigReadService, - gitOperationService git.GitOperationService, async *async.Async) *ArgoClientWrapperServiceImpl { + gitOperationService git.GitOperationService, asyncGoFuncService asyncWrapper.AsyncGoFuncService) *ArgoClientWrapperServiceImpl { return &ArgoClientWrapperServiceImpl{ logger: logger, acdClient: acdClient, @@ -117,7 +116,7 @@ func NewArgoClientWrapperServiceImpl(logger *zap.SugaredLogger, acdClient applic repositoryService: repositoryService, gitOpsConfigReadService: gitOpsConfigReadService, gitOperationService: gitOperationService, - async: async, + asyncGoFuncService: asyncGoFuncService, } } @@ -189,12 +188,7 @@ func (impl *ArgoClientWrapperServiceImpl) SyncArgoCDApplicationIfNeededAndRefres impl.logger.Errorw("error in refreshing argo app", "err", refreshErr) } } - impl.async.Run(callback, - async.RunningMicroService(commonConst.OrchestratorMicroService), - async.RunningInterface("ArgoClientWrapperServiceImpl"), - async.RunningMethod("SyncArgoCDApplicationIfNeededAndRefresh"), - ) - + impl.asyncGoFuncService.Execute(callback) return nil } diff --git a/env_gen.md b/env_gen.md index a91e8b6655..5e35032864 100644 --- a/env_gen.md +++ b/env_gen.md @@ -13,6 +13,8 @@ | ARGO_AUTO_SYNC_ENABLED | true | | | ARGO_GIT_COMMIT_RETRY_COUNT_ON_CONFLICT | 3 | | | ARGO_GIT_COMMIT_RETRY_DELAY_ON_CONFLICT | 1 | | + | ARGO_REPO_REGISTER_RETRY_COUNT | 3 | | + | ARGO_REPO_REGISTER_RETRY_DELAY | 10 | | | AZURE_ACCOUNT_KEY | | | | AZURE_ACCOUNT_NAME | | | | AZURE_BLOB_CONTAINER_CI_CACHE | | | @@ -206,6 +208,7 @@ | PRE_CI_CACHE_PATH | /devtroncd-cache | | | PROPAGATE_EXTRA_LABELS | false | | | PROXY_SERVICE_CONFIG | {} | | + | REPLICAS | 0 | | | REQ_CI_CPU | 0.5 | | | REQ_CI_MEM | 3G | | | RESOURCE_LIST_FOR_REPLICAS | Deployment,Rollout,StatefulSet,ReplicaSet | | diff --git a/go.mod b/go.mod index 46ba893684..b1601ef949 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 - github.com/devtron-labs/common-lib v0.0.22-0.20240704082255-60727fb3517d + github.com/devtron-labs/common-lib v0.0.22-0.20240705084533-b97ee327e9f4 github.com/devtron-labs/go-bitbucket v0.9.60-beta github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 github.com/evanphx/json-patch v5.7.0+incompatible diff --git a/go.sum b/go.sum index 3446ea3114..15acc279f0 100644 --- a/go.sum +++ b/go.sum @@ -197,8 +197,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc= -github.com/devtron-labs/common-lib v0.0.22-0.20240704082255-60727fb3517d h1:JS0kKNMqKAhuuHzPnIDraTrZjoiCibg53cVSo0c3pRA= -github.com/devtron-labs/common-lib v0.0.22-0.20240704082255-60727fb3517d/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= +github.com/devtron-labs/common-lib v0.0.22-0.20240705084533-b97ee327e9f4 h1:LV0tEpI24++rBK1SdbJEd2p/06mphCfYA8BNJjExa5o= +github.com/devtron-labs/common-lib v0.0.22-0.20240705084533-b97ee327e9f4/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM= diff --git a/pkg/asyncWrapper/RunAsyncGoFunc.go b/pkg/asyncWrapper/RunAsyncGoFunc.go new file mode 100644 index 0000000000..be5814e673 --- /dev/null +++ b/pkg/asyncWrapper/RunAsyncGoFunc.go @@ -0,0 +1,31 @@ +package asyncWrapper + +import ( + "fmt" + "github.com/devtron-labs/common-lib/async" + "github.com/devtron-labs/common-lib/constants" + "github.com/devtron-labs/devtron/util/runTimeUtil" + "go.uber.org/zap" +) + +type AsyncGoFuncService interface { + Execute(callback func()) +} + +type AsyncGoFuncServiceImpl struct { + async *async.Async +} + +func NewAsyncGoFuncServiceImpl(logger *zap.SugaredLogger) *AsyncGoFuncServiceImpl { + newAsync := async.NewAsync(logger, constants.OrchestratorMicroService) + return &AsyncGoFuncServiceImpl{ + async: newAsync, + } +} + +func (impl *AsyncGoFuncServiceImpl) Execute(callback func()) { + impl.async.Run(callback, + async.CallerMethod(runTimeUtil.GetCallerFunctionName()), + async.CallerPath(fmt.Sprintf("%s:%d", runTimeUtil.GetCallerFileName(), runTimeUtil.GetCallerLineNumber())), + ) +} diff --git a/pkg/asyncWrapper/wire_asyncWrapperSerive.go b/pkg/asyncWrapper/wire_asyncWrapperSerive.go new file mode 100644 index 0000000000..82c375a69d --- /dev/null +++ b/pkg/asyncWrapper/wire_asyncWrapperSerive.go @@ -0,0 +1,10 @@ +package asyncWrapper + +import ( + "github.com/google/wire" +) + +var ServiceWire = wire.NewSet( + NewAsyncGoFuncServiceImpl, + wire.Bind(new(AsyncGoFuncService), new(*AsyncGoFuncServiceImpl)), +) diff --git a/util/reflectUtil/ReflectUtil.go b/util/reflectUtil/ReflectUtil.go new file mode 100644 index 0000000000..398559c211 --- /dev/null +++ b/util/reflectUtil/ReflectUtil.go @@ -0,0 +1,24 @@ +package reflectUtil + +import "reflect" + +func IsNullableValue(field reflect.Value) bool { + kind := field.Kind() + switch kind { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.UnsafePointer, + reflect.Interface, reflect.Slice: + return true + default: //other types can not be nil + return false + } +} + +func IsPointerType(field reflect.Type) bool { + kind := field.Kind() + switch kind { + case reflect.Pointer: + return true + default: + return false + } +} diff --git a/util/runTimeUtil/GetCallerFrames.go b/util/runTimeUtil/GetCallerFrames.go new file mode 100644 index 0000000000..6bad5ce364 --- /dev/null +++ b/util/runTimeUtil/GetCallerFrames.go @@ -0,0 +1,50 @@ +package runTimeUtil + +import ( + "runtime" +) + +// GetCallerFileName - returns the file name of the invoked func +func GetCallerFileName() string { + // Skip GetCurrentFunctionName + return getFrame(1).File +} + +// GetCallerLineNumber - returns the line number of the invoked func +func GetCallerLineNumber() int { + // Skip GetCurrentFunctionName + return getFrame(1).Line +} + +// GetCallerFunctionName - returns the function name of the invoked func +func GetCallerFunctionName() string { + // Skip GetCallerFunctionName and the function to get the caller of + return getFrame(2).Function +} + +// getFrame returns the runtime.Frame for the targetFrameIndex from the runtime caller stack +// +// examples: +// 1. getFrame(0) -> returns current method frame +// 2. getFrame(1) -> returns caller method frame +// 3. getFrame(2) -> returns caller's caller method frame +func getFrame(targetFrameIndex int) runtime.Frame { + // Set size to targetFrameIndex + 2 to ensure we have room for function runtime.Callers and getFrame + programCounters := make([]uintptr, targetFrameIndex+2) + // We need the frame at index targetFrameIndex + 2, since we never want function runtime.Callers and getFrame + n := runtime.Callers(2, programCounters) + + frame := runtime.Frame{Function: "unknown"} + if n > 0 { + frames := runtime.CallersFrames(programCounters[:n]) + for more, frameIndex := true, 0; more && frameIndex <= targetFrameIndex; frameIndex++ { + var frameCandidate runtime.Frame + frameCandidate, more = frames.Next() + if frameIndex == targetFrameIndex { + frame = frameCandidate + } + } + } + + return frame +} diff --git a/vendor/github.com/devtron-labs/common-lib/async/async.go b/vendor/github.com/devtron-labs/common-lib/async/async.go index 2448502861..09a0365b0c 100644 --- a/vendor/github.com/devtron-labs/common-lib/async/async.go +++ b/vendor/github.com/devtron-labs/common-lib/async/async.go @@ -10,18 +10,25 @@ import ( ) type Async struct { - logger *zap.SugaredLogger + logger *zap.SugaredLogger + microServiceName MicroServiceName +} + +type MicroServiceName string + +func (m MicroServiceName) ToString() string { + return string(m) } type RunAsyncMetaData struct { - MicroServiceName string - InterfaceName string - MethodName string + Method string + Path string } -func NewAsync(logger *zap.SugaredLogger) *Async { +func NewAsync(logger *zap.SugaredLogger, microServiceName MicroServiceName) *Async { return &Async{ - logger: logger, + logger: logger, + microServiceName: microServiceName, } } @@ -29,21 +36,15 @@ func NewRunAsyncMetaData() *RunAsyncMetaData { return &RunAsyncMetaData{} } -func RunningMicroService(microServiceName string) NewUpdateMetaData { - return func(m *RunAsyncMetaData) { - m.MicroServiceName = microServiceName - } -} - -func RunningInterface(interfaceName string) NewUpdateMetaData { +func CallerMethod(methodName string) NewUpdateMetaData { return func(m *RunAsyncMetaData) { - m.InterfaceName = interfaceName + m.Method = methodName } } -func RunningMethod(methodName string) NewUpdateMetaData { +func CallerPath(pathName string) NewUpdateMetaData { return func(m *RunAsyncMetaData) { - m.MethodName = methodName + m.Path = pathName } } @@ -60,7 +61,7 @@ func (impl *Async) Run(fn func(), metadataOpts ...NewUpdateMetaData) { go func() { defer func() { if r := recover(); r != nil { - metrics.IncPanicRecoveryCount("go-routine", metaData.MicroServiceName, metaData.InterfaceName, metaData.MethodName) + metrics.IncPanicRecoveryCount("go-routine", impl.microServiceName.ToString(), metaData.Method, metaData.Path) if impl.logger == nil { log.Println(constants.GoRoutinePanicMsgLogPrefix, "go-routine recovered from panic", "err:", r, "stack:", string(debug.Stack())) } else { diff --git a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/JetStreamUtil.go b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/JetStreamUtil.go index 06c19820fd..a4fb42eefa 100644 --- a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/JetStreamUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/JetStreamUtil.go @@ -323,7 +323,7 @@ func GetStreamSubjects(streamName string) []string { return subjArr } -func AddStream(js nats.JetStreamContext, streamConfig *nats.StreamConfig, streamNames ...string) error { +func AddStream(isClustered bool, js nats.JetStreamContext, streamConfig *nats.StreamConfig, streamNames ...string) error { var err error for _, streamName := range streamNames { streamInfo, err := js.StreamInfo(streamName) @@ -331,6 +331,10 @@ func AddStream(js nats.JetStreamContext, streamConfig *nats.StreamConfig, stream log.Print("No stream was created already. Need to create one. ", "Stream name: ", streamName) // Stream doesn't already exist. Create a new stream from jetStreamContext cfgToSet := getNewConfig(streamName, streamConfig) + if cfgToSet.Replicas > 1 && !isClustered { + cfgToSet.Replicas = 0 + log.Println("replicas > 1 not possible in non clustered mode") + } _, err = js.AddStream(cfgToSet) if err != nil { log.Println("Error while creating stream. ", "stream name: ", streamName, "error: ", err) @@ -342,7 +346,7 @@ func AddStream(js nats.JetStreamContext, streamConfig *nats.StreamConfig, stream } else { config := streamInfo.Config streamConfig.Name = streamName - if checkConfigChangeReqd(&config, streamConfig) { + if checkConfigChangeReqd(&config, streamConfig, isClustered) { _, err1 := js.UpdateStream(&config) if err1 != nil { log.Println("error occurred while updating stream config. ", "streamName: ", streamName, "streamConfig: ", config, "error: ", err1) @@ -353,7 +357,7 @@ func AddStream(js nats.JetStreamContext, streamConfig *nats.StreamConfig, stream return err } -func checkConfigChangeReqd(existingConfig *nats.StreamConfig, toUpdateConfig *nats.StreamConfig) bool { +func checkConfigChangeReqd(existingConfig *nats.StreamConfig, toUpdateConfig *nats.StreamConfig, isClustered bool) bool { configChanged := false newStreamSubjects := GetStreamSubjects(toUpdateConfig.Name) if ((toUpdateConfig.MaxAge != time.Duration(0)) && (toUpdateConfig.MaxAge != existingConfig.MaxAge)) || (len(newStreamSubjects) != len(existingConfig.Subjects)) { @@ -361,7 +365,14 @@ func checkConfigChangeReqd(existingConfig *nats.StreamConfig, toUpdateConfig *na existingConfig.Subjects = newStreamSubjects configChanged = true } - + if replicas := toUpdateConfig.Replicas; replicas > 0 && existingConfig.Replicas != replicas && replicas < 5 { + if replicas > 1 && !isClustered { + log.Println("replicas >1 is not possible in non-clustered mode ") + } else { + existingConfig.Replicas = replicas + configChanged = true + } + } return configChanged } diff --git a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go index 8f80473fef..43bb011cac 100644 --- a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go +++ b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go @@ -48,6 +48,7 @@ type NatsClientConfig struct { NatsMsgBufferSize int `env:"NATS_MSG_BUFFER_SIZE" envDefault:"-1"` NatsMsgMaxAge int `env:"NATS_MSG_MAX_AGE" envDefault:"86400"` NatsMsgAckWaitInSecs int `env:"NATS_MSG_ACK_WAIT_IN_SECS" envDefault:"120"` + Replicas int `env:"REPLICAS" envDefault:"0"` } func (ncc NatsClientConfig) GetNatsMsgBufferSize() int { @@ -63,19 +64,23 @@ func (ncc NatsClientConfig) GetDefaultNatsConsumerConfig() NatsConsumerConfig { NatsMsgProcessingBatchSize: ncc.NatsMsgProcessingBatchSize, NatsMsgBufferSize: ncc.GetNatsMsgBufferSize(), AckWaitInSecs: ncc.NatsMsgAckWaitInSecs, + //Replicas: ncc.Replicas, } } func (ncc NatsClientConfig) GetDefaultNatsStreamConfig() NatsStreamConfig { return NatsStreamConfig{ StreamConfig: StreamConfig{ - MaxAge: time.Duration(ncc.NatsMsgMaxAge) * time.Second, + MaxAge: time.Duration(ncc.NatsMsgMaxAge) * time.Second, + Replicas: ncc.Replicas, }, } } type StreamConfig struct { MaxAge time.Duration `json:"max_age"` + //it will show the instances created for the consumers on a particular subject(topic) + Replicas int `json:"num_replicas"` } type NatsStreamConfig struct { diff --git a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/PubSubClientService.go b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/PubSubClientService.go index fd7c78ab5e..767e0253a3 100644 --- a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/PubSubClientService.go +++ b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/PubSubClientService.go @@ -75,6 +75,11 @@ func NewPubSubClientServiceImpl(logger *zap.SugaredLogger) (*PubSubClientService } return pubSubClient, nil } +func (impl PubSubClientServiceImpl) isClustered() bool { + // This is only ever set, no need for lock here. + clusterInfo := impl.NatsClient.Conn.ConnectedClusterName() + return clusterInfo != "" +} func (impl PubSubClientServiceImpl) ShutDown() error { // Drain the connection, which will close it when done. @@ -99,8 +104,9 @@ func (impl PubSubClientServiceImpl) Publish(topic string, msg string) error { natsTopic := GetNatsTopic(topic) streamName := natsTopic.streamName streamConfig := impl.getStreamConfig(streamName) - // streamConfig := natsClient.streamConfig - _ = AddStream(jetStrCtxt, streamConfig, streamName) + isClustered := impl.isClustered() + _ = AddStream(isClustered, jetStrCtxt, streamConfig, streamName) + // Generate random string for passing as Header Id in message randString := "MsgHeaderId-" + utils.Generate(10) @@ -137,8 +143,8 @@ func (impl PubSubClientServiceImpl) Subscribe(topic string, callback func(msg *m consumerName := natsTopic.consumerName natsClient := impl.NatsClient streamConfig := impl.getStreamConfig(streamName) - // streamConfig := natsClient.streamConfig - _ = AddStream(natsClient.JetStrCtxt, streamConfig, streamName) + isClustered := impl.isClustered() + _ = AddStream(isClustered, natsClient.JetStrCtxt, streamConfig, streamName) deliveryOption := nats.DeliverLast() if streamConfig.Retention == nats.WorkQueuePolicy { deliveryOption = nats.DeliverAll() @@ -153,7 +159,6 @@ func (impl PubSubClientServiceImpl) Subscribe(topic string, callback func(msg *m // Update consumer config if new changes detected impl.updateConsumer(natsClient, streamName, consumerName, &consumerConfig) - channel := make(chan *nats.Msg, msgBufferSize) _, err := natsClient.JetStrCtxt.ChanQueueSubscribe(topic, queueName, channel, nats.Durable(consumerName), @@ -301,6 +306,11 @@ func (impl PubSubClientServiceImpl) updateConsumer(natsClient *NatsClient, strea return } + streamInfo, err := natsClient.JetStrCtxt.StreamInfo(streamName) + if err != nil { + impl.Logger.Errorw("unable to retrieve stream info from NATS-server", "stream", streamName, "consumer", consumerName, "err", err) + return + } existingConfig := info.Config updatesDetected := false @@ -315,6 +325,11 @@ func (impl PubSubClientServiceImpl) updateConsumer(natsClient *NatsClient, strea updatesDetected = true } + if info.Config.Replicas != streamInfo.Config.Replicas { + existingConfig.Replicas = streamInfo.Config.Replicas + updatesDetected = true + } + if updatesDetected { _, err = natsClient.JetStrCtxt.UpdateConsumer(streamName, &existingConfig) if err != nil { diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go index 6568a957b3..4d51abf076 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/K8sUtil.go @@ -165,13 +165,8 @@ func (impl K8sServiceImpl) GetRestConfigByCluster(clusterConfig *ClusterConfig) return nil, err } } else { - restConfig = &rest.Config{Host: clusterConfig.Host, BearerToken: bearerToken, TLSClientConfig: rest.TLSClientConfig{Insecure: clusterConfig.InsecureSkipTLSVerify}} - if clusterConfig.InsecureSkipTLSVerify == false { - restConfig.TLSClientConfig.ServerName = restConfig.ServerName - restConfig.TLSClientConfig.KeyData = []byte(clusterConfig.KeyData) - restConfig.TLSClientConfig.CertData = []byte(clusterConfig.CertData) - restConfig.TLSClientConfig.CAData = []byte(clusterConfig.CAData) - } + restConfig = &rest.Config{Host: clusterConfig.Host, BearerToken: bearerToken} + clusterConfig.PopulateTlsConfigurationsInto(restConfig) } restConfig, err = impl.httpClientConfig.OverrideConfigWithCustomTransport(restConfig) if err != nil { diff --git a/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go b/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go index 85043c9cc1..a12555f9f8 100644 --- a/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/k8s/bean.go @@ -63,6 +63,16 @@ type ClusterConfig struct { RemoteConnectionConfig *bean.RemoteConnectionConfigBean } +func (clusterConfig *ClusterConfig) PopulateTlsConfigurationsInto(restConfig *rest.Config) { + restConfig.TLSClientConfig = rest.TLSClientConfig{Insecure: clusterConfig.InsecureSkipTLSVerify} + if clusterConfig.InsecureSkipTLSVerify == false { + restConfig.TLSClientConfig.ServerName = restConfig.ServerName + restConfig.TLSClientConfig.KeyData = []byte(clusterConfig.KeyData) + restConfig.TLSClientConfig.CertData = []byte(clusterConfig.CertData) + restConfig.TLSClientConfig.CAData = []byte(clusterConfig.CAData) + } +} + type ClusterResourceListMap struct { Headers []string `json:"headers"` Data []map[string]interface{} `json:"data"` diff --git a/vendor/modules.txt b/vendor/modules.txt index fd167a9ef0..b359cbbf17 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -402,7 +402,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.22-0.20240704082255-60727fb3517d +# github.com/devtron-labs/common-lib v0.0.22-0.20240705084533-b97ee327e9f4 ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage diff --git a/wire_gen.go b/wire_gen.go index 7710e02bd3..6d0d394503 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -114,6 +114,7 @@ import ( service3 "github.com/devtron-labs/devtron/pkg/appStore/values/service" appWorkflow2 "github.com/devtron-labs/devtron/pkg/appWorkflow" "github.com/devtron-labs/devtron/pkg/argoApplication" + "github.com/devtron-labs/devtron/pkg/asyncWrapper" "github.com/devtron-labs/devtron/pkg/attributes" "github.com/devtron-labs/devtron/pkg/auth/authentication" "github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin" @@ -579,7 +580,8 @@ func InitializeApp() (*App, error) { pipelineStrategyHistoryServiceImpl := history.NewPipelineStrategyHistoryServiceImpl(sugaredLogger, pipelineStrategyHistoryRepositoryImpl, userServiceImpl) propertiesConfigServiceImpl := pipeline.NewPropertiesConfigServiceImpl(sugaredLogger, envConfigOverrideRepositoryImpl, chartRepositoryImpl, environmentRepositoryImpl, deploymentTemplateHistoryServiceImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl) repositoryServiceClientImpl := repository14.NewServiceClientImpl(sugaredLogger, argoCDConnectionManagerImpl) - argoClientWrapperServiceImpl := argocdServer.NewArgoClientWrapperServiceImpl(sugaredLogger, applicationServiceClientImpl, acdConfig, repositoryServiceClientImpl, gitOpsConfigReadServiceImpl, gitOperationServiceImpl) + asyncGoFuncServiceImpl := asyncWrapper.NewAsyncGoFuncServiceImpl(sugaredLogger) + argoClientWrapperServiceImpl := argocdServer.NewArgoClientWrapperServiceImpl(sugaredLogger, applicationServiceClientImpl, acdConfig, repositoryServiceClientImpl, gitOpsConfigReadServiceImpl, gitOperationServiceImpl, asyncGoFuncServiceImpl) imageDigestPolicyServiceImpl := imageDigestPolicy.NewImageDigestPolicyServiceImpl(sugaredLogger, qualifierMappingServiceImpl, devtronResourceSearchableKeyServiceImpl) pipelineConfigEventPublishServiceImpl := out.NewPipelineConfigEventPublishServiceImpl(sugaredLogger, pubSubClientServiceImpl) deploymentTypeOverrideServiceImpl := providerConfig.NewDeploymentTypeOverrideServiceImpl(sugaredLogger, environmentVariables, attributesServiceImpl) From 878b23cdfdb9427ad92ea1e3b995f4b20768985f Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Fri, 5 Jul 2024 16:56:25 +0530 Subject: [PATCH 03/10] common-lib: beta version --- go.mod | 2 +- go.sum | 4 ++-- vendor/modules.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index b1601ef949..d63aaec620 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 - github.com/devtron-labs/common-lib v0.0.22-0.20240705084533-b97ee327e9f4 + github.com/devtron-labs/common-lib v0.0.22-beta1 github.com/devtron-labs/go-bitbucket v0.9.60-beta github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 github.com/evanphx/json-patch v5.7.0+incompatible diff --git a/go.sum b/go.sum index 15acc279f0..9d06d339cd 100644 --- a/go.sum +++ b/go.sum @@ -197,8 +197,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc= -github.com/devtron-labs/common-lib v0.0.22-0.20240705084533-b97ee327e9f4 h1:LV0tEpI24++rBK1SdbJEd2p/06mphCfYA8BNJjExa5o= -github.com/devtron-labs/common-lib v0.0.22-0.20240705084533-b97ee327e9f4/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= +github.com/devtron-labs/common-lib v0.0.22-beta1 h1:N0o3EVF/I4WIiduJINqGX9KLgBNuvPiwV9aT8CMHOig= +github.com/devtron-labs/common-lib v0.0.22-beta1/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM= diff --git a/vendor/modules.txt b/vendor/modules.txt index b359cbbf17..4d0d04e2a5 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -402,7 +402,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.22-0.20240705084533-b97ee327e9f4 +# github.com/devtron-labs/common-lib v0.0.22-beta1 ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage From fa0a4db032b46b6ef087d74bc8886643a606963c Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Fri, 5 Jul 2024 18:44:03 +0530 Subject: [PATCH 04/10] fix: EA mode build issue --- .../installedApp/service/EAMode/EAModeDeploymentService.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/appStore/installedApp/service/EAMode/EAModeDeploymentService.go b/pkg/appStore/installedApp/service/EAMode/EAModeDeploymentService.go index 4f06ae9ebc..35025a5a41 100644 --- a/pkg/appStore/installedApp/service/EAMode/EAModeDeploymentService.go +++ b/pkg/appStore/installedApp/service/EAMode/EAModeDeploymentService.go @@ -441,3 +441,7 @@ func (impl *EAModeDeploymentServiceImpl) GetChartBytesForParticularDeployment(in func (impl *EAModeDeploymentServiceImpl) DeleteACD(acdAppName string, ctx context.Context, isNonCascade bool) error { return errors.New("this is not implemented") } + +func (impl *EAModeDeploymentServiceImpl) GetAcdAppGitOpsRepoURL(appName string, environmentName string) (string, error) { + return "", errors.New("this is not implemented") +} From 03bdb84d5098d2a0c5e31ef10c99976555648af2 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Mon, 8 Jul 2024 17:24:59 +0530 Subject: [PATCH 05/10] chore: refactoring and renaming --- Wire.go | 4 +-- .../argocdServer/ArgoClientWrapperService.go | 12 +++---- go.mod | 2 +- go.sum | 4 +-- pkg/asyncProvider/AsyncProvider.go | 11 +++++++ pkg/asyncProvider/wire_AsyncProvider.go | 9 ++++++ pkg/asyncWrapper/RunAsyncGoFunc.go | 31 ------------------- pkg/asyncWrapper/wire_asyncWrapperSerive.go | 10 ------ util/reflectUtil/ReflectUtil.go | 10 ------ .../devtron-labs/common-lib/async/async.go | 30 +++++++++++------- .../utils/runTime}/GetCallerFrames.go | 2 +- vendor/modules.txt | 3 +- wire_gen.go | 6 ++-- 13 files changed, 56 insertions(+), 78 deletions(-) create mode 100644 pkg/asyncProvider/AsyncProvider.go create mode 100644 pkg/asyncProvider/wire_AsyncProvider.go delete mode 100644 pkg/asyncWrapper/RunAsyncGoFunc.go delete mode 100644 pkg/asyncWrapper/wire_asyncWrapperSerive.go rename {util/runTimeUtil => vendor/github.com/devtron-labs/common-lib/utils/runTime}/GetCallerFrames.go (98%) diff --git a/Wire.go b/Wire.go index b9e7b73d98..935ddf7021 100644 --- a/Wire.go +++ b/Wire.go @@ -112,7 +112,7 @@ import ( "github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/deploymentTypeChange" "github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/resource" "github.com/devtron-labs/devtron/pkg/appWorkflow" - "github.com/devtron-labs/devtron/pkg/asyncWrapper" + "github.com/devtron-labs/devtron/pkg/asyncProvider" "github.com/devtron-labs/devtron/pkg/attributes" "github.com/devtron-labs/devtron/pkg/build" "github.com/devtron-labs/devtron/pkg/bulkAction" @@ -231,7 +231,7 @@ func InitializeApp() (*App, error) { // ---- pprof end ---- // ---- goroutine async wrapper service start ---- - asyncWrapper.ServiceWire, + asyncProvider.WireSet, // ---- goroutine async wrapper service end ---- sql.NewTransactionUtilImpl, diff --git a/client/argocdServer/ArgoClientWrapperService.go b/client/argocdServer/ArgoClientWrapperService.go index 2240111902..f2eed938e9 100644 --- a/client/argocdServer/ArgoClientWrapperService.go +++ b/client/argocdServer/ArgoClientWrapperService.go @@ -24,13 +24,13 @@ import ( repository2 "github.com/argoproj/argo-cd/v2/pkg/apiclient/repository" "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" "github.com/caarlos0/env" + "github.com/devtron-labs/common-lib/async" "github.com/devtron-labs/devtron/client/argocdServer/adapter" "github.com/devtron-labs/devtron/client/argocdServer/application" "github.com/devtron-labs/devtron/client/argocdServer/bean" "github.com/devtron-labs/devtron/client/argocdServer/repository" "github.com/devtron-labs/devtron/internal/constants" "github.com/devtron-labs/devtron/internal/util" - "github.com/devtron-labs/devtron/pkg/asyncWrapper" "github.com/devtron-labs/devtron/pkg/deployment/gitOps/config" "github.com/devtron-labs/devtron/pkg/deployment/gitOps/git" "github.com/devtron-labs/devtron/util/retryFunc" @@ -105,12 +105,12 @@ type ArgoClientWrapperServiceImpl struct { repositoryService repository.ServiceClient gitOpsConfigReadService config.GitOpsConfigReadService gitOperationService git.GitOperationService - asyncGoFuncService asyncWrapper.AsyncGoFuncService + asyncRunnable *async.Runnable } func NewArgoClientWrapperServiceImpl(logger *zap.SugaredLogger, acdClient application.ServiceClient, ACDConfig *ACDConfig, repositoryService repository.ServiceClient, gitOpsConfigReadService config.GitOpsConfigReadService, - gitOperationService git.GitOperationService, asyncGoFuncService asyncWrapper.AsyncGoFuncService) *ArgoClientWrapperServiceImpl { + gitOperationService git.GitOperationService, asyncRunnable *async.Runnable) *ArgoClientWrapperServiceImpl { return &ArgoClientWrapperServiceImpl{ logger: logger, acdClient: acdClient, @@ -118,7 +118,7 @@ func NewArgoClientWrapperServiceImpl(logger *zap.SugaredLogger, acdClient applic repositoryService: repositoryService, gitOpsConfigReadService: gitOpsConfigReadService, gitOperationService: gitOperationService, - asyncGoFuncService: asyncGoFuncService, + asyncRunnable: asyncRunnable, } } @@ -183,14 +183,14 @@ func (impl *ArgoClientWrapperServiceImpl) SyncArgoCDApplicationIfNeededAndRefres impl.logger.Infow("ArgoCd sync completed", "argoAppName", argoAppName) } - callback := func() { + runnableFunc := func() { // running ArgoCd app refresh in asynchronous mode refreshErr := impl.GetArgoAppWithNormalRefresh(newCtx, argoAppName) if refreshErr != nil { impl.logger.Errorw("error in refreshing argo app", "err", refreshErr) } } - impl.asyncGoFuncService.Execute(callback) + impl.asyncRunnable.Execute(runnableFunc) return nil } diff --git a/go.mod b/go.mod index d63aaec620..ddb3e9a3c4 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 - github.com/devtron-labs/common-lib v0.0.22-beta1 + github.com/devtron-labs/common-lib v0.0.23-0.20240708112813-d9f6c41a4841 github.com/devtron-labs/go-bitbucket v0.9.60-beta github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 github.com/evanphx/json-patch v5.7.0+incompatible diff --git a/go.sum b/go.sum index 9d06d339cd..231e806de1 100644 --- a/go.sum +++ b/go.sum @@ -197,8 +197,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc= -github.com/devtron-labs/common-lib v0.0.22-beta1 h1:N0o3EVF/I4WIiduJINqGX9KLgBNuvPiwV9aT8CMHOig= -github.com/devtron-labs/common-lib v0.0.22-beta1/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= +github.com/devtron-labs/common-lib v0.0.23-0.20240708112813-d9f6c41a4841 h1:noH5YNUMyhZUUnJB+L2Nh1b0csYwXdI0MFfd21+JBnc= +github.com/devtron-labs/common-lib v0.0.23-0.20240708112813-d9f6c41a4841/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM= diff --git a/pkg/asyncProvider/AsyncProvider.go b/pkg/asyncProvider/AsyncProvider.go new file mode 100644 index 0000000000..49b80f12b1 --- /dev/null +++ b/pkg/asyncProvider/AsyncProvider.go @@ -0,0 +1,11 @@ +package asyncProvider + +import ( + "github.com/devtron-labs/common-lib/async" + "github.com/devtron-labs/common-lib/constants" + "go.uber.org/zap" +) + +func NewAsyncRunnable(logger *zap.SugaredLogger) *async.Runnable { + return async.NewAsyncRunnable(logger, constants.OrchestratorMicroService) +} diff --git a/pkg/asyncProvider/wire_AsyncProvider.go b/pkg/asyncProvider/wire_AsyncProvider.go new file mode 100644 index 0000000000..44f68301cf --- /dev/null +++ b/pkg/asyncProvider/wire_AsyncProvider.go @@ -0,0 +1,9 @@ +package asyncProvider + +import ( + "github.com/google/wire" +) + +var WireSet = wire.NewSet( + NewAsyncRunnable, +) diff --git a/pkg/asyncWrapper/RunAsyncGoFunc.go b/pkg/asyncWrapper/RunAsyncGoFunc.go deleted file mode 100644 index be5814e673..0000000000 --- a/pkg/asyncWrapper/RunAsyncGoFunc.go +++ /dev/null @@ -1,31 +0,0 @@ -package asyncWrapper - -import ( - "fmt" - "github.com/devtron-labs/common-lib/async" - "github.com/devtron-labs/common-lib/constants" - "github.com/devtron-labs/devtron/util/runTimeUtil" - "go.uber.org/zap" -) - -type AsyncGoFuncService interface { - Execute(callback func()) -} - -type AsyncGoFuncServiceImpl struct { - async *async.Async -} - -func NewAsyncGoFuncServiceImpl(logger *zap.SugaredLogger) *AsyncGoFuncServiceImpl { - newAsync := async.NewAsync(logger, constants.OrchestratorMicroService) - return &AsyncGoFuncServiceImpl{ - async: newAsync, - } -} - -func (impl *AsyncGoFuncServiceImpl) Execute(callback func()) { - impl.async.Run(callback, - async.CallerMethod(runTimeUtil.GetCallerFunctionName()), - async.CallerPath(fmt.Sprintf("%s:%d", runTimeUtil.GetCallerFileName(), runTimeUtil.GetCallerLineNumber())), - ) -} diff --git a/pkg/asyncWrapper/wire_asyncWrapperSerive.go b/pkg/asyncWrapper/wire_asyncWrapperSerive.go deleted file mode 100644 index 82c375a69d..0000000000 --- a/pkg/asyncWrapper/wire_asyncWrapperSerive.go +++ /dev/null @@ -1,10 +0,0 @@ -package asyncWrapper - -import ( - "github.com/google/wire" -) - -var ServiceWire = wire.NewSet( - NewAsyncGoFuncServiceImpl, - wire.Bind(new(AsyncGoFuncService), new(*AsyncGoFuncServiceImpl)), -) diff --git a/util/reflectUtil/ReflectUtil.go b/util/reflectUtil/ReflectUtil.go index 398559c211..bbb378c49a 100644 --- a/util/reflectUtil/ReflectUtil.go +++ b/util/reflectUtil/ReflectUtil.go @@ -12,13 +12,3 @@ func IsNullableValue(field reflect.Value) bool { return false } } - -func IsPointerType(field reflect.Type) bool { - kind := field.Kind() - switch kind { - case reflect.Pointer: - return true - default: - return false - } -} diff --git a/vendor/github.com/devtron-labs/common-lib/async/async.go b/vendor/github.com/devtron-labs/common-lib/async/async.go index 09a0365b0c..1b783bd9a3 100644 --- a/vendor/github.com/devtron-labs/common-lib/async/async.go +++ b/vendor/github.com/devtron-labs/common-lib/async/async.go @@ -4,19 +4,20 @@ import ( "fmt" "github.com/devtron-labs/common-lib/constants" "github.com/devtron-labs/common-lib/pubsub-lib/metrics" + "github.com/devtron-labs/common-lib/utils/runTime" "go.uber.org/zap" "log" "runtime/debug" ) -type Async struct { - logger *zap.SugaredLogger - microServiceName MicroServiceName +type Runnable struct { + logger *zap.SugaredLogger + serviceName ServiceName } -type MicroServiceName string +type ServiceName string -func (m MicroServiceName) ToString() string { +func (m ServiceName) ToString() string { return string(m) } @@ -25,10 +26,10 @@ type RunAsyncMetaData struct { Path string } -func NewAsync(logger *zap.SugaredLogger, microServiceName MicroServiceName) *Async { - return &Async{ - logger: logger, - microServiceName: microServiceName, +func NewAsyncRunnable(logger *zap.SugaredLogger, serviceName ServiceName) *Runnable { + return &Runnable{ + logger: logger, + serviceName: serviceName, } } @@ -50,7 +51,14 @@ func CallerPath(pathName string) NewUpdateMetaData { type NewUpdateMetaData func(*RunAsyncMetaData) -func (impl *Async) Run(fn func(), metadataOpts ...NewUpdateMetaData) { +func (impl *Runnable) Execute(runnableFunc func()) { + impl.run(runnableFunc, + CallerMethod(runTime.GetCallerFunctionName()), + CallerPath(fmt.Sprintf("%s:%d", runTime.GetCallerFileName(), runTime.GetCallerLineNumber())), + ) +} + +func (impl *Runnable) run(fn func(), metadataOpts ...NewUpdateMetaData) { metaData := NewRunAsyncMetaData() for _, metadataOpt := range metadataOpts { // updating meta data @@ -61,7 +69,7 @@ func (impl *Async) Run(fn func(), metadataOpts ...NewUpdateMetaData) { go func() { defer func() { if r := recover(); r != nil { - metrics.IncPanicRecoveryCount("go-routine", impl.microServiceName.ToString(), metaData.Method, metaData.Path) + metrics.IncPanicRecoveryCount("go-routine", impl.serviceName.ToString(), metaData.Method, metaData.Path) if impl.logger == nil { log.Println(constants.GoRoutinePanicMsgLogPrefix, "go-routine recovered from panic", "err:", r, "stack:", string(debug.Stack())) } else { diff --git a/util/runTimeUtil/GetCallerFrames.go b/vendor/github.com/devtron-labs/common-lib/utils/runTime/GetCallerFrames.go similarity index 98% rename from util/runTimeUtil/GetCallerFrames.go rename to vendor/github.com/devtron-labs/common-lib/utils/runTime/GetCallerFrames.go index 6bad5ce364..ff54cba4a8 100644 --- a/util/runTimeUtil/GetCallerFrames.go +++ b/vendor/github.com/devtron-labs/common-lib/utils/runTime/GetCallerFrames.go @@ -1,4 +1,4 @@ -package runTimeUtil +package runTime import ( "runtime" diff --git a/vendor/modules.txt b/vendor/modules.txt index 4d0d04e2a5..ada95adbca 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -402,7 +402,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.22-beta1 +# github.com/devtron-labs/common-lib v0.0.23-0.20240708112813-d9f6c41a4841 ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage @@ -422,6 +422,7 @@ github.com/devtron-labs/common-lib/utils/k8s/commonBean github.com/devtron-labs/common-lib/utils/k8s/health github.com/devtron-labs/common-lib/utils/k8sObjectsUtil github.com/devtron-labs/common-lib/utils/remoteConnection/bean +github.com/devtron-labs/common-lib/utils/runTime github.com/devtron-labs/common-lib/utils/yaml # github.com/devtron-labs/go-bitbucket v0.9.60-beta ## explicit; go 1.14 diff --git a/wire_gen.go b/wire_gen.go index 6d0d394503..cd4db20995 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -114,7 +114,7 @@ import ( service3 "github.com/devtron-labs/devtron/pkg/appStore/values/service" appWorkflow2 "github.com/devtron-labs/devtron/pkg/appWorkflow" "github.com/devtron-labs/devtron/pkg/argoApplication" - "github.com/devtron-labs/devtron/pkg/asyncWrapper" + "github.com/devtron-labs/devtron/pkg/asyncProvider" "github.com/devtron-labs/devtron/pkg/attributes" "github.com/devtron-labs/devtron/pkg/auth/authentication" "github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin" @@ -580,8 +580,8 @@ func InitializeApp() (*App, error) { pipelineStrategyHistoryServiceImpl := history.NewPipelineStrategyHistoryServiceImpl(sugaredLogger, pipelineStrategyHistoryRepositoryImpl, userServiceImpl) propertiesConfigServiceImpl := pipeline.NewPropertiesConfigServiceImpl(sugaredLogger, envConfigOverrideRepositoryImpl, chartRepositoryImpl, environmentRepositoryImpl, deploymentTemplateHistoryServiceImpl, scopedVariableManagerImpl, deployedAppMetricsServiceImpl) repositoryServiceClientImpl := repository14.NewServiceClientImpl(sugaredLogger, argoCDConnectionManagerImpl) - asyncGoFuncServiceImpl := asyncWrapper.NewAsyncGoFuncServiceImpl(sugaredLogger) - argoClientWrapperServiceImpl := argocdServer.NewArgoClientWrapperServiceImpl(sugaredLogger, applicationServiceClientImpl, acdConfig, repositoryServiceClientImpl, gitOpsConfigReadServiceImpl, gitOperationServiceImpl, asyncGoFuncServiceImpl) + runnable := asyncProvider.NewAsyncRunnable(sugaredLogger) + argoClientWrapperServiceImpl := argocdServer.NewArgoClientWrapperServiceImpl(sugaredLogger, applicationServiceClientImpl, acdConfig, repositoryServiceClientImpl, gitOpsConfigReadServiceImpl, gitOperationServiceImpl, runnable) imageDigestPolicyServiceImpl := imageDigestPolicy.NewImageDigestPolicyServiceImpl(sugaredLogger, qualifierMappingServiceImpl, devtronResourceSearchableKeyServiceImpl) pipelineConfigEventPublishServiceImpl := out.NewPipelineConfigEventPublishServiceImpl(sugaredLogger, pubSubClientServiceImpl) deploymentTypeOverrideServiceImpl := providerConfig.NewDeploymentTypeOverrideServiceImpl(sugaredLogger, environmentVariables, attributesServiceImpl) From f9d7e87b09d4d98d8f5df7d045371f54c8f0d3de Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Mon, 8 Jul 2024 17:34:53 +0530 Subject: [PATCH 06/10] common-lib version --- go.mod | 2 +- go.sum | 4 ++-- .../devtron-labs/common-lib/pubsub-lib/NatsClient.go | 4 ++-- vendor/modules.txt | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index f6668e0815..bd658eebef 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 - github.com/devtron-labs/common-lib v0.0.23-0.20240708112813-d9f6c41a4841 + github.com/devtron-labs/common-lib v0.0.23-beta1 github.com/devtron-labs/go-bitbucket v0.9.60-beta github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 github.com/evanphx/json-patch v5.7.0+incompatible diff --git a/go.sum b/go.sum index 11a58b1969..ed434e4375 100644 --- a/go.sum +++ b/go.sum @@ -197,8 +197,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc= -github.com/devtron-labs/common-lib v0.0.23-0.20240708112813-d9f6c41a4841 h1:noH5YNUMyhZUUnJB+L2Nh1b0csYwXdI0MFfd21+JBnc= -github.com/devtron-labs/common-lib v0.0.23-0.20240708112813-d9f6c41a4841/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= +github.com/devtron-labs/common-lib v0.0.23-beta1 h1:ZpFw4CETqjNpTdUKbE9oOq99s9cdF++cbmXLoJevGcA= +github.com/devtron-labs/common-lib v0.0.23-beta1/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM= diff --git a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go index 43bb011cac..1da3710cd4 100644 --- a/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go +++ b/vendor/github.com/devtron-labs/common-lib/pubsub-lib/NatsClient.go @@ -48,7 +48,7 @@ type NatsClientConfig struct { NatsMsgBufferSize int `env:"NATS_MSG_BUFFER_SIZE" envDefault:"-1"` NatsMsgMaxAge int `env:"NATS_MSG_MAX_AGE" envDefault:"86400"` NatsMsgAckWaitInSecs int `env:"NATS_MSG_ACK_WAIT_IN_SECS" envDefault:"120"` - Replicas int `env:"REPLICAS" envDefault:"0"` + NatsMsgReplicas int `env:"NATS_MSG_REPLICAS" envDefault:"0"` } func (ncc NatsClientConfig) GetNatsMsgBufferSize() int { @@ -72,7 +72,7 @@ func (ncc NatsClientConfig) GetDefaultNatsStreamConfig() NatsStreamConfig { return NatsStreamConfig{ StreamConfig: StreamConfig{ MaxAge: time.Duration(ncc.NatsMsgMaxAge) * time.Second, - Replicas: ncc.Replicas, + Replicas: ncc.NatsMsgReplicas, }, } } diff --git a/vendor/modules.txt b/vendor/modules.txt index b547c6feb7..32b111fee3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -402,7 +402,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.23-0.20240708112813-d9f6c41a4841 +# github.com/devtron-labs/common-lib v0.0.23-beta1 ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage From b5680118d66c5af63b4beff5d852269b1a894df9 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Mon, 8 Jul 2024 19:46:47 +0530 Subject: [PATCH 07/10] chore: updated common-lib version --- env_gen.md | 2 +- go.mod | 2 +- go.sum | 4 ++-- pkg/asyncProvider/AsyncProvider.go | 2 +- .../devtron-labs/common-lib/async/async.go | 17 +++-------------- .../common-lib/constants/constants.go | 10 ++++++++-- vendor/modules.txt | 2 +- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/env_gen.md b/env_gen.md index 7a76a63bc3..e2d802c524 100644 --- a/env_gen.md +++ b/env_gen.md @@ -189,6 +189,7 @@ | NATS_MSG_BUFFER_SIZE | -1 | | | NATS_MSG_MAX_AGE | 86400 | | | NATS_MSG_PROCESSING_BATCH_SIZE | 1 | | + | NATS_MSG_REPLICAS | 0 | | | NATS_SERVER_HOST | nats://devtron-nats.devtroncd:4222 | | | NOTIFICATION_MEDIUM | rest | | | ORCH_HOST | http://devtroncd-orchestrator-service-prod.devtroncd/webhook/msg/nats | | @@ -210,7 +211,6 @@ | PRE_CI_CACHE_PATH | /devtroncd-cache | | | PROPAGATE_EXTRA_LABELS | false | | | PROXY_SERVICE_CONFIG | {} | | - | REPLICAS | 0 | | | REQ_CI_CPU | 0.5 | | | REQ_CI_MEM | 3G | | | RESOURCE_LIST_FOR_REPLICAS | Deployment,Rollout,StatefulSet,ReplicaSet | | diff --git a/go.mod b/go.mod index bd658eebef..00c057847a 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 - github.com/devtron-labs/common-lib v0.0.23-beta1 + github.com/devtron-labs/common-lib v0.0.23-beta2 github.com/devtron-labs/go-bitbucket v0.9.60-beta github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 github.com/evanphx/json-patch v5.7.0+incompatible diff --git a/go.sum b/go.sum index ed434e4375..38cfc603c2 100644 --- a/go.sum +++ b/go.sum @@ -197,8 +197,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc= -github.com/devtron-labs/common-lib v0.0.23-beta1 h1:ZpFw4CETqjNpTdUKbE9oOq99s9cdF++cbmXLoJevGcA= -github.com/devtron-labs/common-lib v0.0.23-beta1/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= +github.com/devtron-labs/common-lib v0.0.23-beta2 h1:wEyNdHVHUm14V6+DC/ct+03O21QJEQqUz6sqJg1XNYs= +github.com/devtron-labs/common-lib v0.0.23-beta2/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM= diff --git a/pkg/asyncProvider/AsyncProvider.go b/pkg/asyncProvider/AsyncProvider.go index 49b80f12b1..f60ed35624 100644 --- a/pkg/asyncProvider/AsyncProvider.go +++ b/pkg/asyncProvider/AsyncProvider.go @@ -7,5 +7,5 @@ import ( ) func NewAsyncRunnable(logger *zap.SugaredLogger) *async.Runnable { - return async.NewAsyncRunnable(logger, constants.OrchestratorMicroService) + return async.NewAsyncRunnable(logger, constants.Orchestrator) } diff --git a/vendor/github.com/devtron-labs/common-lib/async/async.go b/vendor/github.com/devtron-labs/common-lib/async/async.go index 1b783bd9a3..425af98c4b 100644 --- a/vendor/github.com/devtron-labs/common-lib/async/async.go +++ b/vendor/github.com/devtron-labs/common-lib/async/async.go @@ -6,19 +6,12 @@ import ( "github.com/devtron-labs/common-lib/pubsub-lib/metrics" "github.com/devtron-labs/common-lib/utils/runTime" "go.uber.org/zap" - "log" "runtime/debug" ) type Runnable struct { logger *zap.SugaredLogger - serviceName ServiceName -} - -type ServiceName string - -func (m ServiceName) ToString() string { - return string(m) + serviceName constants.ServiceName } type RunAsyncMetaData struct { @@ -26,7 +19,7 @@ type RunAsyncMetaData struct { Path string } -func NewAsyncRunnable(logger *zap.SugaredLogger, serviceName ServiceName) *Runnable { +func NewAsyncRunnable(logger *zap.SugaredLogger, serviceName constants.ServiceName) *Runnable { return &Runnable{ logger: logger, serviceName: serviceName, @@ -70,11 +63,7 @@ func (impl *Runnable) run(fn func(), metadataOpts ...NewUpdateMetaData) { defer func() { if r := recover(); r != nil { metrics.IncPanicRecoveryCount("go-routine", impl.serviceName.ToString(), metaData.Method, metaData.Path) - if impl.logger == nil { - log.Println(constants.GoRoutinePanicMsgLogPrefix, "go-routine recovered from panic", "err:", r, "stack:", string(debug.Stack())) - } else { - impl.logger.Errorw(fmt.Sprintf("%s %s", constants.GoRoutinePanicMsgLogPrefix, "go-routine recovered from panic"), "err", r, "stack", string(debug.Stack())) - } + impl.logger.Errorw(fmt.Sprintf("%s %s", constants.GoRoutinePanicMsgLogPrefix, "go-routine recovered from panic"), "err", r, "stack", string(debug.Stack())) } }() if fn != nil { diff --git a/vendor/github.com/devtron-labs/common-lib/constants/constants.go b/vendor/github.com/devtron-labs/common-lib/constants/constants.go index 9dde20bf0d..9d319c623e 100644 --- a/vendor/github.com/devtron-labs/common-lib/constants/constants.go +++ b/vendor/github.com/devtron-labs/common-lib/constants/constants.go @@ -21,10 +21,16 @@ const ( GoRoutinePanicMsgLogPrefix = "GO_ROUTINE_PANIC_LOG:" ) -// microservice names constant +// service names constant + +type ServiceName string + +func (m ServiceName) ToString() string { + return string(m) +} const ( - OrchestratorMicroService = "ORCHESTRATOR" + Orchestrator ServiceName = "ORCHESTRATOR" ) // metrics name constants diff --git a/vendor/modules.txt b/vendor/modules.txt index 32b111fee3..55d18879f4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -402,7 +402,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.23-beta1 +# github.com/devtron-labs/common-lib v0.0.23-beta2 ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage From 973a992031f6f9e52fcf951749ab8d29fd398dec Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Mon, 8 Jul 2024 23:46:57 +0530 Subject: [PATCH 08/10] chore: updated logging --- client/argocdServer/ArgoClientWrapperService.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/argocdServer/ArgoClientWrapperService.go b/client/argocdServer/ArgoClientWrapperService.go index f2eed938e9..9f41a5fbba 100644 --- a/client/argocdServer/ArgoClientWrapperService.go +++ b/client/argocdServer/ArgoClientWrapperService.go @@ -187,7 +187,7 @@ func (impl *ArgoClientWrapperServiceImpl) SyncArgoCDApplicationIfNeededAndRefres // running ArgoCd app refresh in asynchronous mode refreshErr := impl.GetArgoAppWithNormalRefresh(newCtx, argoAppName) if refreshErr != nil { - impl.logger.Errorw("error in refreshing argo app", "err", refreshErr) + impl.logger.Errorw("error in refreshing argo app", "argoAppName", argoAppName, "err", refreshErr) } } impl.asyncRunnable.Execute(runnableFunc) From 748f4b6b30100cd64fb1ac088ae42205050c4f43 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Fri, 12 Jul 2024 11:34:04 +0530 Subject: [PATCH 09/10] chore: updated common-lib version --- go.mod | 2 +- go.sum | 4 ++-- vendor/modules.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 00c057847a..aed3a9b10c 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 - github.com/devtron-labs/common-lib v0.0.23-beta2 + github.com/devtron-labs/common-lib v0.0.23 github.com/devtron-labs/go-bitbucket v0.9.60-beta github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 github.com/evanphx/json-patch v5.7.0+incompatible diff --git a/go.sum b/go.sum index 38cfc603c2..d48259a015 100644 --- a/go.sum +++ b/go.sum @@ -197,8 +197,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1 h1:qdkpTAo2Kr0ZicZIVXfNwsGSshpc9OB9j9RzmKYdIwY= github.com/devtron-labs/authenticator v0.4.35-0.20240607135426-c86e868ecee1/go.mod h1:IkKPPEfgLCMR29he5yv2OCC6iM2R7K5/0AA3k8b9XNc= -github.com/devtron-labs/common-lib v0.0.23-beta2 h1:wEyNdHVHUm14V6+DC/ct+03O21QJEQqUz6sqJg1XNYs= -github.com/devtron-labs/common-lib v0.0.23-beta2/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= +github.com/devtron-labs/common-lib v0.0.23 h1:3n9VgJALanjHrb/t0nSaLbLJcJa7sdsdyFf2leE+cN0= +github.com/devtron-labs/common-lib v0.0.23/go.mod h1:UZGPt1ep9Tnd9Ak2sibGSiLr7p3ijO2/JLT+h+pqBuU= github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU= github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y= github.com/devtron-labs/protos v0.0.3-0.20240527113333-08a3be5ec6c1 h1:R6qVeFaayqstBSu4w+ipWQqJyMKDqBVV3a11qoA2IaM= diff --git a/vendor/modules.txt b/vendor/modules.txt index 55d18879f4..337f2ab91b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -402,7 +402,7 @@ github.com/devtron-labs/authenticator/jwt github.com/devtron-labs/authenticator/middleware github.com/devtron-labs/authenticator/oidc github.com/devtron-labs/authenticator/password -# github.com/devtron-labs/common-lib v0.0.23-beta2 +# github.com/devtron-labs/common-lib v0.0.23 ## explicit; go 1.21 github.com/devtron-labs/common-lib/async github.com/devtron-labs/common-lib/blob-storage From 2a7bf546c97f076de01975c7a0bf15849c924553 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Fri, 12 Jul 2024 12:51:44 +0530 Subject: [PATCH 10/10] fix: gorountine context handling --- client/argocdServer/ArgoClientWrapperService.go | 2 +- pkg/deployment/trigger/devtronApps/TriggerService.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/argocdServer/ArgoClientWrapperService.go b/client/argocdServer/ArgoClientWrapperService.go index 9f41a5fbba..8e78a0c1cf 100644 --- a/client/argocdServer/ArgoClientWrapperService.go +++ b/client/argocdServer/ArgoClientWrapperService.go @@ -185,7 +185,7 @@ func (impl *ArgoClientWrapperServiceImpl) SyncArgoCDApplicationIfNeededAndRefres runnableFunc := func() { // running ArgoCd app refresh in asynchronous mode - refreshErr := impl.GetArgoAppWithNormalRefresh(newCtx, argoAppName) + refreshErr := impl.GetArgoAppWithNormalRefresh(context.Background(), argoAppName) if refreshErr != nil { impl.logger.Errorw("error in refreshing argo app", "argoAppName", argoAppName, "err", refreshErr) } diff --git a/pkg/deployment/trigger/devtronApps/TriggerService.go b/pkg/deployment/trigger/devtronApps/TriggerService.go index 12f5ad20f7..a662305f07 100644 --- a/pkg/deployment/trigger/devtronApps/TriggerService.go +++ b/pkg/deployment/trigger/devtronApps/TriggerService.go @@ -1170,7 +1170,7 @@ func (impl *TriggerServiceImpl) updateArgoPipeline(ctx context.Context, pipeline impl.logger.Infow("received payload, updateArgoPipeline", "appId", pipeline.AppId, "pipelineName", pipeline.Name, "envId", envOverride.TargetEnvironment, "argoAppName", argoAppName) argoApplication, err := impl.argoClientWrapperService.GetArgoAppByName(newCtx, argoAppName) if err != nil { - impl.logger.Errorw("no argo app exists", "app", argoAppName, "pipeline", pipeline.Name) + impl.logger.Errorw("unable to get ArgoCd app", "app", argoAppName, "pipeline", pipeline.Name, "err", err) return false, err } //if status, ok:=status.FromError(err);ok{