Skip to content

Commit

Permalink
Multiple escaping occurs on Jenkins URLs at certain folder depth (#8048)
Browse files Browse the repository at this point in the history
Co-author: @hansnqyr
  • Loading branch information
medains authored Oct 7, 2020
1 parent 74fd427 commit 7f7703b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugins/inputs/jenkins/jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ type jobRequest struct {
}

func (jr jobRequest) combined() []string {
return append(jr.parents, jr.name)
path := make([]string, len(jr.parents))
copy(path, jr.parents)
return append(path, jr.name)
}

func (jr jobRequest) combinedEscaped() []string {
Expand Down
53 changes: 53 additions & 0 deletions plugins/inputs/jenkins/jenkins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,59 @@ func TestGatherJobs(t *testing.T) {
},
},
},
{
name: "gather metrics for nested jobs with space exercising append slice behaviour",
input: mockHandler{
responseMap: map[string]interface{}{
"/api/json": &jobResponse{
Jobs: []innerJob{
{Name: "l1"},
},
},
"/job/l1/api/json": &jobResponse{
Jobs: []innerJob{
{Name: "l2"},
},
},
"/job/l1/job/l2/api/json": &jobResponse{
Jobs: []innerJob{
{Name: "job 1"},
},
},
"/job/l1/job/l2/job/job%201/api/json": &jobResponse{
Jobs: []innerJob{
{Name: "job 2"},
},
},
"/job/l1/job/l2/job/job%201/job/job%202/api/json": &jobResponse{
LastBuild: jobBuild{
Number: 3,
},
},
"/job/l1/job/l2/job/job%201/job/job%202/3/api/json": &buildResponse{
Building: false,
Result: "SUCCESS",
Duration: 25558,
Timestamp: (time.Now().Unix() - int64(time.Minute.Seconds())) * 1000,
},
},
},
output: &testutil.Accumulator{
Metrics: []*testutil.Metric{
{
Tags: map[string]string{
"name": "job 2",
"parents": "l1/l2/job 1",
"result": "SUCCESS",
},
Fields: map[string]interface{}{
"duration": int64(25558),
"result_code": 0,
},
},
},
},
},
{
name: "gather sub jobs, jobs filter",
input: mockHandler{
Expand Down

0 comments on commit 7f7703b

Please sign in to comment.