Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): improve tracing #5286

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/api/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion engine/api/api_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions engine/api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions engine/api/application_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion engine/api/application_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
6 changes: 3 additions & 3 deletions engine/api/ascode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion engine/api/ascode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions engine/api/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions engine/api/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions engine/api/environment_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion engine/api/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions engine/api/observability/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
Expand All @@ -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()
}
}
Expand Down
12 changes: 6 additions & 6 deletions engine/api/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion engine/api/pipeline/pipeline_importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions engine/api/pipeline_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions engine/api/pipeline_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion engine/api/pipeline_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading