Skip to content

Commit

Permalink
feat: add build number field to jenkins_job measurement (influxdata#8038
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alespour authored Dec 10, 2020
1 parent 97de398 commit d3031a4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/inputs/jenkins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ This plugin does not require a plugin on jenkins and it makes use of Jenkins API
- port
- fields:
- duration (ms)
- number
- result_code (0 = SUCCESS, 1 = FAILURE, 2 = NOT_BUILD, 3 = UNSTABLE, 4 = ABORTED)

### Sample Queries:
Expand Down
3 changes: 3 additions & 0 deletions plugins/inputs/jenkins/jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ type jobBuild struct {
type buildResponse struct {
Building bool `json:"building"`
Duration int64 `json:"duration"`
Number int64 `json:"number"`
Result string `json:"result"`
Timestamp int64 `json:"timestamp"`
}
Expand All @@ -436,6 +437,7 @@ type jobRequest struct {
name string
parents []string
layer int
number int64
}

func (jr jobRequest) combined() []string {
Expand Down Expand Up @@ -473,6 +475,7 @@ func (j *Jenkins) gatherJobBuild(jr jobRequest, b *buildResponse, acc telegraf.A
fields := make(map[string]interface{})
fields["duration"] = b.Duration
fields["result_code"] = mapResultCode(b.Result)
fields["number"] = b.Number

acc.AddFields(measurementJob, fields, tags, b.GetTimestamp())
}
Expand Down
14 changes: 14 additions & 0 deletions plugins/inputs/jenkins/jenkins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,14 @@ func TestGatherJobs(t *testing.T) {
Building: false,
Result: "SUCCESS",
Duration: 25558,
Number: 3,
Timestamp: (time.Now().Unix() - int64(time.Minute.Seconds())) * 1000,
},
"/job/job2/1/api/json": &buildResponse{
Building: false,
Result: "FAILURE",
Duration: 1558,
Number: 1,
Timestamp: (time.Now().Unix() - int64(time.Minute.Seconds())) * 1000,
},
},
Expand All @@ -549,6 +551,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(25558),
"number": int64(3),
"result_code": 0,
},
},
Expand All @@ -559,6 +562,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(1558),
"number": int64(1),
"result_code": 1,
},
},
Expand All @@ -583,6 +587,7 @@ func TestGatherJobs(t *testing.T) {
Building: false,
Result: "SUCCESS",
Duration: 25558,
Number: 3,
Timestamp: (time.Now().Unix() - int64(time.Minute.Seconds())) * 1000,
},
},
Expand All @@ -596,6 +601,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(25558),
"number": int64(3),
"result_code": 0,
},
},
Expand Down Expand Up @@ -711,24 +717,28 @@ func TestGatherJobs(t *testing.T) {
Building: false,
Result: "FAILURE",
Duration: 1558,
Number: 1,
Timestamp: (time.Now().Unix() - int64(time.Minute.Seconds())) * 1000,
},
"/job/apps/job/k8s-cloud/job/PR-101/4/api/json": &buildResponse{
Building: false,
Result: "SUCCESS",
Duration: 76558,
Number: 4,
Timestamp: (time.Now().Unix() - int64(time.Minute.Seconds())) * 1000,
},
"/job/apps/job/k8s-cloud/job/PR-100/1/api/json": &buildResponse{
Building: false,
Result: "SUCCESS",
Duration: 91558,
Number: 1,
Timestamp: (time.Now().Unix() - int64(time.Minute.Seconds())) * 1000,
},
"/job/apps/job/k8s-cloud/job/PR%201/1/api/json": &buildResponse{
Building: false,
Result: "SUCCESS",
Duration: 87832,
Number: 1,
Timestamp: (time.Now().Unix() - int64(time.Minute.Seconds())) * 1000,
},
},
Expand All @@ -743,6 +753,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(87832),
"number": int64(1),
"result_code": 0,
},
},
Expand All @@ -754,6 +765,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(91558),
"number": int64(1),
"result_code": 0,
},
},
Expand All @@ -765,6 +777,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(76558),
"number": int64(4),
"result_code": 0,
},
},
Expand All @@ -776,6 +789,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(1558),
"number": int64(1),
"result_code": 1,
},
},
Expand Down

0 comments on commit d3031a4

Please sign in to comment.