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(service): enable tracing on all services #3135

Merged
merged 9 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions engine/api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func selectDeleteAdminServiceCallHandler(api *API, method string) Handler {
}

query := r.FormValue("query")
btes, code, err := services.DoRequest(srvs, method, query, nil)
btes, code, err := services.DoRequest(ctx, srvs, method, query, nil)
if err != nil {
sdkErr := sdk.Error{
Status: code,
Expand Down Expand Up @@ -126,7 +126,7 @@ func putPostAdminServiceCallHandler(api *API, method string) Handler {
}
defer r.Body.Close()

btes, code, err := services.DoRequest(srvs, method, query, body)
btes, code, err := services.DoRequest(ctx, srvs, method, query, body)
if err != nil {
sdkErr := sdk.Error{
Status: code,
Expand Down
7 changes: 1 addition & 6 deletions engine/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/ovh/cds/engine/api/secret"
"github.com/ovh/cds/engine/api/services"
"github.com/ovh/cds/engine/api/sessionstore"
"github.com/ovh/cds/engine/api/tracing"
"github.com/ovh/cds/engine/api/warning"
"github.com/ovh/cds/engine/api/worker"
"github.com/ovh/cds/engine/api/workflow"
Expand Down Expand Up @@ -144,7 +143,6 @@ type Configuration struct {
} `toml:"vault"`
Providers []ProviderConfiguration `toml:"providers" comment:"###########################\n CDS Providers Settings \n##########################"`
Services []ServiceConfiguration `toml:"services" comment:"###########################\n CDS Providers Settings \n##########################"`
Tracing tracing.Configuration `toml:"tracing" comment:"###########################\n CDS Tracing Settings \n##########################"`
DefaultOS string `toml:"defaultOS" default:"linux" comment:"if no model and os/arch is specified in your job's requirements then spawn worker on this operating system (example: freebsd, linux, windows)"`
DefaultArch string `toml:"defaultArch" default:"amd64" comment:"if no model and no os/arch is specified in your job's requirements then spawn worker on this architecture (example: amd64, arm, 386)"`
}
Expand Down Expand Up @@ -217,6 +215,7 @@ func (a *API) ApplyConfiguration(config interface{}) error {
}

a.Type = services.TypeAPI
a.ServiceName = "cds-api"

return nil
}
Expand Down Expand Up @@ -527,10 +526,6 @@ func (a *API) Serve(ctx context.Context) error {
return fmt.Errorf("cannot connect to cache store: %v", errCache)
}

if err := tracing.Init(a.Config.Tracing); err != nil {
return fmt.Errorf("Unable to start tracing exporter: %v", err)
}

log.Info("Initializing HTTP router")
a.Router = &Router{
Mux: mux.NewRouter(),
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 @@ -13,7 +13,7 @@ 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.Router.PostMiddlewares = append(api.Router.PostMiddlewares, api.deletePermissionMiddleware, api.tracingPostMiddleware)
api.Router.PostMiddlewares = append(api.Router.PostMiddlewares, api.deletePermissionMiddleware, TracingPostMiddleware)

api.eventsBroker = &eventsBroker{
cache: api.Cache,
Expand Down
10 changes: 5 additions & 5 deletions engine/api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,12 @@ func (api *API) getApplicationBranchHandler() Handler {
var branches []sdk.VCSBranch
if app.RepositoryFullname != "" && app.VCSServer != "" {
vcsServer := repositoriesmanager.GetProjectVCSServer(proj, app.VCSServer)
client, erra := repositoriesmanager.AuthorizedClient(api.mustDB(), api.Cache, vcsServer)
client, erra := repositoriesmanager.AuthorizedClient(ctx, api.mustDB(), api.Cache, vcsServer)
if erra != nil {
return sdk.WrapError(sdk.ErrNoReposManagerClientAuth, "getApplicationBranchHandler> Cannot get client got %s %s : %s", projectKey, app.VCSServer, erra)
}
if remote != "" && remote != app.RepositoryFullname {
brs, errB := client.Branches(remote)
brs, errB := client.Branches(ctx, remote)
if errB != nil {
return sdk.WrapError(errB, "getApplicationBranchHandler> Cannot get branches from repository %s", remote)
}
Expand All @@ -405,7 +405,7 @@ func (api *API) getApplicationBranchHandler() Handler {
}
} else {
var errb error
branches, errb = client.Branches(app.RepositoryFullname)
branches, errb = client.Branches(ctx, app.RepositoryFullname)
if errb != nil {
return sdk.WrapError(errb, "getApplicationBranchHandler> Cannot get branches from repository %s: %s", app.RepositoryFullname, errb)
}
Expand Down Expand Up @@ -444,12 +444,12 @@ func (api *API) getApplicationRemoteHandler() Handler {
var prs []sdk.VCSPullRequest
if app.RepositoryFullname != "" && app.VCSServer != "" {
vcsServer := repositoriesmanager.GetProjectVCSServer(proj, app.VCSServer)
client, erra := repositoriesmanager.AuthorizedClient(api.mustDB(), api.Cache, vcsServer)
client, erra := repositoriesmanager.AuthorizedClient(ctx, api.mustDB(), api.Cache, vcsServer)
if erra != nil {
return sdk.WrapError(sdk.ErrNoReposManagerClientAuth, "getApplicationRemoteHandler> Cannot get client got %s %s : %s", projectKey, app.VCSServer, erra)
}
var errb error
prs, errb = client.PullRequests(app.RepositoryFullname)
prs, errb = client.PullRequests(ctx, app.RepositoryFullname)
if errb != nil {
return sdk.WrapError(errb, "getApplicationRemoteHandler> Cannot get branches from repository %s: %s", app.RepositoryFullname, errb)
}
Expand Down
4 changes: 2 additions & 2 deletions engine/api/application/application_pipeline_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func TriggerPipeline(tx gorp.SqlExecutor, store cache.Store, h sdk.Hook, branch
// Get commit message to check if we have to skip the build
if a.VCSServer != "" {
vcsServer := repositoriesmanager.GetProjectVCSServer(projectData, a.VCSServer)
client, _ := repositoriesmanager.AuthorizedClient(tx, store, vcsServer)
client, _ := repositoriesmanager.AuthorizedClient(context.Background(), tx, store, vcsServer)
if client != nil {
commit, err := client.Commit(a.RepositoryFullname, hash)
commit, err := client.Commit(context.Background(), a.RepositoryFullname, hash)
if err != nil {
log.Warning("hook> can't get commit %s from %s on %s : %s", hash, a.RepositoryFullname, a.VCSServer, err)
}
Expand Down
14 changes: 7 additions & 7 deletions engine/api/ascode.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func (api *API) postImportAsCodeHandler() Handler {
}

vcsServer := repositoriesmanager.GetProjectVCSServer(p, ope.VCSServer)
client, erra := repositoriesmanager.AuthorizedClient(api.mustDB(), api.Cache, vcsServer)
client, erra := repositoriesmanager.AuthorizedClient(ctx, api.mustDB(), api.Cache, vcsServer)
if erra != nil {
return sdk.WrapError(sdk.ErrNoReposManagerClientAuth, "postImportAsCodeHandler> Cannot get client for %s %s : %s", key, ope.VCSServer, erra)
}

branches, errB := client.Branches(ope.RepoFullName)
branches, errB := client.Branches(ctx, ope.RepoFullName)
if errB != nil {
return sdk.WrapError(errB, "postImportAsCodeHandler> Cannot list branches for %s/%s", ope.VCSServer, ope.RepoFullName)
}
Expand All @@ -68,7 +68,7 @@ func (api *API) postImportAsCodeHandler() Handler {
}
}

if err := workflow.PostRepositoryOperation(api.mustDB(), api.Cache, *p, ope); err != nil {
if err := workflow.PostRepositoryOperation(ctx, api.mustDB(), api.Cache, *p, ope); err != nil {
return sdk.WrapError(err, "postImportAsCodeHandler> Cannot create repository operation")
}
ope.RepositoryStrategy.SSHKeyContent = ""
Expand All @@ -89,7 +89,7 @@ func (api *API) getImportAsCodeHandler() Handler {

var ope = new(sdk.Operation)
ope.UUID = uuid
if err := workflow.GetRepositoryOperation(api.mustDB(), api.Cache, ope); err != nil {
if err := workflow.GetRepositoryOperation(ctx, api.mustDB(), api.Cache, ope); err != nil {
return sdk.WrapError(err, "getImportAsCodeHandler> Cannot get repository operation status")
}
return WriteJSON(w, ope, http.StatusOK)
Expand Down Expand Up @@ -127,7 +127,7 @@ func (api *API) postPerformImportAsCodeHandler() Handler {
var ope = new(sdk.Operation)
ope.UUID = uuid

if err := workflow.GetRepositoryOperation(api.mustDB(), api.Cache, ope); err != nil {
if err := workflow.GetRepositoryOperation(ctx, api.mustDB(), api.Cache, ope); err != nil {
return sdk.WrapError(err, "postPerformImportAsCodeHandler> Unable to get repository operation")
}

Expand Down Expand Up @@ -161,11 +161,11 @@ func (api *API) postPerformImportAsCodeHandler() Handler {
// Grant CDS as a repository collaborator
// TODO for this moment, this step is not mandatory. If it's failed, continue the ascode process
vcsServer := repositoriesmanager.GetProjectVCSServer(proj, ope.VCSServer)
client, erra := repositoriesmanager.AuthorizedClient(api.mustDB(), api.Cache, vcsServer)
client, erra := repositoriesmanager.AuthorizedClient(ctx, api.mustDB(), api.Cache, vcsServer)
if erra != nil {
log.Error("postPerformImportAsCodeHandler> Cannot get client for %s %s : %s", proj.Key, ope.VCSServer, erra)
} else {
if err := client.GrantReadPermission(ope.RepoFullName); err != nil {
if err := client.GrantReadPermission(ctx, ope.RepoFullName); err != nil {
log.Error("postPerformImportAsCodeHandler> Unable to grant CDS a repository %s/%s collaborator : %v", ope.VCSServer, ope.RepoFullName, err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions engine/api/event/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func PushInElasticSearch(c context.Context, db gorp.SqlExecutor, store cache.Sto
continue
}
e.Payload = nil
code, errD := services.DoJSONRequest(esServices, "POST", "/events", e, nil)
code, errD := services.DoJSONRequest(context.Background(), esServices, "POST", "/events", e, nil)
if code >= 400 || errD != nil {
log.Error("PushInElasticSearch> Unable to send event %s to elasticsearch [%d]: %v", e.EventType, code, errD)
continue
Expand All @@ -50,15 +50,15 @@ func PushInElasticSearch(c context.Context, db gorp.SqlExecutor, store cache.Sto
}
}

// GetEvent retrieves events from elasticsearch
// GetEvents retrieves events from elasticsearch
func GetEvents(db gorp.SqlExecutor, store cache.Store, filters sdk.EventFilter) ([]json.RawMessage, error) {
srvs, err := services.FindByType(db, services.TypeElasticsearch)
if err != nil {
return nil, sdk.WrapError(err, "GetEvent> Unable to get elasticsearch service")
}

var esEvents []elastic.SearchHit
if _, err := services.DoJSONRequest(srvs, "GET", "/events", filters, &esEvents); err != nil {
if _, err := services.DoJSONRequest(context.Background(), srvs, "GET", "/events", filters, &esEvents); err != nil {
return nil, sdk.WrapError(err, "GetEvent> Unable to get events")
}

Expand Down
2 changes: 1 addition & 1 deletion engine/api/grpc_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (h *grpcHandlers) SendResult(c context.Context, res *sdk.Result) (*empty.Em
}

workflowRuns, workflowNodeRuns := workflow.GetWorkflowRunEventData(report, p.Key)
workflow.ResyncNodeRunsWithCommits(db, h.store, p, workflowNodeRuns)
workflow.ResyncNodeRunsWithCommits(c, db, h.store, p, workflowNodeRuns)

go workflow.SendEvent(db, workflowRuns, workflowNodeRuns, p.Key)

Expand Down
10 changes: 5 additions & 5 deletions engine/api/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,29 +421,29 @@ func (api *API) getHookPollingVCSEvents() Handler {

//get the client for the repositories manager
vcsServer := repositoriesmanager.GetProjectVCSServer(proj, vcsServerParam)
client, errR := repositoriesmanager.AuthorizedClient(api.mustDB(), api.Cache, vcsServer)
client, errR := repositoriesmanager.AuthorizedClient(ctx, api.mustDB(), api.Cache, vcsServer)
if errR != nil {
return sdk.WrapError(errR, "getHookPollingVCSEvents> Unable to get client for %s %s", proj.Key, vcsServerParam)
}

//Check if the polling if disabled
if info, err := repositoriesmanager.GetPollingInfos(client, *proj); err != nil {
if info, err := repositoriesmanager.GetPollingInfos(ctx, client, *proj); err != nil {
return sdk.WrapError(err, "getHookPollingVCSEvents> cannot check if polling is enabled")
} else if info.PollingDisabled || !info.PollingSupported {
log.Info("getHookPollingVCSEvents> %s polling is disabled", vcsServer.Name)
return WriteJSON(w, nil, http.StatusOK)
}

events, pollingDelay, err := client.GetEvents(h.Config["repoFullName"].Value, lastExec)
events, pollingDelay, err := client.GetEvents(ctx, h.Config["repoFullName"].Value, lastExec)
if err != nil && err.Error() != "No new events" {
return sdk.WrapError(err, "Polling> Unable to get events for %s %s", proj.Key, vcsServerParam)
}
pushEvents, err := client.PushEvents(h.Config["repoFullName"].Value, events)
pushEvents, err := client.PushEvents(ctx, h.Config["repoFullName"].Value, events)
if err != nil {
return sdk.WrapError(err, "getHookPollingVCSEvent> ")
}

pullRequestEvents, err := client.PullRequestEvents(h.Config["repoFullName"].Value, events)
pullRequestEvents, err := client.PullRequestEvents(ctx, h.Config["repoFullName"].Value, events)
if err != nil {
return sdk.WrapError(err, "getHookPollingVCSEvent> ")
}
Expand Down
7 changes: 4 additions & 3 deletions engine/api/hook/hook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hook

import (
"context"
"crypto/rand"
"database/sql"
"encoding/hex"
Expand Down Expand Up @@ -252,13 +253,13 @@ func CreateHook(tx gorp.SqlExecutor, store cache.Store, proj *sdk.Project, rm, r
if server == nil {
return nil, fmt.Errorf("Unable to find repository manager")
}
client, err := repositoriesmanager.AuthorizedClient(tx, store, server)
client, err := repositoriesmanager.AuthorizedClient(context.Background(), tx, store, server)
if err != nil {
return nil, sdk.WrapError(err, "CreateHook> Cannot get client, got %s %s", proj.Key, rm)
}

//Check if the webhooks if disabled
if info, err := repositoriesmanager.GetWebhooksInfos(client); err != nil {
if info, err := repositoriesmanager.GetWebhooksInfos(context.Background(), client); err != nil {
return nil, err
} else if !info.WebhooksSupported || info.WebhooksDisabled {
return nil, sdk.WrapError(sdk.NewError(sdk.ErrForbidden, fmt.Errorf("Webhooks are not supported on %s", server.Name)), "CreateHook>")
Expand Down Expand Up @@ -300,7 +301,7 @@ func CreateHook(tx gorp.SqlExecutor, store cache.Store, proj *sdk.Project, rm, r

log.Info("CreateHook> will create %+v", hook)

if err := client.CreateHook(repoFullName, &hook); err != nil {
if err := client.CreateHook(context.Background(), repoFullName, &hook); err != nil {
log.Warning("Cannot create hook on repository manager: %s", err)
if strings.Contains(err.Error(), "Not yet implemented") {
return nil, sdk.WrapError(sdk.ErrNotImplemented, "CreateHook> Cannot create hook on repository manager")
Expand Down
4 changes: 2 additions & 2 deletions engine/api/migrate/clean_old_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func cleanApplicationHook(db *gorp.DbMap, store cache.Store, wg *sync.WaitGroup,
if vcsServer == nil {
return
}
client, err := repositoriesmanager.AuthorizedClient(db, store, vcsServer)
client, err := repositoriesmanager.AuthorizedClient(context.Background(), db, store, vcsServer)
if err != nil {
log.Error("cleanApplicationHook> Cannot connect to repository manager: %s", err)
return
Expand Down Expand Up @@ -167,7 +167,7 @@ func cleanApplicationHook(db *gorp.DbMap, store cache.Store, wg *sync.WaitGroup,
Workflow: false,
}

if err := client.DeleteHook(app.RepositoryFullname, vcsHook); err != nil {
if err := client.DeleteHook(context.Background(), app.RepositoryFullname, vcsHook); err != nil {
log.Error("cleanApplicationHook> Cannot delete hooks from repomanager: %s / %s", vcsServer.Name, app.RepositoryFullname)
return
}
Expand Down
8 changes: 4 additions & 4 deletions engine/api/migrate/migrate_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ func ToWorkflow(db gorp.SqlExecutor, store cache.Store, cdTree []sdk.CDPipeline,
newW.Root = n

if force {
w, err := workflow.Load(context.TODO(), db, store, proj, newW.Name, u, workflow.LoadOptions{})
w, err := workflow.Load(context.Background(), db, store, proj, newW.Name, u, workflow.LoadOptions{})
if err == nil {
if errD := workflow.Delete(db, store, proj, w); errD != nil {
if errD := workflow.Delete(context.Background(), db, store, proj, w); errD != nil {
return nil, sdk.WrapError(errD, "MigrateToWorkflow workflow.Load>")
}
}
}

if newW.Root != nil && newW.Root.Context != nil && (newW.Root.Context.Application != nil || newW.Root.Context.ApplicationID != 0) {
var err error
if newW.Root.Context.DefaultPayload, err = workflow.DefaultPayload(db, store, proj, u, &newW); err != nil {
if newW.Root.Context.DefaultPayload, err = workflow.DefaultPayload(context.Background(), db, store, proj, u, &newW); err != nil {
return nil, sdk.WrapError(err, "migratePipeline> error compute defaut payload: %s", err)
}
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func ToWorkflow(db gorp.SqlExecutor, store cache.Store, cdTree []sdk.CDPipeline,
newW.ID = oldW.ID

// then register (node is updated in HookRegistration)
if errHr := workflow.HookRegistration(db, store, nil, *oldW, proj); errHr != nil {
if errHr := workflow.HookRegistration(context.Background(), db, store, nil, *oldW, proj); errHr != nil {
return nil, sdk.WrapError(errHr, "migratePipeline> Cannot register hook 2")
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions engine/api/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ func (api *API) getPipelineCommitsHandler() Handler {

//Get the RepositoriesManager Client
vcsServer := repositoriesmanager.GetProjectVCSServer(proj, app.VCSServer)
client, errclient := repositoriesmanager.AuthorizedClient(api.mustDB(), api.Cache, vcsServer)
client, errclient := repositoriesmanager.AuthorizedClient(ctx, api.mustDB(), api.Cache, vcsServer)
if errclient != nil {
return sdk.WrapError(errclient, "getPipelineCommitsHandler> Cannot get client")
}
Expand All @@ -996,7 +996,7 @@ func (api *API) getPipelineCommitsHandler() Handler {

//If we are lucky, return a true diff
var errcommits error
commits, errcommits = client.Commits(app.RepositoryFullname, pbs[0].Trigger.VCSChangesBranch, pbs[0].Trigger.VCSChangesHash, hash)
commits, errcommits = client.Commits(ctx, app.RepositoryFullname, pbs[0].Trigger.VCSChangesBranch, pbs[0].Trigger.VCSChangesHash, hash)
if errcommits != nil {
return sdk.WrapError(errcommits, "getPipelineBuildCommitsHandler> Cannot get commits")
}
Expand Down
4 changes: 2 additions & 2 deletions engine/api/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func LoadPipeline(db gorp.SqlExecutor, projectKey, name string, deep bool) (*sdk
func LoadPipelineByID(ctx context.Context, db gorp.SqlExecutor, pipelineID int64, deep bool) (*sdk.Pipeline, error) {
var end func()
ctx, end = tracing.Span(ctx, "pipeline.LoadPipelineByID",
tracing.Tag("pipeline_id", pipelineID),
tracing.Tag("deep", deep),
tracing.Tag(tracing.TagPipelineID, pipelineID),
tracing.Tag(tracing.TagPipelineDeep, deep),
)
defer end()

Expand Down
Loading