add "field_tags" to json parser config
This commit is contained in:
@@ -20,6 +20,7 @@ var (
|
||||
type JSONParser struct {
|
||||
MetricName string
|
||||
TagKeys []string
|
||||
FieldKeys []string
|
||||
DefaultTags map[string]string
|
||||
}
|
||||
|
||||
@@ -86,6 +87,17 @@ func (p *JSONParser) switchFieldToTag(tags map[string]string, fields map[string]
|
||||
}
|
||||
}
|
||||
|
||||
//if field_keys is specified, only those values should be reported as fields
|
||||
if len(p.FieldKeys) > 0 {
|
||||
nFields := make(map[string]interface{})
|
||||
for _, name := range p.FieldKeys {
|
||||
if fields[name] != nil {
|
||||
nFields[name] = fields[name]
|
||||
}
|
||||
}
|
||||
return tags, nFields
|
||||
}
|
||||
|
||||
//remove any additional string/bool values from fields
|
||||
for k := range fields {
|
||||
switch fields[k].(type) {
|
||||
|
||||
@@ -448,19 +448,24 @@ func TestJSONParseNestedArray(t *testing.T) {
|
||||
"total_devices": 5,
|
||||
"total_threads": 10,
|
||||
"shares": {
|
||||
"total": 5,
|
||||
"accepted": 5,
|
||||
"rejected": 0,
|
||||
"avg_find_time": 4,
|
||||
"tester": "work",
|
||||
"tester2": "don't want this",
|
||||
"tester3": 7.93
|
||||
"total": 5,
|
||||
"accepted": 5,
|
||||
"rejected": 0,
|
||||
"avg_find_time": 4,
|
||||
"tester": "work",
|
||||
"tester2": "don't want this",
|
||||
"tester3": {
|
||||
"hello":"sup",
|
||||
"fun":"money",
|
||||
"break":9
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
parser := JSONParser{
|
||||
MetricName: "json_test",
|
||||
TagKeys: []string{"total_devices", "total_threads", "shares_tester", "shares_tester3"},
|
||||
TagKeys: []string{"total_devices", "total_threads", "shares_tester3_fun"},
|
||||
FieldKeys: []string{"shares_tester", "shares_tester3_break"},
|
||||
}
|
||||
|
||||
metrics, err := parser.Parse([]byte(testString))
|
||||
|
||||
Reference in New Issue
Block a user