From 922c07653942551d7f779307c7b5531f9d7c91b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Tue, 30 Jun 2020 09:16:10 +0200 Subject: [PATCH] feat(api): improve tracing (#5286) Signed-off-by: francois samin --- engine/api/action.go | 2 +- engine/api/api_routes.go | 2 +- engine/api/application.go | 12 +++--- engine/api/application_deployment.go | 4 +- engine/api/application_import.go | 2 +- engine/api/ascode.go | 6 +-- engine/api/ascode_test.go | 2 +- engine/api/broadcast.go | 4 +- engine/api/environment.go | 12 +++--- engine/api/environment_import.go | 4 +- engine/api/hook.go | 2 +- engine/api/observability/helper.go | 4 +- engine/api/pipeline.go | 12 +++--- engine/api/pipeline/pipeline_importer_test.go | 2 +- engine/api/pipeline_import.go | 4 +- engine/api/pipeline_job.go | 4 +- engine/api/pipeline_stage_test.go | 2 +- engine/api/project.go | 12 +++--- engine/api/project/dao.go | 27 +++++++++---- engine/api/project_group.go | 8 ++-- engine/api/project_integration.go | 8 ++-- engine/api/project_key.go | 6 +-- engine/api/project_variable.go | 14 +++---- engine/api/repositories_manager.go | 18 ++++----- .../api/router_middleware_auth_permission.go | 2 +- engine/api/suggest.go | 2 +- engine/api/templates.go | 4 +- engine/api/test/assets/assets.go | 2 +- engine/api/user_bookmark.go | 2 +- engine/api/worker_model.go | 2 +- engine/api/workflow.go | 22 +++++----- engine/api/workflow/dao.go | 8 ++++ engine/api/workflow/workflow_exporter_test.go | 2 +- engine/api/workflow/workflow_importer_test.go | 2 +- engine/api/workflow/workflow_parser_test.go | 4 +- engine/api/workflow_application.go | 2 +- engine/api/workflow_ascode.go | 2 +- engine/api/workflow_ascode_test.go | 4 +- engine/api/workflow_export.go | 4 +- engine/api/workflow_export_test.go | 6 +-- engine/api/workflow_group.go | 6 +-- engine/api/workflow_group_test.go | 14 +++---- engine/api/workflow_hook.go | 4 +- engine/api/workflow_import.go | 8 ++-- engine/api/workflow_import_test.go | 4 +- engine/api/workflow_queue_test.go | 8 ++-- engine/api/workflow_run.go | 22 +++++----- engine/api/workflow_run_test.go | 40 +++++++++---------- engine/api/workflow_test.go | 8 ++-- engine/api/workflow_trigger.go | 2 +- 50 files changed, 190 insertions(+), 169 deletions(-) diff --git a/engine/api/action.go b/engine/api/action.go index 24bbf5516c..a11c44b550 100644 --- a/engine/api/action.go +++ b/engine/api/action.go @@ -55,7 +55,7 @@ func (api *API) getActionsForProjectHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithGroups) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithGroups) if err != nil { return sdk.WrapError(err, "unable to load projet %s", key) } diff --git a/engine/api/api_routes.go b/engine/api/api_routes.go index 5b72518c74..1e0ee1cbd8 100644 --- a/engine/api/api_routes.go +++ b/engine/api/api_routes.go @@ -24,7 +24,7 @@ var ( func (api *API) InitRouter() { api.Router.URL = api.Config.URL.API api.Router.SetHeaderFunc = DefaultHeaders - api.Router.Middlewares = append(api.Router.Middlewares, api.authMiddleware, api.tracingMiddleware, api.maintenanceMiddleware) + api.Router.Middlewares = append(api.Router.Middlewares, api.tracingMiddleware, api.authMiddleware, api.maintenanceMiddleware) api.Router.PostMiddlewares = append(api.Router.PostMiddlewares, TracingPostMiddleware) r := api.Router diff --git a/engine/api/application.go b/engine/api/application.go index 5e1d175581..af85c4df12 100644 --- a/engine/api/application.go +++ b/engine/api/application.go @@ -151,7 +151,7 @@ func (api *API) getApplicationHandler() service.Handler { } if app.FromRepository != "" { - proj, err := project.Load(api.mustDB(), projectKey, + proj, err := project.Load(ctx, api.mustDB(), projectKey, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, @@ -255,7 +255,7 @@ func (api *API) addApplicationHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - proj, errl := project.Load(api.mustDB(), key) + proj, errl := project.Load(ctx, api.mustDB(), key) if errl != nil { return sdk.WrapError(errl, "addApplicationHandler> Cannot load %s", key) } @@ -299,7 +299,7 @@ func (api *API) deleteApplicationHandler() service.Handler { projectKey := vars[permProjectKey] applicationName := vars["applicationName"] - proj, errP := project.Load(api.mustDB(), projectKey) + proj, errP := project.Load(ctx, api.mustDB(), projectKey) if errP != nil { return sdk.WrapError(errP, "deleteApplicationHandler> Cannot laod project") } @@ -337,7 +337,7 @@ func (api *API) cloneApplicationHandler() service.Handler { projectKey := vars[permProjectKey] applicationName := vars["applicationName"] - proj, errProj := project.Load(api.mustDB(), projectKey) + proj, errProj := project.Load(ctx, api.mustDB(), projectKey) if errProj != nil { return sdk.WrapError(sdk.ErrNoProject, "cloneApplicationHandler> Cannot load %s", projectKey) } @@ -441,7 +441,7 @@ func (api *API) updateAsCodeApplicationHandler() service.Handler { return sdk.WrapError(sdk.ErrInvalidApplicationPattern, "Application name %s do not respect pattern", a.Name) } - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithClearKeys) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithClearKeys) if err != nil { return err } @@ -527,7 +527,7 @@ func (api *API) updateApplicationHandler() service.Handler { projectKey := vars[permProjectKey] applicationName := vars["applicationName"] - p, err := project.Load(api.mustDB(), projectKey, project.LoadOptions.Default) + p, err := project.Load(ctx, api.mustDB(), projectKey, project.LoadOptions.Default) if err != nil { return sdk.WrapError(err, "cannot load project %s", projectKey) } diff --git a/engine/api/application_deployment.go b/engine/api/application_deployment.go index 38e713f685..290e43e336 100644 --- a/engine/api/application_deployment.go +++ b/engine/api/application_deployment.go @@ -47,7 +47,7 @@ func (api *API) postApplicationDeploymentStrategyConfigHandler() service.Handler } defer tx.Rollback() // nolint - proj, err := project.Load(tx, key, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, tx, key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load project") } @@ -116,7 +116,7 @@ func (api *API) deleteApplicationDeploymentStrategyConfigHandler() service.Handl } defer tx.Rollback() // nolint - proj, err := project.Load(tx, key, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, tx, key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load project") } diff --git a/engine/api/application_import.go b/engine/api/application_import.go index 921e780464..a808c6576b 100644 --- a/engine/api/application_import.go +++ b/engine/api/application_import.go @@ -25,7 +25,7 @@ func (api *API) postApplicationImportHandler() service.Handler { key := vars[permProjectKey] force := FormBool(r, "force") - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable load project") } diff --git a/engine/api/ascode.go b/engine/api/ascode.go index 6ce9cd8696..4a0a63f472 100644 --- a/engine/api/ascode.go +++ b/engine/api/ascode.go @@ -47,7 +47,7 @@ func (api *API) postImportAsCodeHandler() service.Handler { return sdk.WithStack(sdk.ErrWrongRequest) } - p, err := project.Load(api.mustDB(), key, project.LoadOptions.WithClearKeys) + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithClearKeys) if err != nil { return sdk.WrapError(err, "cannot load project") } @@ -113,7 +113,7 @@ func (api *API) postPerformImportAsCodeHandler() service.Handler { uuid := vars["uuid"] //Load project - proj, errp := project.Load(api.mustDB(), key, + proj, errp := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithGroups, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, @@ -215,7 +215,7 @@ func (api *API) postWorkflowAsCodeEventsResyncHandler() service.Handler { projectKey := vars["key"] workflowName := vars["permWorkflowName"] - proj, err := project.Load(api.mustDB(), projectKey, + proj, err := project.Load(ctx, api.mustDB(), projectKey, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, diff --git a/engine/api/ascode_test.go b/engine/api/ascode_test.go index aa366325ef..63f5ddc4c4 100644 --- a/engine/api/ascode_test.go +++ b/engine/api/ascode_test.go @@ -399,7 +399,7 @@ vcs_ssh_key: proj-blabla }, }, } - proj2, errP := project.Load(api.mustDB(), p.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), p.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), db, api.Cache, *proj2, &wf)) diff --git a/engine/api/broadcast.go b/engine/api/broadcast.go index 15dbacf3a4..3cb3724d1f 100644 --- a/engine/api/broadcast.go +++ b/engine/api/broadcast.go @@ -27,7 +27,7 @@ func (api *API) addBroadcastHandler() service.Handler { bc.Updated = now if bc.ProjectKey != "" { - proj, errProj := project.Load(api.mustDB(), bc.ProjectKey) + proj, errProj := project.Load(ctx, api.mustDB(), bc.ProjectKey) if errProj != nil { return sdk.WrapError(sdk.ErrNoProject, "Cannot load %s", bc.ProjectKey) } @@ -63,7 +63,7 @@ func (api *API) updateBroadcastHandler() service.Handler { } if bc.ProjectKey != "" { - proj, errProj := project.Load(api.mustDB(), bc.ProjectKey) + proj, errProj := project.Load(ctx, api.mustDB(), bc.ProjectKey) if errProj != nil { return sdk.WrapError(sdk.ErrNoProject, "Cannot load %s", bc.ProjectKey) } diff --git a/engine/api/environment.go b/engine/api/environment.go index fa9e601d7e..0a69fa55e9 100644 --- a/engine/api/environment.go +++ b/engine/api/environment.go @@ -80,7 +80,7 @@ func (api *API) getEnvironmentHandler() service.Handler { } if env.FromRepository != "" { - proj, err := project.Load(api.mustDB(), projectKey, + proj, err := project.Load(ctx, api.mustDB(), projectKey, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, @@ -141,7 +141,7 @@ func (api *API) addEnvironmentHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - proj, errProj := project.Load(api.mustDB(), key, project.LoadOptions.Default) + proj, errProj := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default) if errProj != nil { return sdk.WrapError(errProj, "addEnvironmentHandler> Cannot load %s", key) } @@ -186,7 +186,7 @@ func (api *API) deleteEnvironmentHandler() service.Handler { projectKey := vars[permProjectKey] environmentName := vars["environmentName"] - p, errProj := project.Load(api.mustDB(), projectKey, project.LoadOptions.Default) + p, errProj := project.Load(ctx, api.mustDB(), projectKey, project.LoadOptions.Default) if errProj != nil { return sdk.WrapError(errProj, "deleteEnvironmentHandler> Cannot load project %s", projectKey) } @@ -249,7 +249,7 @@ func (api *API) updateAsCodeEnvironmentHandler() service.Handler { return sdk.WrapError(sdk.ErrInvalidApplicationPattern, "Environment name %s do not respect pattern", env.Name) } - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithClearKeys) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithClearKeys) if err != nil { return err } @@ -345,7 +345,7 @@ func (api *API) updateEnvironmentHandler() service.Handler { return sdk.WithStack(sdk.ErrForbidden) } - p, errProj := project.Load(api.mustDB(), projectKey) + p, errProj := project.Load(ctx, api.mustDB(), projectKey) if errProj != nil { return sdk.WrapError(errProj, "updateEnvironmentHandler> Cannot load project %s", projectKey) } @@ -396,7 +396,7 @@ func (api *API) cloneEnvironmentHandler() service.Handler { return sdk.WrapError(err, "cannot load environment %s", environmentName) } - p, err := project.Load(api.mustDB(), projectKey) + p, err := project.Load(ctx, api.mustDB(), projectKey) if err != nil { return sdk.WrapError(err, "cannot load project %s", projectKey) } diff --git a/engine/api/environment_import.go b/engine/api/environment_import.go index b1aa9bd532..7c362d6369 100644 --- a/engine/api/environment_import.go +++ b/engine/api/environment_import.go @@ -27,7 +27,7 @@ func (api *API) postEnvironmentImportHandler() service.Handler { key := vars[permProjectKey] force := FormBool(r, "force") - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithGroups) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithGroups) if err != nil { return sdk.WrapError(err, "unable load project") } @@ -82,7 +82,7 @@ func (api *API) importNewEnvironmentHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.Default, + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default, project.LoadOptions.WithGroups, project.LoadOptions.WithPermission) if err != nil { return sdk.WrapError(err, "cannot load %s", key) diff --git a/engine/api/hook.go b/engine/api/hook.go index 1b2b0c3a3c..afa22eae7e 100644 --- a/engine/api/hook.go +++ b/engine/api/hook.go @@ -39,7 +39,7 @@ func (api *API) getHookPollingVCSEvents() service.Handler { return err } - proj, err := project.Load(api.mustDB(), h.Config[sdk.HookConfigProject].Value, nil) + proj, err := project.Load(ctx, api.mustDB(), h.Config[sdk.HookConfigProject].Value, nil) if err != nil { return err } diff --git a/engine/api/observability/helper.go b/engine/api/observability/helper.go index 903d5e658a..a32162c5d1 100644 --- a/engine/api/observability/helper.go +++ b/engine/api/observability/helper.go @@ -107,7 +107,7 @@ func ContextGetTags(ctx context.Context, s ...string) []tag.Mutator { // Span start a new span from the parent context func Span(ctx context.Context, name string, tags ...trace.Attribute) (context.Context, func()) { - // log.Debug("# %s - begin", name) + log.Debug("# %s - begin", name) if ctx == nil { return context.Background(), func() {} } @@ -118,7 +118,7 @@ func Span(ctx context.Context, name string, tags ...trace.Attribute) (context.Co } ctx = tracingutils.SpanContextToContext(ctx, span.SpanContext()) return ctx, func() { - // log.Debug("# %s - end", name) + log.Debug("# %s - end", name) span.End() } } diff --git a/engine/api/pipeline.go b/engine/api/pipeline.go index 949968046e..3b336cd800 100644 --- a/engine/api/pipeline.go +++ b/engine/api/pipeline.go @@ -46,7 +46,7 @@ func (api *API) updateAsCodePipelineHandler() service.Handler { return sdk.WrapError(sdk.ErrInvalidPipelinePattern, "updateAsCodePipelineHandler: Pipeline name %s do not respect pattern", p.Name) } - proj, err := project.Load(api.mustDB(), key, + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, @@ -192,7 +192,7 @@ func (api *API) postPipelineRollbackHandler() service.Handler { return sdk.WithStack(sdk.ErrForbidden) } - proj, errP := project.Load(db, key, project.LoadOptions.WithGroups) + proj, errP := project.Load(ctx, db, key, project.LoadOptions.WithGroups) if errP != nil { return sdk.WrapError(errP, "postPipelineRollbackHandler> Cannot load project") } @@ -244,7 +244,7 @@ func (api *API) addPipelineHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.Default) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default) if err != nil { return sdk.WrapError(err, "cannot load %s", key) } @@ -318,7 +318,7 @@ func (api *API) getPipelineHandler() service.Handler { } if p.FromRepository != "" { - proj, err := project.Load(api.mustDB(), projectKey, + proj, err := project.Load(ctx, api.mustDB(), projectKey, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, @@ -368,7 +368,7 @@ func (api *API) getPipelinesHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - project, err := project.Load(api.mustDB(), key, project.LoadOptions.Default) + project, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default) if err != nil { if !sdk.ErrorIs(err, sdk.ErrNoProject) { log.Warning(ctx, "getPipelinesHandler: Cannot load %s: %s\n", key, err) @@ -395,7 +395,7 @@ func (api *API) deletePipelineHandler() service.Handler { key := vars[permProjectKey] pipelineName := vars["pipelineKey"] - proj, errP := project.Load(api.mustDB(), key) + proj, errP := project.Load(ctx, api.mustDB(), key) if errP != nil { return sdk.WrapError(errP, "Cannot load project") } diff --git a/engine/api/pipeline/pipeline_importer_test.go b/engine/api/pipeline/pipeline_importer_test.go index 1b36569e45..a3ac6c5986 100644 --- a/engine/api/pipeline/pipeline_importer_test.go +++ b/engine/api/pipeline/pipeline_importer_test.go @@ -52,7 +52,7 @@ func testImportUpdate(t *testing.T, db gorp.SqlExecutor, store cache.Store, tt t tt.setup(t, tt.args) } - proj, err := project.Load(db, tt.args.pip.ProjectKey, nil) + proj, err := project.Load(context.TODO(), db, tt.args.pip.ProjectKey, nil) test.NoError(t, err) if err := pipeline.ImportUpdate(context.TODO(), db, *proj, tt.args.pip, msgChan); (err != nil) != tt.wantErr { diff --git a/engine/api/pipeline_import.go b/engine/api/pipeline_import.go index 814c9397f4..bf3c5bf002 100644 --- a/engine/api/pipeline_import.go +++ b/engine/api/pipeline_import.go @@ -66,7 +66,7 @@ func (api *API) importPipelineHandler() service.Handler { } // Load project - proj, err := project.Load(api.mustDB(), key, + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default, project.LoadOptions.WithGroups, ) @@ -127,7 +127,7 @@ func (api *API) putImportPipelineHandler() service.Handler { return err } - proj, err := project.Load(api.mustDB(), key, + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default, project.LoadOptions.WithGroups, ) diff --git a/engine/api/pipeline_job.go b/engine/api/pipeline_job.go index e7f2b46773..1ae9684859 100644 --- a/engine/api/pipeline_job.go +++ b/engine/api/pipeline_job.go @@ -71,7 +71,7 @@ func (api *API) addJobToStageHandler() service.Handler { defer tx.Rollback() // nolint // check that action used by job can be used by pipeline's project - project, err := project.Load(tx, pip.ProjectKey, project.LoadOptions.WithGroups) + project, err := project.Load(ctx, tx, pip.ProjectKey, project.LoadOptions.WithGroups) if err != nil { return sdk.WithStack(err) } @@ -195,7 +195,7 @@ func (api *API) updateJobHandler() service.Handler { defer tx.Rollback() // nolint // check that action used by job can be used by pipeline's project - project, err := project.Load(tx, pipelineData.ProjectKey, project.LoadOptions.WithGroups) + project, err := project.Load(ctx, tx, pipelineData.ProjectKey, project.LoadOptions.WithGroups) if err != nil { return sdk.WithStack(err) } diff --git a/engine/api/pipeline_stage_test.go b/engine/api/pipeline_stage_test.go index f8bf44521d..f5f6ef7763 100644 --- a/engine/api/pipeline_stage_test.go +++ b/engine/api/pipeline_stage_test.go @@ -18,7 +18,7 @@ import ( func deleteAll(t *testing.T, api *API, key string) error { // Delete all apps t.Logf("start deleted : %s", key) - proj, errl := project.Load(api.mustDB(), key, project.LoadOptions.WithGroups) + proj, errl := project.Load(context.TODO(), api.mustDB(), key, project.LoadOptions.WithGroups) if errl != nil { return errl } diff --git a/engine/api/project.go b/engine/api/project.go index 23648d33ef..83b00fa4c0 100644 --- a/engine/api/project.go +++ b/engine/api/project.go @@ -234,7 +234,7 @@ func (api *API) updateProjectHandler() service.Handler { } // Check is project exist - p, errProj := project.Load(api.mustDB(), key, project.LoadOptions.WithIcon) + p, errProj := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIcon) if errProj != nil { return sdk.WrapError(errProj, "updateProject> Cannot load project from db") } @@ -331,7 +331,7 @@ func (api *API) getProjectHandler() service.Handler { opts = append(opts, project.LoadOptions.WithLabels) } - p, errProj := project.Load(api.mustDB(), key, opts...) + p, errProj := project.Load(ctx, api.mustDB(), key, opts...) if errProj != nil { return sdk.WrapError(errProj, "getProjectHandler (%s)", key) } @@ -372,7 +372,7 @@ func (api *API) putProjectLabelsHandler() service.Handler { } // Check if project exist - proj, err := project.Load(db, key, project.LoadOptions.WithLabels) + proj, err := project.Load(ctx, db, key, project.LoadOptions.WithLabels) if err != nil { return err } @@ -433,7 +433,7 @@ func (api *API) putProjectLabelsHandler() service.Handler { return sdk.WithStack(err) } - p, errP := project.Load(db, key, + p, errP := project.Load(ctx, db, key, project.LoadOptions.WithLabels, project.LoadOptions.WithWorkflowNames, project.LoadOptions.WithVariables, project.LoadOptions.WithFavorites(getAPIConsumer(ctx).AuthentifiedUser.ID), project.LoadOptions.WithKeys, project.LoadOptions.WithPermission, project.LoadOptions.WithIntegrations) @@ -597,7 +597,7 @@ func (api *API) postProjectHandler() service.Handler { event.PublishAddProject(ctx, &p, consumer) - proj, err := project.Load(api.mustDB(), p.Key, + proj, err := project.Load(ctx, api.mustDB(), p.Key, project.LoadOptions.WithLabels, project.LoadOptions.WithWorkflowNames, project.LoadOptions.WithFavorites(consumer.AuthentifiedUser.ID), @@ -622,7 +622,7 @@ func (api *API) deleteProjectHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - p, err := project.Load(api.mustDB(), key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications) + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications) if err != nil { if !sdk.ErrorIs(err, sdk.ErrNoProject) { return sdk.WrapError(err, "deleteProject> load project '%s' from db", key) diff --git a/engine/api/project/dao.go b/engine/api/project/dao.go index 9d109e2542..f976718419 100644 --- a/engine/api/project/dao.go +++ b/engine/api/project/dao.go @@ -3,6 +3,8 @@ package project import ( "context" "database/sql" + "reflect" + "runtime" "time" "github.com/go-gorp/gorp" @@ -125,7 +127,7 @@ func Exist(db gorp.SqlExecutor, projectKey string) (bool, error) { // Delete delete one or more projects given the key func Delete(db gorp.SqlExecutor, key string) error { - proj, err := Load(db, key, nil) + proj, err := Load(context.Background(), db, key, nil) if err != nil { return err } @@ -224,8 +226,8 @@ func LoadByID(db gorp.SqlExecutor, id int64, opts ...LoadOptionFunc) (*sdk.Proje } // Load returns a project with all its variables and applications given a user. It can also returns pipelines, environments, groups, permission, and repositorires manager. See LoadOptions -func Load(db gorp.SqlExecutor, key string, opts ...LoadOptionFunc) (*sdk.Project, error) { - return load(context.Background(), db, opts, "select project.* from project where projectkey = $1", key) +func Load(ctx context.Context, db gorp.SqlExecutor, key string, opts ...LoadOptionFunc) (*sdk.Project, error) { + return load(ctx, db, opts, "select project.* from project where projectkey = $1", key) } // LoadProjectByWorkflowID loads a project from workflow iD @@ -238,6 +240,10 @@ func LoadProjectByWorkflowID(db gorp.SqlExecutor, workflowID int64, opts ...Load } func loadprojects(ctx context.Context, db gorp.SqlExecutor, opts []LoadOptionFunc, query string, args ...interface{}) ([]sdk.Project, error) { + var end func() + _, end = observability.Span(ctx, "project.loadprojects") + defer end() + var res []dbProject if _, err := db.Select(&res, query, args...); err != nil { if err == sql.ErrNoRows { @@ -249,7 +255,7 @@ func loadprojects(ctx context.Context, db gorp.SqlExecutor, opts []LoadOptionFun projs := make([]sdk.Project, 0, len(res)) for i := range res { p := &res[i] - proj, err := unwrap(db, p, opts) + proj, err := unwrap(ctx, db, p, opts) if err != nil { log.Error(ctx, "loadprojects> unwrap error (ID=%d, Key:%s): %v", p.ID, p.Key, err) continue @@ -274,22 +280,29 @@ func load(ctx context.Context, db gorp.SqlExecutor, opts []LoadOptionFunc, query return nil, sdk.WithStack(err) } - return unwrap(db, dbProj, opts) + return unwrap(ctx, db, dbProj, opts) } -func unwrap(db gorp.SqlExecutor, p *dbProject, opts []LoadOptionFunc) (*sdk.Project, error) { +func unwrap(ctx context.Context, db gorp.SqlExecutor, p *dbProject, opts []LoadOptionFunc) (*sdk.Project, error) { + ctx, end := observability.Span(ctx, "project.unwrap") + defer end() + proj := sdk.Project(*p) for _, f := range opts { if f == nil { continue } + name := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name() + _, end = observability.Span(ctx, name) if err := f(db, &proj); err != nil && sdk.Cause(err) != sql.ErrNoRows { + end() return nil, err } + end() } - vcsServers, err := repositoriesmanager.LoadAllProjectVCSServerLinksByProjectID(context.Background(), db, p.ID) + vcsServers, err := repositoriesmanager.LoadAllProjectVCSServerLinksByProjectID(ctx, db, p.ID) if err != nil { return nil, err } diff --git a/engine/api/project_group.go b/engine/api/project_group.go index f9336e202c..c99c3893b7 100644 --- a/engine/api/project_group.go +++ b/engine/api/project_group.go @@ -29,7 +29,7 @@ func (api *API) deleteGroupFromProjectHandler() service.Handler { } defer tx.Rollback() // nolint - proj, err := project.Load(tx, key) + proj, err := project.Load(ctx, tx, key) if err != nil { return sdk.WrapError(err, "cannot load %s", key) } @@ -82,7 +82,7 @@ func (api *API) putGroupRoleOnProjectHandler() service.Handler { } defer tx.Rollback() // nolint - proj, err := project.Load(tx, key) + proj, err := project.Load(ctx, tx, key) if err != nil { return sdk.WrapError(err, "cannot load project %s", key) } @@ -168,7 +168,7 @@ func (api *API) postGroupInProjectHandler() service.Handler { } defer tx.Rollback() // nolint - proj, err := project.Load(tx, key) + proj, err := project.Load(ctx, tx, key) if err != nil { return sdk.WrapError(err, "cannot load %s", key) } @@ -231,7 +231,7 @@ func (api *API) postImportGroupsInProjectHandler() service.Handler { key := vars[permProjectKey] force := FormBool(r, "force") - proj, err := project.Load(api.mustDB(), key) + proj, err := project.Load(ctx, api.mustDB(), key) if err != nil { return sdk.WrapError(err, "cannot load project %s", key) } diff --git a/engine/api/project_integration.go b/engine/api/project_integration.go index 34dbe30dcb..b9d5177b55 100644 --- a/engine/api/project_integration.go +++ b/engine/api/project_integration.go @@ -60,7 +60,7 @@ func (api *API) putProjectIntegrationHandler() service.Handler { return sdk.WrapError(err, "Cannot read body") } - p, err := project.Load(api.mustDB(), projectKey) + p, err := project.Load(ctx, api.mustDB(), projectKey) if err != nil { return sdk.WrapError(err, "Cannot load project") } @@ -144,7 +144,7 @@ func (api *API) deleteProjectIntegrationHandler() service.Handler { projectKey := vars[permProjectKey] integrationName := vars["integrationName"] - p, err := project.Load(api.mustDB(), projectKey, project.LoadOptions.WithIntegrations) + p, err := project.Load(ctx, api.mustDB(), projectKey, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "Cannot load project") } @@ -187,7 +187,7 @@ func (api *API) getProjectIntegrationsHandler() service.Handler { vars := mux.Vars(r) projectKey := vars[permProjectKey] - p, errP := project.Load(api.mustDB(), projectKey, project.LoadOptions.WithIntegrations) + p, errP := project.Load(ctx, api.mustDB(), projectKey, project.LoadOptions.WithIntegrations) if errP != nil { return sdk.WrapError(errP, "getProjectIntegrationsHandler> Cannot load project") } @@ -200,7 +200,7 @@ func (api *API) postProjectIntegrationHandler() service.Handler { vars := mux.Vars(r) projectKey := vars[permProjectKey] - p, err := project.Load(api.mustDB(), projectKey, project.LoadOptions.WithIntegrations) + p, err := project.Load(ctx, api.mustDB(), projectKey, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "Cannot load project") } diff --git a/engine/api/project_key.go b/engine/api/project_key.go index fcfe4c9173..c5adacb6ba 100644 --- a/engine/api/project_key.go +++ b/engine/api/project_key.go @@ -19,7 +19,7 @@ func (api *API) getKeysInProjectHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - p, err := project.Load(api.mustDB(), key) + p, err := project.Load(ctx, api.mustDB(), key) if err != nil { return err } @@ -39,7 +39,7 @@ func (api *API) deleteKeyInProjectHandler() service.Handler { key := vars[permProjectKey] keyName := vars["name"] - p, errP := project.Load(api.mustDB(), key, project.LoadOptions.WithKeys) + p, errP := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithKeys) if errP != nil { return sdk.WrapError(errP, "deleteKeyInProjectHandler> Cannot load project") } @@ -86,7 +86,7 @@ func (api *API) addKeyInProjectHandler() service.Handler { return sdk.WrapError(sdk.ErrInvalidKeyPattern, "addKeyInProjectHandler: Key name %s do not respect pattern %s", newKey.Name, sdk.NamePattern) } - p, errP := project.Load(api.mustDB(), key) + p, errP := project.Load(ctx, api.mustDB(), key) if errP != nil { return sdk.WrapError(errP, "addKeyInProjectHandler> Cannot load project") } diff --git a/engine/api/project_variable.go b/engine/api/project_variable.go index 689d5b15a1..9d6f97f2e0 100644 --- a/engine/api/project_variable.go +++ b/engine/api/project_variable.go @@ -17,7 +17,7 @@ func (api *API) postEncryptVariableHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - p, errp := project.Load(api.mustDB(), key) + p, errp := project.Load(ctx, api.mustDB(), key) if errp != nil { return sdk.WrapError(errp, "unable to load project") } @@ -59,7 +59,7 @@ func (api *API) getVariablesInProjectHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - p, err := project.Load(api.mustDB(), key, project.LoadOptions.WithVariables) + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithVariables) if err != nil { return sdk.WrapError(err, "cannot load %s", key) } @@ -75,7 +75,7 @@ func (api *API) deleteVariableFromProjectHandler() service.Handler { key := vars[permProjectKey] varName := vars["name"] - p, err := project.Load(api.mustDB(), key, project.LoadOptions.Default) + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default) if err != nil { return sdk.WrapError(err, "deleteVariableFromProject: Cannot load %s", key) } @@ -117,7 +117,7 @@ func (api *API) updateVariableInProjectHandler() service.Handler { return err } - p, err := project.Load(api.mustDB(), key, project.LoadOptions.Default) + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default) if err != nil { return sdk.WrapError(err, "updateVariableInProject: Cannot load %s", key) } @@ -163,7 +163,7 @@ func (api *API) addVariableInProjectHandler() service.Handler { } - p, err := project.Load(api.mustDB(), key, project.LoadOptions.Default) + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default) if err != nil { return err } @@ -201,7 +201,7 @@ func (api *API) getVariableInProjectHandler() service.Handler { key := vars[permProjectKey] varName := vars["name"] - p, err := project.Load(api.mustDB(), key, project.LoadOptions.WithVariables) + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithVariables) if err != nil { return sdk.WrapError(err, "getVariableInProjectHandler: Cannot load %s", key) } @@ -221,7 +221,7 @@ func (api *API) getVariableAuditInProjectHandler() service.Handler { key := vars[permProjectKey] varName := vars["name"] - p, err := project.Load(api.mustDB(), key) + p, err := project.Load(ctx, api.mustDB(), key) if err != nil { return err } diff --git a/engine/api/repositories_manager.go b/engine/api/repositories_manager.go index 7765577578..92747023e8 100644 --- a/engine/api/repositories_manager.go +++ b/engine/api/repositories_manager.go @@ -39,7 +39,7 @@ func (api *API) getRepositoriesManagerForProjectHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - proj, errproj := project.Load(api.mustDB(), key) + proj, errproj := project.Load(ctx, api.mustDB(), key) if errproj != nil { return errproj } @@ -54,7 +54,7 @@ func (api *API) repositoriesManagerAuthorizeHandler() service.Handler { key := vars[permProjectKey] rmName := vars["name"] - proj, err := project.Load(api.mustDB(), key) + proj, err := project.Load(ctx, api.mustDB(), key) if err != nil { return sdk.WrapError(err, "cannot load project") } @@ -125,7 +125,7 @@ func (api *API) repositoriesManagerOAuthCallbackHandler() service.Handler { // return sdk.WrapError(err, "repositoriesManagerAuthorizeCallback> Cannot load user %s", username) //} - proj, errP := project.Load(api.mustDB(), projectKey) + proj, errP := project.Load(ctx, api.mustDB(), projectKey) if errP != nil { return sdk.WrapError(errP, "repositoriesManagerAuthorizeCallback> Cannot load project") } @@ -201,7 +201,7 @@ func (api *API) repositoriesManagerAuthorizeBasicHandler() service.Handler { return sdk.WrapError(sdk.ErrWrongRequest, "cannot get token nor verifier from data") } - proj, errP := project.Load(api.mustDB(), projectKey) + proj, errP := project.Load(ctx, api.mustDB(), projectKey) if errP != nil { return sdk.WrapError(errP, "cannot load project %s", projectKey) } @@ -268,7 +268,7 @@ func (api *API) repositoriesManagerAuthorizeCallbackHandler() service.Handler { return sdk.WrapError(sdk.ErrWrongRequest, "repositoriesManagerAuthorizeCallback> Cannot get token nor verifier from data") } - proj, errP := project.Load(api.mustDB(), projectKey) + proj, errP := project.Load(ctx, api.mustDB(), projectKey) if errP != nil { return sdk.WrapError(errP, "repositoriesManagerAuthorizeCallback> Cannot load project") } @@ -321,7 +321,7 @@ func (api *API) deleteRepositoriesManagerHandler() service.Handler { force := FormBool(r, "force") - p, err := project.Load(api.mustDB(), projectKey) + p, err := project.Load(ctx, api.mustDB(), projectKey) if err != nil { return sdk.WrapError(err, "cannot load project %s", projectKey) } @@ -372,7 +372,7 @@ func (api *API) getReposFromRepositoriesManagerHandler() service.Handler { vcsServerName := vars["name"] sync := FormBool(r, "synchronize") - proj, err := project.Load(api.mustDB(), projectKey) + proj, err := project.Load(ctx, api.mustDB(), projectKey) if err != nil { return sdk.NewErrorWithStack(err, sdk.NewErrorFrom(sdk.ErrNoReposManagerClientAuth, "cannot get client got %s %s", projectKey, vcsServerName)) @@ -431,7 +431,7 @@ func (api *API) getRepositoriesManagerLinkedApplicationsHandler() service.Handle projectKey := vars[permProjectKey] rmName := vars["name"] - proj, err := project.Load(api.mustDB(), projectKey) + proj, err := project.Load(ctx, api.mustDB(), projectKey) if err != nil { return sdk.WrapError(err, "cannot get client got %s %s", projectKey, rmName) } @@ -504,7 +504,7 @@ func (api *API) attachRepositoriesManagerHandler() service.Handler { // Update default payload of linked workflow root if len(usage.Workflows) > 0 { - proj, errP := project.Load(db, projectKey, project.LoadOptions.WithIntegrations) + proj, errP := project.Load(ctx, db, projectKey, project.LoadOptions.WithIntegrations) if errP != nil { return sdk.WrapError(errP, "attachRepositoriesManager> Cannot load project") } diff --git a/engine/api/router_middleware_auth_permission.go b/engine/api/router_middleware_auth_permission.go index fb1a31e92e..6e7eef7d22 100644 --- a/engine/api/router_middleware_auth_permission.go +++ b/engine/api/router_middleware_auth_permission.go @@ -104,7 +104,7 @@ func (api *API) checkProjectPermissions(ctx context.Context, projectKey string, ctx, end := observability.Span(ctx, "api.checkProjectPermissions") defer end() - if _, err := project.Load(api.mustDB(), projectKey); err != nil { + if _, err := project.Load(ctx, api.mustDB(), projectKey); err != nil { return err } diff --git a/engine/api/suggest.go b/engine/api/suggest.go index 55fc669dfe..b85a0f25f9 100644 --- a/engine/api/suggest.go +++ b/engine/api/suggest.go @@ -25,7 +25,7 @@ func (api *API) getVariablesHandler() service.Handler { var allVariables []string - proj, err := project.Load(api.mustDB(), projectKey, project.LoadOptions.WithVariables) + proj, err := project.Load(ctx, api.mustDB(), projectKey, project.LoadOptions.WithVariables) if err != nil { return err } diff --git a/engine/api/templates.go b/engine/api/templates.go index 657363ab31..a9171abad7 100644 --- a/engine/api/templates.go +++ b/engine/api/templates.go @@ -360,7 +360,7 @@ func (api *API) postTemplateApplyHandler() service.Handler { } // load project with key - p, err := project.Load(api.mustDB(), req.ProjectKey, + p, err := project.Load(ctx, api.mustDB(), req.ProjectKey, project.LoadOptions.WithGroups, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, @@ -585,7 +585,7 @@ func (api *API) postTemplateBulkHandler() service.Handler { } // load project with key - p, err := project.Load(api.mustDB(), bulk.Operations[i].Request.ProjectKey, + p, err := project.Load(ctx, api.mustDB(), bulk.Operations[i].Request.ProjectKey, project.LoadOptions.WithGroups, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, diff --git a/engine/api/test/assets/assets.go b/engine/api/test/assets/assets.go index 28016758f4..6c8e7d75df 100644 --- a/engine/api/test/assets/assets.go +++ b/engine/api/test/assets/assets.go @@ -38,7 +38,7 @@ import ( // InsertTestProject create a test project. func InsertTestProject(t *testing.T, db *gorp.DbMap, store cache.Store, key, name string) *sdk.Project { - oldProj, _ := project.Load(db, key, + oldProj, _ := project.Load(context.TODO(), db, key, project.LoadOptions.WithApplications, project.LoadOptions.WithPipelines, project.LoadOptions.WithWorkflows, diff --git a/engine/api/user_bookmark.go b/engine/api/user_bookmark.go index 4f7c76460c..8635694fa3 100644 --- a/engine/api/user_bookmark.go +++ b/engine/api/user_bookmark.go @@ -20,7 +20,7 @@ func (api *API) postUserFavoriteHandler() service.Handler { consumer := getAPIConsumer(ctx) - p, err := project.Load(api.mustDB(), params.ProjectKey, + p, err := project.Load(ctx, api.mustDB(), params.ProjectKey, project.LoadOptions.WithIntegrations, project.LoadOptions.WithFavorites(consumer.AuthentifiedUser.ID), ) diff --git a/engine/api/worker_model.go b/engine/api/worker_model.go index f2002e829d..905a2a3e08 100644 --- a/engine/api/worker_model.go +++ b/engine/api/worker_model.go @@ -284,7 +284,7 @@ func (api *API) getWorkerModelsForProjectHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithGroups) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithGroups) if err != nil { return sdk.WrapError(err, "unable to load projet %s", key) } diff --git a/engine/api/workflow.go b/engine/api/workflow.go index f444c9e18f..b69b31fcff 100644 --- a/engine/api/workflow.go +++ b/engine/api/workflow.go @@ -108,7 +108,7 @@ func (api *API) getWorkflowHandler() service.Handler { minimal := FormBool(r, "minimal") withoutIcons := FormBool(r, "withoutIcons") - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load projet") } @@ -201,7 +201,7 @@ func (api *API) postWorkflowRollbackHandler() service.Handler { db := api.mustDB() u := getAPIConsumer(ctx) - proj, err := project.Load(db, key, + proj, err := project.Load(ctx, db, key, project.LoadOptions.WithGroups, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, @@ -268,7 +268,7 @@ func (api *API) postWorkflowLabelHandler() service.Handler { return sdk.WrapError(err, "cannot read body") } - proj, err := project.Load(db, key, + proj, err := project.Load(ctx, db, key, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, @@ -338,7 +338,7 @@ func (api *API) deleteWorkflowLabelHandler() service.Handler { db := api.mustDB() - proj, err := project.Load(db, key, + proj, err := project.Load(ctx, db, key, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, @@ -368,7 +368,7 @@ func (api *API) postWorkflowHandler() service.Handler { vars := mux.Vars(r) key := vars[permProjectKey] - p, err := project.Load(api.mustDB(), key, + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, @@ -429,7 +429,7 @@ func (api *API) putWorkflowHandler() service.Handler { key := vars["key"] name := vars["permWorkflowName"] - p, err := project.Load(api.mustDB(), key, + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, @@ -516,7 +516,7 @@ func (api *API) putWorkflowIconHandler() service.Handler { key := vars["key"] name := vars["permWorkflowName"] - p, errP := project.Load(api.mustDB(), key) + p, errP := project.Load(ctx, api.mustDB(), key) if errP != nil { return errP } @@ -557,7 +557,7 @@ func (api *API) deleteWorkflowIconHandler() service.Handler { key := vars["key"] name := vars["permWorkflowName"] - p, errP := project.Load(api.mustDB(), key) + p, errP := project.Load(ctx, api.mustDB(), key) if errP != nil { return errP } @@ -582,7 +582,7 @@ func (api *API) deleteWorkflowHandler() service.Handler { key := vars["key"] name := vars["permWorkflowName"] - p, errP := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + p, errP := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if errP != nil { return sdk.WrapError(errP, "Cannot load Project %s", key) } @@ -662,7 +662,7 @@ func (api *API) deleteWorkflowEventsIntegrationHandler() service.Handler { return sdk.WrapError(sdk.ErrInvalidID, "integration id is not correct (%s) : %v", prjIntegrationIDStr, err) } - p, err := project.Load(db, key, project.LoadOptions.WithIntegrations) + p, err := project.Load(ctx, db, key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "cannot load Project %s", key) } @@ -687,7 +687,7 @@ func (api *API) getWorkflowHookHandler() service.Handler { name := vars["permWorkflowName"] uuid := vars["uuid"] - proj, err := project.Load(api.mustDB(), key, + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, diff --git a/engine/api/workflow/dao.go b/engine/api/workflow/dao.go index a047c3478b..1b145612a2 100644 --- a/engine/api/workflow/dao.go +++ b/engine/api/workflow/dao.go @@ -395,6 +395,9 @@ func Insert(ctx context.Context, db gorp.SqlExecutor, store cache.Store, proj sd } func RenameNode(ctx context.Context, db gorp.SqlExecutor, w *sdk.Workflow) error { + ctx, end := observability.Span(ctx, "workflow.RenameNode") + defer end() + nodes := w.WorkflowData.Array() var maxJoinNumber int maxNumberByPipeline := map[int64]int{} @@ -569,6 +572,9 @@ func RenameNode(ctx context.Context, db gorp.SqlExecutor, w *sdk.Workflow) error // Update updates a workflow func Update(ctx context.Context, db gorp.SqlExecutor, store cache.Store, proj sdk.Project, wf *sdk.Workflow, uptOption UpdateOptions) error { + ctx, end := observability.Span(ctx, "workflow.Update") + defer end() + if err := CompleteWorkflow(ctx, db, wf, proj, LoadOptions{}); err != nil { return err } @@ -689,6 +695,8 @@ func Delete(ctx context.Context, db gorp.SqlExecutor, store cache.Store, proj sd } func CompleteWorkflow(ctx context.Context, db gorp.SqlExecutor, w *sdk.Workflow, proj sdk.Project, opts LoadOptions) error { + ctx, end := observability.Span(ctx, "workflow.CompleteWorkflow") + defer end() w.InitMaps() w.AssignEmptyType() diff --git a/engine/api/workflow/workflow_exporter_test.go b/engine/api/workflow/workflow_exporter_test.go index fc81879310..464a47437e 100644 --- a/engine/api/workflow/workflow_exporter_test.go +++ b/engine/api/workflow/workflow_exporter_test.go @@ -116,7 +116,7 @@ func TestPull(t *testing.T) { }, } - proj, _ = project.Load(db, proj.Key, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, project.LoadOptions.WithPipelines) + proj, _ = project.Load(context.TODO(), db, proj.Key, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, project.LoadOptions.WithPipelines) test.NoError(t, workflow.Insert(context.TODO(), db, cache, *proj, &w)) diff --git a/engine/api/workflow/workflow_importer_test.go b/engine/api/workflow/workflow_importer_test.go index ceb86848dc..d4a518ab0c 100644 --- a/engine/api/workflow/workflow_importer_test.go +++ b/engine/api/workflow/workflow_importer_test.go @@ -80,7 +80,7 @@ func TestImport(t *testing.T) { test.NoError(t, environment.InsertEnvironment(db, env)) //Reload project - proj, _ = project.Load(db, proj.Key, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, project.LoadOptions.WithPipelines) + proj, _ = project.Load(context.TODO(), db, proj.Key, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, project.LoadOptions.WithPipelines) test.NoError(t, workflow.CreateBuiltinWorkflowHookModels(db)) hookModels, err := workflow.LoadHookModels(db) diff --git a/engine/api/workflow/workflow_parser_test.go b/engine/api/workflow/workflow_parser_test.go index 6ba6cfc4af..994675e593 100644 --- a/engine/api/workflow/workflow_parser_test.go +++ b/engine/api/workflow/workflow_parser_test.go @@ -62,7 +62,7 @@ func TestParseAndImport(t *testing.T) { test.NoError(t, environment.InsertEnvironment(db, env)) //Reload project - proj, _ = project.Load(db, proj.Key, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, project.LoadOptions.WithPipelines) + proj, _ = project.Load(context.TODO(), db, proj.Key, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, project.LoadOptions.WithPipelines) input := v2.Workflow{ Name: sdk.RandomString(10), @@ -247,7 +247,7 @@ func TestParseAndImportFromRepository(t *testing.T) { test.NoError(t, environment.InsertEnvironment(db, env)) //Reload project - proj, _ = project.Load(db, proj.Key, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, project.LoadOptions.WithPipelines) + proj, _ = project.Load(context.TODO(), db, proj.Key, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, project.LoadOptions.WithPipelines) input := v2.Workflow{ Name: sdk.RandomString(10), diff --git a/engine/api/workflow_application.go b/engine/api/workflow_application.go index 020c54b770..bb4b3fe14a 100644 --- a/engine/api/workflow_application.go +++ b/engine/api/workflow_application.go @@ -36,7 +36,7 @@ func (api *API) releaseApplicationWorkflowHandler() service.Handler { return errU } - proj, errprod := project.Load(api.mustDB(), key) + proj, errprod := project.Load(ctx, api.mustDB(), key) if errprod != nil { return sdk.WrapError(errprod, "releaseApplicationWorkflowHandler") } diff --git a/engine/api/workflow_ascode.go b/engine/api/workflow_ascode.go index cbf1a6f68d..34cff5c082 100644 --- a/engine/api/workflow_ascode.go +++ b/engine/api/workflow_ascode.go @@ -55,7 +55,7 @@ func (api *API) postWorkflowAsCodeHandler() service.Handler { } u := getAPIConsumer(ctx) - p, err := project.Load(api.mustDB(), key, + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, diff --git a/engine/api/workflow_ascode_test.go b/engine/api/workflow_ascode_test.go index e934433148..8df9b9104a 100644 --- a/engine/api/workflow_ascode_test.go +++ b/engine/api/workflow_ascode_test.go @@ -158,7 +158,7 @@ func TestPostUpdateWorkflowAsCodeHandler(t *testing.T) { w.FromRepository = "myfromrepositoryurl" var errP error - proj, errP = project.Load(api.mustDB(), proj.Key, + proj, errP = project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, @@ -366,7 +366,7 @@ func TestPostMigrateWorkflowAsCodeHandler(t *testing.T) { w := initWorkflow(t, db, proj, app, pip, repoModel) var errP error - proj, errP = project.Load(api.mustDB(), proj.Key, + proj, errP = project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, diff --git a/engine/api/workflow_export.go b/engine/api/workflow_export.go index 3efc41c03b..ad345be2d2 100644 --- a/engine/api/workflow_export.go +++ b/engine/api/workflow_export.go @@ -37,7 +37,7 @@ func (api *API) getWorkflowExportHandler() service.Handler { opts = append(opts, v2.WorkflowWithPermissions) } - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load projet") } @@ -71,7 +71,7 @@ func (api *API) getWorkflowPullHandler() service.Handler { opts = append(opts, v2.WorkflowWithPermissions) } - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load projet") } diff --git a/engine/api/workflow_export_test.go b/engine/api/workflow_export_test.go index c56eb7b8eb..3fc5d87df7 100644 --- a/engine/api/workflow_export_test.go +++ b/engine/api/workflow_export_test.go @@ -103,7 +103,7 @@ func Test_getWorkflowExportHandler(t *testing.T) { test.NoError(t, workflow.RenameNode(context.Background(), db, &w)) - proj, _ = project.Load(api.mustDB(), proj.Key, + proj, _ = project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, ) @@ -240,7 +240,7 @@ func Test_getWorkflowExportHandlerWithPermissions(t *testing.T) { test.NoError(t, workflow.RenameNode(context.TODO(), db, &w)) - proj, _ = project.Load(api.mustDB(), proj.Key, + proj, _ = project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, ) @@ -350,7 +350,7 @@ func Test_getWorkflowPullHandler(t *testing.T) { test.NoError(t, workflow.RenameNode(context.TODO(), db, &w)) - proj, _ = project.Load(api.mustDB(), proj.Key, + proj, _ = project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, ) diff --git a/engine/api/workflow_group.go b/engine/api/workflow_group.go index 189e6be262..65a8da79c8 100644 --- a/engine/api/workflow_group.go +++ b/engine/api/workflow_group.go @@ -24,7 +24,7 @@ func (api *API) deleteWorkflowGroupHandler() service.Handler { groupName := vars["groupName"] u := getAPIConsumer(ctx) - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load projet") } @@ -87,7 +87,7 @@ func (api *API) putWorkflowGroupHandler() service.Handler { return sdk.WrapError(sdk.ErrInvalidName, "putWorkflowGroupHandler") } - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load projet") } @@ -142,7 +142,7 @@ func (api *API) postWorkflowGroupHandler() service.Handler { return sdk.WrapError(err, "cannot unmarshal body") } - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load projet") } diff --git a/engine/api/workflow_group_test.go b/engine/api/workflow_group_test.go index 65113c35cf..554fd096d0 100644 --- a/engine/api/workflow_group_test.go +++ b/engine/api/workflow_group_test.go @@ -48,7 +48,7 @@ func Test_postWorkflowGroupHandler(t *testing.T) { ProjectKey: proj.Key, } - proj2, errP := project.Load(api.mustDB(), proj.Key, + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, ) @@ -120,7 +120,7 @@ func Test_postWorkflowGroupWithLessThanRWXProjectHandler(t *testing.T) { ProjectKey: proj.Key, } - proj2, errP := project.Load(api.mustDB(), proj.Key, + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, ) @@ -186,7 +186,7 @@ func Test_putWorkflowGroupHandler(t *testing.T) { ProjectKey: proj.Key, } - proj2, errP := project.Load(api.mustDB(), proj.Key, + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, ) @@ -291,7 +291,7 @@ func Test_deleteWorkflowGroupHandler(t *testing.T) { ProjectKey: proj.Key, } - proj2, errP := project.Load(api.mustDB(), proj.Key, + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, ) @@ -401,7 +401,7 @@ func Test_UpdateProjectPermsWithWorkflow(t *testing.T) { router.Mux.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) - proj2, errP := project.Load(api.mustDB(), proj.Key, + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, ) @@ -507,7 +507,7 @@ func Test_PermissionOnWorkflowInferiorOfProject(t *testing.T) { require.NoError(t, group.DeleteUserFromGroup(context.TODO(), db, proj.ProjectGroups[0].Group.ID, u.ID)) - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups) require.NoError(t, errP) wfLoaded, errL := workflow.Load(context.Background(), db, api.Cache, *proj2, newWf.Name, workflow.LoadOptions{DeepPipeline: true}) require.NoError(t, errL) @@ -675,7 +675,7 @@ func Test_PermissionOnWorkflowWithRestrictionOnNode(t *testing.T) { test.NoError(t, group.DeleteUserFromGroup(context.TODO(), db, proj.ProjectGroups[0].Group.ID, u.ID)) - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups) test.NoError(t, errP) wfLoaded, errL := workflow.Load(context.Background(), db, api.Cache, *proj2, newWf.Name, workflow.LoadOptions{DeepPipeline: true}) test.NoError(t, errL) diff --git a/engine/api/workflow_hook.go b/engine/api/workflow_hook.go index ce5437368a..d67c70f416 100644 --- a/engine/api/workflow_hook.go +++ b/engine/api/workflow_hook.go @@ -52,7 +52,7 @@ func (api *API) getWorkflowHookModelsHandler() service.Handler { return err } - p, err := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WithStack(err) } @@ -241,7 +241,7 @@ func (api *API) postWorkflowJobHookCallbackHandler() service.Handler { defer tx.Rollback() // nolint _, next := observability.Span(ctx, "project.Load") - proj, err := project.Load(tx, key, + proj, err := project.Load(ctx, tx, key, project.LoadOptions.WithVariables, project.LoadOptions.WithFeatures(api.Cache), project.LoadOptions.WithIntegrations, diff --git a/engine/api/workflow_import.go b/engine/api/workflow_import.go index bca9ced867..2b19213482 100644 --- a/engine/api/workflow_import.go +++ b/engine/api/workflow_import.go @@ -40,7 +40,7 @@ func (api *API) postWorkflowPreviewHandler() service.Handler { return err } - proj, err := project.Load(api.mustDB(), key, + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithGroups, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, @@ -104,7 +104,7 @@ func (api *API) postWorkflowImportHandler() service.Handler { return err } - proj, err := project.Load(api.mustDB(), key, + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithGroups, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, @@ -199,7 +199,7 @@ func (api *API) putWorkflowImportHandler() service.Handler { } // Load project - proj, err := project.Load(api.mustDB(), key, + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithGroups, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, @@ -292,7 +292,7 @@ func (api *API) postWorkflowPushHandler() service.Handler { u := getAPIConsumer(ctx) //Load project - proj, err := project.Load(db, key, + proj, err := project.Load(ctx, db, key, project.LoadOptions.WithGroups, project.LoadOptions.WithApplications, project.LoadOptions.WithEnvironments, diff --git a/engine/api/workflow_import_test.go b/engine/api/workflow_import_test.go index 7b929c653c..932a4cfd6d 100644 --- a/engine/api/workflow_import_test.go +++ b/engine/api/workflow_import_test.go @@ -738,7 +738,7 @@ func Test_getWorkflowPushHandler(t *testing.T) { }, } - proj, _ = project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications) + proj, _ = project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications) test.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj, &w)) test.NoError(t, workflow.RenameNode(context.TODO(), api.mustDB(), &w)) @@ -907,7 +907,7 @@ metadata: api.Router.Mux.ServeHTTP(rec, req) assert.Equal(t, 200, rec.Code) - p, errP := project.Load(db, proj.Key) + p, errP := project.Load(context.TODO(), db, proj.Key) assert.NoError(t, errP) wUpdated, err := workflow.Load(context.TODO(), db, api.Cache, *p, "test_1", workflow.LoadOptions{}) assert.NoError(t, err) diff --git a/engine/api/workflow_queue_test.go b/engine/api/workflow_queue_test.go index 686bbf4ec1..9d8daae649 100644 --- a/engine/api/workflow_queue_test.go +++ b/engine/api/workflow_queue_test.go @@ -176,7 +176,7 @@ func testRunWorkflow(t *testing.T, api *API, router *Router) testRunWorkflowCtx }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -1050,7 +1050,7 @@ func TestWorkerPrivateKey(t *testing.T) { }, } - p, err := project.Load(db, proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications) + p, err := project.Load(context.TODO(), db, proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications) assert.NoError(t, err) assert.NoError(t, workflow.Insert(context.TODO(), db, api.Cache, *p, &w)) @@ -1166,7 +1166,7 @@ func TestPostVulnerabilityReportHandler(t *testing.T) { }, } - p, err := project.Load(db, proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications) + p, err := project.Load(context.TODO(), db, proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications) assert.NoError(t, err) assert.NoError(t, workflow.Insert(context.TODO(), db, api.Cache, *p, &w)) @@ -1320,7 +1320,7 @@ func TestInsertNewCodeCoverageReport(t *testing.T) { }, } - p, err := project.Load(db, proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications) + p, err := project.Load(context.TODO(), db, proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications) require.NoError(t, err) require.NoError(t, workflow.Insert(context.TODO(), db, api.Cache, *p, &w)) diff --git a/engine/api/workflow_run.go b/engine/api/workflow_run.go index d134a9a2c3..efaa782462 100644 --- a/engine/api/workflow_run.go +++ b/engine/api/workflow_run.go @@ -224,7 +224,7 @@ func (api *API) postWorkflowRunNumHandler() service.Handler { return sdk.WrapError(sdk.ErrWrongRequest, "cannot num must be > %d, got %d", num, m.Num) } - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load projet") } @@ -355,7 +355,7 @@ func (api *API) stopWorkflowRunHandler() service.Handler { return sdk.WrapError(err, "unable to load last workflow run") } - proj, err := project.Load(api.mustDB(), key) + proj, err := project.Load(ctx, api.mustDB(), key) if err != nil { return sdk.WrapError(err, "unable to load project") } @@ -459,7 +459,7 @@ func stopWorkflowRun(ctx context.Context, dbFunc func() *gorp.DbMap, store cache continue } - targetProj, errP := project.Load(dbFunc(), targetProject) + targetProj, errP := project.Load(ctx, dbFunc(), targetProject) if errP != nil { log.Error(ctx, "stopWorkflowRun> Unable to load project %v", errP) continue @@ -503,7 +503,7 @@ func updateParentWorkflowRun(ctx context.Context, dbFunc func() *gorp.DbMap, sto return nil, nil } - parentProj, err := project.Load( + parentProj, err := project.Load(context.Background(), dbFunc(), run.RootRun().HookEvent.ParentWorkflow.Key, project.LoadOptions.WithVariables, project.LoadOptions.WithFeatures(store), @@ -577,7 +577,7 @@ func (api *API) getWorkflowCommitsHandler() service.Handler { return err } - proj, errP := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + proj, errP := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if errP != nil { return sdk.WrapError(errP, "getWorkflowCommitsHandler> Unable to load project %s", key) } @@ -667,7 +667,7 @@ func (api *API) stopWorkflowNodeRunHandler() service.Handler { return err } - p, err := project.Load(api.mustDB(), key, project.LoadOptions.WithVariables) + p, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithVariables) if err != nil { return sdk.WrapError(err, "cannot load project") } @@ -793,7 +793,7 @@ func (api *API) postWorkflowRunHandler() service.Handler { // LOAD PROJECT _, next := observability.Span(ctx, "project.Load") - p, errP := project.Load(api.mustDB(), key, + p, errP := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithVariables, project.LoadOptions.WithFeatures(api.Cache), project.LoadOptions.WithIntegrations, @@ -927,7 +927,7 @@ func (api *API) initWorkflowRun(ctx context.Context, projKey string, wf *sdk.Wor var asCodeInfosMsg []sdk.Message report := new(workflow.ProcessorReport) - p, err := project.Load(api.mustDB(), projKey, + p, err := project.Load(ctx, api.mustDB(), projKey, project.LoadOptions.WithVariables, project.LoadOptions.WithFeatures(api.Cache), project.LoadOptions.WithIntegrations, @@ -973,7 +973,7 @@ func (api *API) initWorkflowRun(ctx context.Context, projKey string, wf *sdk.Wor if wf.FromRepository != "" && (workflowStartedByRepoWebHook || opts.Manual != nil) { log.Debug("initWorkflowRun> rebuild workflow %s/%s from as code configuration", p.Key, wf.Name) - p1, err := project.Load(api.mustDB(), projKey, + p1, err := project.Load(ctx, api.mustDB(), projKey, project.LoadOptions.WithVariables, project.LoadOptions.WithGroups, project.LoadOptions.WithApplicationVariables, @@ -1119,7 +1119,7 @@ func (api *API) getDownloadArtifactHandler() service.Handler { return sdk.NewErrorFrom(sdk.ErrInvalidID, "invalid node job run ID") } - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load projet") } @@ -1380,7 +1380,7 @@ func (api *API) postResyncVCSWorkflowRunHandler() service.Handler { return err } - proj, err := project.Load(db, key, project.LoadOptions.WithVariables) + proj, err := project.Load(ctx, db, key, project.LoadOptions.WithVariables) if err != nil { return sdk.WrapError(err, "cannot load project") } diff --git a/engine/api/workflow_run_test.go b/engine/api/workflow_run_test.go index 1f422c5f09..b64e406f45 100644 --- a/engine/api/workflow_run_test.go +++ b/engine/api/workflow_run_test.go @@ -109,7 +109,7 @@ func Test_getWorkflowNodeRunHistoryHandler(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), db, api.Cache, *proj2, &w)) @@ -236,7 +236,7 @@ func Test_getWorkflowRunsHandler(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -391,7 +391,7 @@ func Test_getWorkflowRunsHandlerWithFilter(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -507,7 +507,7 @@ func Test_getLatestWorkflowRunHandler(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -641,7 +641,7 @@ func Test_getWorkflowRunHandler(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -766,7 +766,7 @@ func Test_getWorkflowNodeRunHandler(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations, project.LoadOptions.WithApplications) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations, project.LoadOptions.WithApplications) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -907,7 +907,7 @@ func Test_postWorkflowRunHandler(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -1041,7 +1041,7 @@ func Test_postWorkflowRunAsyncFailedHandler(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithApplications, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithApplications, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -1317,7 +1317,7 @@ func Test_postWorkflowRunHandlerWithoutRightOnEnvironment(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithEnvironments) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithEnvironments) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -1467,7 +1467,7 @@ func Test_postWorkflowRunHandlerWithoutRightConditionsOnHook(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithEnvironments) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithEnvironments) test.NoError(t, errP) test.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -1610,7 +1610,7 @@ func Test_postWorkflowRunHandlerHookWithMutex(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithEnvironments) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithEnvironments) test.NoError(t, errP) test.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -2047,7 +2047,7 @@ func Test_postWorkflowRunHandlerHook(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithEnvironments) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithEnvironments) test.NoError(t, errP) test.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -2139,7 +2139,7 @@ func Test_postWorkflowRunHandler_Forbidden(t *testing.T) { } require.NoError(t, environment.InsertEnvironment(api.mustDB(), env)) - proj2, errp := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments) + proj2, errp := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments) require.NoError(t, errp) w := sdk.Workflow{ @@ -2202,7 +2202,7 @@ func Test_postWorkflowRunHandler_ConditionNotOK(t *testing.T) { } test.NoError(t, environment.InsertEnvironment(api.mustDB(), env)) - proj2, errp := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments) + proj2, errp := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments) test.NoError(t, errp) w := sdk.Workflow{ @@ -2296,7 +2296,7 @@ func Test_postWorkflowRunHandler_BadPayload(t *testing.T) { } require.NoError(t, environment.InsertEnvironment(api.mustDB(), env)) - proj2, errp := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments) + proj2, errp := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments) require.NoError(t, errp) w := sdk.Workflow{ @@ -2414,7 +2414,7 @@ func initGetWorkflowNodeRunJobTest(t *testing.T, api *API, db *gorp.DbMap) (*sdk }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) consumer, _ := authentication.LoadConsumerByTypeAndUserID(context.TODO(), db, sdk.ConsumerLocal, u.ID, authentication.LoadConsumerOptions.WithAuthentifiedUser) @@ -2609,7 +2609,7 @@ func Test_deleteWorkflowRunsBranchHandler(t *testing.T) { consumer, _ := authentication.LoadConsumerByTypeAndUserID(context.TODO(), db, sdk.ConsumerLocal, u.ID, authentication.LoadConsumerOptions.WithAuthentifiedUser) - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -2753,7 +2753,7 @@ func Test_deleteWorkflowRunHandler(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -2875,7 +2875,7 @@ func Test_postWorkflowRunHandlerRestartOnlyFailed(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) @@ -3019,7 +3019,7 @@ func Test_postWorkflowRunHandlerRestartResync(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) require.NoError(t, errP) require.NoError(t, workflow.Insert(context.TODO(), api.mustDB(), api.Cache, *proj2, &w)) diff --git a/engine/api/workflow_test.go b/engine/api/workflow_test.go index a7e09dafdc..2bc6af3543 100644 --- a/engine/api/workflow_test.go +++ b/engine/api/workflow_test.go @@ -210,7 +210,7 @@ func Test_getWorkflowNotificationsConditionsHandler(t *testing.T) { }, } - proj2, errP := project.Load(api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) + proj2, errP := project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithGroups, project.LoadOptions.WithIntegrations) test.NoError(t, errP) test.NoError(t, workflow.Insert(context.TODO(), db, api.Cache, *proj2, &w)) @@ -1268,7 +1268,7 @@ func Test_postAndDeleteWorkflowLabelHandler(t *testing.T) { test.NoError(t, json.Unmarshal(w.Body.Bytes(), &pi)) assert.Equal(t, pname, pi.Name) - proj, err = project.Load(api.mustDB(), proj.Key, + proj, err = project.Load(context.TODO(), api.mustDB(), proj.Key, project.LoadOptions.WithApplicationWithDeploymentStrategies, project.LoadOptions.WithPipelines, project.LoadOptions.WithEnvironments, @@ -1457,7 +1457,7 @@ func TestBenchmarkGetWorkflowsWithoutAPIAsAdmin(t *testing.T) { assert.NoError(t, application.Insert(db, *proj, &app)) - prj, err := project.Load(db, proj.Key, + prj, err := project.Load(context.TODO(), db, proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications, project.LoadOptions.WithWorkflows, @@ -1524,7 +1524,7 @@ func TestBenchmarkGetWorkflowsWithAPI(t *testing.T) { assert.NoError(t, application.Insert(db, *proj, &app)) - prj, err := project.Load(db, proj.Key, + prj, err := project.Load(context.TODO(), db, proj.Key, project.LoadOptions.WithPipelines, project.LoadOptions.WithApplications, project.LoadOptions.WithWorkflows, diff --git a/engine/api/workflow_trigger.go b/engine/api/workflow_trigger.go index 5a84a6df49..fbe3941391 100644 --- a/engine/api/workflow_trigger.go +++ b/engine/api/workflow_trigger.go @@ -20,7 +20,7 @@ func (api *API) getWorkflowTriggerConditionHandler() service.Handler { name := vars["permWorkflowName"] id := FormInt(r, "nodeID") - proj, err := project.Load(api.mustDB(), key, project.LoadOptions.WithVariables, project.LoadOptions.WithIntegrations) + proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.WithVariables, project.LoadOptions.WithIntegrations) if err != nil { return sdk.WrapError(err, "unable to load project") }