Skip to content

Commit b540946

Browse files
glintonJean-Louis Dupond
authored andcommitted
Don't add unserializable fields to jolokia2 input (influxdata#4930)
1 parent c051b1a commit b540946

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

plugins/inputs/jolokia2/examples/zookeeper.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
urls = ["http://localhost:8080/jolokia"]
33
name_prefix = "zk_"
44

5-
[[inputs.jolokia2_agent.metrics]]
5+
[[inputs.jolokia2_agent.metric]]
66
name = "quorum"
77
mbean = "org.apache.ZooKeeperService:name0=*"
88
tag_keys = ["name0"]
99

10-
[[inputs.jolokia2_agent.metrics]]
10+
[[inputs.jolokia2_agent.metric]]
1111
name = "leader"
1212
mbean = "org.apache.ZooKeeperService:name0=*,name1=*,name2=Leader"
1313
tag_keys = ["name1"]
1414

15-
[[inputs.jolokia2_agent.metrics]]
15+
[[inputs.jolokia2_agent.metric]]
1616
name = "follower"
1717
mbean = "org.apache.ZooKeeperService:name0=*,name1=*,name2=Follower"
1818
tag_keys = ["name1"]

plugins/inputs/jolokia2/jolokia_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ func TestJolokia2_ObjectValues(t *testing.T) {
143143
[[jolokia2_agent.metric]]
144144
name = "object_with_key_pattern"
145145
mbean = "object_with_key_pattern:test=*"
146-
tag_keys = ["test"]`
146+
tag_keys = ["test"]
147+
148+
[[jolokia2_agent.metric]]
149+
name = "ColumnFamily"
150+
mbean = "org.apache.cassandra.metrics:keyspace=*,name=EstimatedRowSizeHistogram,scope=schema_columns,type=ColumnFamily"
151+
tag_keys = ["keyspace", "name", "scope"]`
147152

148153
response := `[{
149154
"request": {
@@ -214,7 +219,20 @@ func TestJolokia2_ObjectValues(t *testing.T) {
214219
}
215220
},
216221
"status": 200
217-
}]`
222+
}, {
223+
"request": {
224+
"mbean": "org.apache.cassandra.metrics:keyspace=*,name=EstimatedRowSizeHistogram,scope=schema_columns,type=ColumnFamily",
225+
"type": "read"
226+
},
227+
"value": {
228+
"org.apache.cassandra.metrics:keyspace=system,name=EstimatedRowSizeHistogram,scope=schema_columns,type=ColumnFamily": {
229+
"Value": [
230+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
231+
]
232+
}
233+
},
234+
"status": 200
235+
}]`
218236

219237
server := setupServer(http.StatusOK, response)
220238
defer server.Close()
@@ -730,6 +748,20 @@ func TestJolokia2_ProxyTargets(t *testing.T) {
730748
})
731749
}
732750

751+
func TestFillFields(t *testing.T) {
752+
complex := map[string]interface{}{"Value": []interface{}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
753+
var scalar interface{}
754+
scalar = []interface{}{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
755+
756+
results := map[string]interface{}{}
757+
newPointBuilder(Metric{Name: "test", Mbean: "complex"}, []string{"this", "that"}, "/").fillFields("", complex, results)
758+
assert.Equal(t, map[string]interface{}{}, results)
759+
760+
results = map[string]interface{}{}
761+
newPointBuilder(Metric{Name: "test", Mbean: "scalar"}, []string{"this", "that"}, "/").fillFields("", scalar, results)
762+
assert.Equal(t, map[string]interface{}{}, results)
763+
}
764+
733765
func setupServer(status int, resp string) *httptest.Server {
734766
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
735767
w.WriteHeader(http.StatusOK)

plugins/inputs/jolokia2/point_builder.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ func (pb *pointBuilder) fillFields(name string, value interface{}, fieldMap map[
158158
if valueMap, ok := value.(map[string]interface{}); ok {
159159
// keep going until we get to something that is not a map
160160
for key, innerValue := range valueMap {
161-
var innerName string
161+
if _, ok := innerValue.([]interface{}); ok {
162+
continue
163+
}
162164

165+
var innerName string
163166
if name == "" {
164167
innerName = pb.metric.FieldPrefix + key
165168
} else {
@@ -172,6 +175,10 @@ func (pb *pointBuilder) fillFields(name string, value interface{}, fieldMap map[
172175
return
173176
}
174177

178+
if _, ok := value.([]interface{}); ok {
179+
return
180+
}
181+
175182
if pb.metric.FieldName != "" {
176183
name = pb.metric.FieldName
177184
if prefix := pb.metric.FieldPrefix; prefix != "" {

0 commit comments

Comments
 (0)