Skip to content

Commit

Permalink
feat(api): add tag in event for heatmap (#3848)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored and bnjjj committed Jan 14, 2019
1 parent 0493d89 commit f1a668c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 60 deletions.
53 changes: 0 additions & 53 deletions engine/api/event/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/fatih/structs"
"github.com/go-gorp/gorp"

"github.com/ovh/cds/engine/api/cache"
"github.com/ovh/cds/sdk"
Expand Down Expand Up @@ -82,55 +81,3 @@ func Publish(payload interface{}, u *sdk.User) {
}
publishEvent(event)
}

// PublishActionBuild sends a actionBuild event
func PublishActionBuild(pb *sdk.PipelineBuild, pbJob *sdk.PipelineBuildJob) {
e := sdk.EventJob{
Version: pb.Version,
JobName: pbJob.Job.Action.Name,
JobID: pbJob.Job.PipelineActionID,
Status: sdk.StatusFromString(pbJob.Status),
Queued: pbJob.Queued.Unix(),
Start: pbJob.Start.Unix(),
Done: pbJob.Done.Unix(),
ModelName: pbJob.Model,
PipelineName: pb.Pipeline.Name,
PipelineType: pb.Pipeline.Type,
ProjectKey: pb.Pipeline.ProjectKey,
ApplicationName: pb.Application.Name,
EnvironmentName: pb.Environment.Name,
BranchName: pb.Trigger.VCSChangesBranch,
Hash: pb.Trigger.VCSChangesHash,
}

Publish(e, nil)
}

// PublishPipelineBuild sends a pipelineBuild event
func PublishPipelineBuild(db gorp.SqlExecutor, pb *sdk.PipelineBuild, previous *sdk.PipelineBuild) {
rmn := ""
rfn := ""
if pb.Application.VCSServer != "" {
rmn = pb.Application.VCSServer
rfn = pb.Application.RepositoryFullname
}

e := sdk.EventPipelineBuild{
Version: pb.Version,
BuildNumber: pb.BuildNumber,
Status: pb.Status,
Start: pb.Start.Unix(),
Done: pb.Done.Unix(),
RepositoryManagerName: rmn,
RepositoryFullname: rfn,
PipelineName: pb.Pipeline.Name,
PipelineType: pb.Pipeline.Type,
ProjectKey: pb.Pipeline.ProjectKey,
ApplicationName: pb.Application.Name,
EnvironmentName: pb.Environment.Name,
BranchName: pb.Trigger.VCSChangesBranch,
Hash: pb.Trigger.VCSChangesHash,
}

Publish(e, nil)
}
9 changes: 5 additions & 4 deletions engine/api/event/publish_workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ovh/cds/sdk/log"
)

func publishRunWorkflow(payload interface{}, key, workflowName, appName, pipName, envName string, num int64, sub int64, status string) {
func publishRunWorkflow(payload interface{}, key, workflowName, appName, pipName, envName string, num int64, sub int64, status string, tags []sdk.WorkflowRunTag) {
event := sdk.Event{
Timestamp: time.Now(),
Hostname: hostname,
Expand All @@ -27,6 +27,7 @@ func publishRunWorkflow(payload interface{}, key, workflowName, appName, pipName
WorkflowRunNum: num,
WorkflowRunNumSub: sub,
Status: status,
Tags: tags,
}
publishEvent(event)
}
Expand All @@ -42,7 +43,7 @@ func PublishWorkflowRun(wr sdk.WorkflowRun, projectKey string) {
LastModified: wr.LastModified.Unix(),
Tags: wr.Tags,
}
publishRunWorkflow(e, projectKey, wr.Workflow.Name, "", "", "", wr.Number, wr.LastSubNumber, wr.Status)
publishRunWorkflow(e, projectKey, wr.Workflow.Name, "", "", "", wr.Number, wr.LastSubNumber, wr.Status, wr.Tags)
}

// PublishWorkflowNodeRun publish event on a workflow node run
Expand Down Expand Up @@ -126,7 +127,7 @@ func PublishWorkflowNodeRun(db gorp.SqlExecutor, nr sdk.WorkflowNodeRun, w sdk.W
if sdk.StatusIsTerminated(nr.Status) {
e.Done = nr.Done.Unix()
}
publishRunWorkflow(e, w.ProjectKey, w.Name, appName, pipName, envName, nr.Number, nr.SubNumber, nr.Status)
publishRunWorkflow(e, w.ProjectKey, w.Name, appName, pipName, envName, nr.Number, nr.SubNumber, nr.Status, nil)
}

// PublishWorkflowNodeJobRun publish a WorkflowNodeJobRun
Expand All @@ -140,5 +141,5 @@ func PublishWorkflowNodeJobRun(db gorp.SqlExecutor, pkey, wname string, jr sdk.W
if sdk.StatusIsTerminated(jr.Status) {
e.Done = jr.Done.Unix()
}
publishRunWorkflow(e, pkey, wname, "", "", "", 0, 0, jr.Status)
publishRunWorkflow(e, pkey, wname, "", "", "", 0, 0, jr.Status, nil)
}
3 changes: 0 additions & 3 deletions engine/api/pipeline/pipeline_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/go-gorp/gorp"
"github.com/lib/pq"

"github.com/ovh/cds/engine/api/event"
"github.com/ovh/cds/sdk"
"github.com/ovh/cds/sdk/log"
)
Expand Down Expand Up @@ -464,8 +463,6 @@ func UpdatePipelineBuildStatusAndStage(db gorp.SqlExecutor, pb *sdk.PipelineBuil
}
}
}

event.PublishPipelineBuild(db, pb, previous)
}

pb.Status = newStatus
Expand Down
1 change: 1 addition & 0 deletions sdk/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Event struct {
WorkflowRunNum int64 `json:"workflow_run_num,omitempty"`
WorkflowRunNumSub int64 `json:"workflow_run_num_sub,omitempty"`
Status string `json:"status,omitempty"`
Tags []WorkflowRunTag `json:"tag,omitempty"`
}

// EventFilter represents filters when getting events
Expand Down

0 comments on commit f1a668c

Please sign in to comment.