Skip to content

Commit

Permalink
Added StatusInt to show success/failure in integers for Grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
jlehtimaki committed Dec 1, 2020
1 parent 1107100 commit 21fa145
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
28 changes: 17 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ func processBuilds(repo *dronecli.Repo, builds []*dronecli.Build) []types.Point
for _, stage := range buildInfo.Stages {
// Loop through build info stages and save the results into DB
// Don't save running pipelines and set BuildState integer according to the status because of Grafana
var waittime int64
var waitTime int64
statusInt := int64(0)
if stage.Started == 0 {
waittime = stage.Updated - stage.Created
waitTime = stage.Updated - stage.Created
} else {
waittime = stage.Started - stage.Created
waitTime = stage.Started - stage.Created
}

var duration int64
Expand All @@ -214,15 +215,20 @@ func processBuilds(repo *dronecli.Repo, builds []*dronecli.Build) []types.Point
duration = stage.Stopped - stage.Started
}

if stage.Status == "success" {
statusInt = 1
}

points = append(points, &types.Stage{
Time: time.Unix(stage.Started, 0),
WaitTime: waittime,
Duration: duration,
OS: stage.OS,
Arch: stage.Arch,
Status: stage.Status,
Name: stage.Name,
BuildId: build.Number,
Time: time.Unix(stage.Started, 0),
WaitTime: waitTime,
Duration: duration,
OS: stage.OS,
Arch: stage.Arch,
Status: stage.Status,
StatusInt: statusInt,
Name: stage.Name,
BuildId: build.Number,
Tags: map[string]string{
"DroneAddress": drone.GetHost(),
"Slug": repo.Slug,
Expand Down
25 changes: 13 additions & 12 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@ func (p Build) GetMeasurement() string {
}

type Stage struct {
Time time.Time
BuildId int64
WaitTime int64
Duration int64
Created int64
Started int64
Stopped int64
OS string
Arch string
Status string
Name string
Tags Tags
Time time.Time
BuildId int64
WaitTime int64
Duration int64
Created int64
Started int64
Stopped int64
OS string
Arch string
Status string
StatusInt int64
Name string
Tags Tags
}

func (p Stage) GetTime() time.Time {
Expand Down

0 comments on commit 21fa145

Please sign in to comment.