From 71280e7df04c244bb8dca55ae6afc2614179dc31 Mon Sep 17 00:00:00 2001 From: Ales Pour Date: Wed, 26 Aug 2020 16:54:40 +0200 Subject: [PATCH] feat: add build number field to jenkins_job measurement --- plugins/inputs/jenkins/README.md | 1 + plugins/inputs/jenkins/jenkins.go | 3 +++ plugins/inputs/jenkins/jenkins_test.go | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/plugins/inputs/jenkins/README.md b/plugins/inputs/jenkins/README.md index f4e9f94ac22a7..dc9889fe628fc 100644 --- a/plugins/inputs/jenkins/README.md +++ b/plugins/inputs/jenkins/README.md @@ -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: diff --git a/plugins/inputs/jenkins/jenkins.go b/plugins/inputs/jenkins/jenkins.go index f4882b1dc0bf2..6cc2115e32f9b 100644 --- a/plugins/inputs/jenkins/jenkins.go +++ b/plugins/inputs/jenkins/jenkins.go @@ -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"` } @@ -436,6 +437,7 @@ type jobRequest struct { name string parents []string layer int + number int64 } func (jr jobRequest) combined() []string { @@ -471,6 +473,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()) } diff --git a/plugins/inputs/jenkins/jenkins_test.go b/plugins/inputs/jenkins/jenkins_test.go index b8284fc0d3348..8cc8a59ad7e02 100644 --- a/plugins/inputs/jenkins/jenkins_test.go +++ b/plugins/inputs/jenkins/jenkins_test.go @@ -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, }, }, @@ -549,6 +551,7 @@ func TestGatherJobs(t *testing.T) { }, Fields: map[string]interface{}{ "duration": int64(25558), + "number": int64(3), "result_code": 0, }, }, @@ -559,6 +562,7 @@ func TestGatherJobs(t *testing.T) { }, Fields: map[string]interface{}{ "duration": int64(1558), + "number": int64(1), "result_code": 1, }, }, @@ -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, }, }, @@ -596,6 +601,7 @@ func TestGatherJobs(t *testing.T) { }, Fields: map[string]interface{}{ "duration": int64(25558), + "number": int64(3), "result_code": 0, }, }, @@ -658,24 +664,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, }, }, @@ -690,6 +700,7 @@ func TestGatherJobs(t *testing.T) { }, Fields: map[string]interface{}{ "duration": int64(87832), + "number": int64(1), "result_code": 0, }, }, @@ -701,6 +712,7 @@ func TestGatherJobs(t *testing.T) { }, Fields: map[string]interface{}{ "duration": int64(91558), + "number": int64(1), "result_code": 0, }, }, @@ -712,6 +724,7 @@ func TestGatherJobs(t *testing.T) { }, Fields: map[string]interface{}{ "duration": int64(76558), + "number": int64(4), "result_code": 0, }, }, @@ -723,6 +736,7 @@ func TestGatherJobs(t *testing.T) { }, Fields: map[string]interface{}{ "duration": int64(1558), + "number": int64(1), "result_code": 1, }, },