Skip to content

Commit

Permalink
Jolokia2 skips over 404 read responses
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmei committed Jul 18, 2017
1 parent 82185cb commit bdc7afb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
7 changes: 6 additions & 1 deletion plugins/inputs/jolokia2/gatherer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ func (g *Gatherer) gatherPoints(metric Metric, responses []ReadResponse) []point
points := make([]point, 0)

for _, response := range responses {
if response.Status != 200 {
switch response.Status {
case 200:
break
case 404:
continue
default:
g.accumulator.AddError(fmt.Errorf("Unexpected status in response from target %s: %d",
response.RequestTarget, response.Status))
continue
Expand Down
55 changes: 55 additions & 0 deletions plugins/inputs/jolokia2/jolokia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,61 @@ func TestJolokia2_ObjectValues(t *testing.T) {
})
}

func TestJolokia2_StatusCodes(t *testing.T) {
config := `
[[inputs.jolokia2]]
urls = ["%s"]
[[inputs.jolokia2.metric]]
name = "ok"
mbean = "ok"
[[inputs.jolokia2.metric]]
name = "not_found"
mbean = "not_found"
[[inputs.jolokia2.metric]]
name = "unknown"
mbean = "unknown"`

response := `[{
"request": {
"mbean": "ok",
"type": "read"
},
"value": 1,
"status": 200
}, {
"request": {
"mbean": "not_found",
"type": "read"
},
"status": 404
}, {
"request": {
"mbean": "unknown",
"type": "read"
},
"status": 500
}]`

server := setupServer(http.StatusOK, response)
defer server.Close()
jolokia := setupJolokia(t, fmt.Sprintf(config, server.URL))

var acc testutil.Accumulator
assert.NoError(t, jolokia.Gather(&acc))

acc.AssertContainsTaggedFields(t, "ok", map[string]interface{}{
"value": 1.0,
}, map[string]string{
"jolokia_agent_url": server.URL,
})

acc.AssertDoesNotContainMeasurement(t, "not_found")
acc.AssertDoesNotContainMeasurement(t, "unknown")
}

func TestJolokia2_TagRenaming(t *testing.T) {
config := `
[[inputs.jolokia2]]
Expand Down

0 comments on commit bdc7afb

Please sign in to comment.