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(plugins/input/jenkins): add build number field to jenkins_job measurement #8038

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -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())
}
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 @@ -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,
},
},
Expand All @@ -690,6 +700,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(87832),
"number": int64(1),
"result_code": 0,
},
},
Expand All @@ -701,6 +712,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(91558),
"number": int64(1),
"result_code": 0,
},
},
Expand All @@ -712,6 +724,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(76558),
"number": int64(4),
"result_code": 0,
},
},
Expand All @@ -723,6 +736,7 @@ func TestGatherJobs(t *testing.T) {
},
Fields: map[string]interface{}{
"duration": int64(1558),
"number": int64(1),
"result_code": 1,
},
},
Expand Down