Merge pull request #8 from Clever/INFRA-2263-kvroutes-bugfix

decode: json decodes dimensions as array of interface
This commit is contained in:
Nathan Leiby 2017-08-15 12:11:49 -07:00 committed by GitHub
commit 035cc7fd83
2 changed files with 16 additions and 7 deletions

View file

@ -154,11 +154,20 @@ func getStringArray(json map[string]interface{}, key string) []string {
return []string{} return []string{}
} }
strArray, ok := val.([]string) iArray, ok := val.([]interface{})
if !ok { if !ok {
return []string{} return []string{}
} }
strArray := []string{}
for _, item := range iArray {
s, ok := item.(string)
if !ok {
return []string{}
}
strArray = append(strArray, s)
}
return strArray return strArray
} }

View file

@ -562,13 +562,13 @@ func TestExtractKVMeta(t *testing.T) {
"rule": "cool", "rule": "cool",
"series": "1,1,2,3,5,8,13", "series": "1,1,2,3,5,8,13",
"value_field": "value", "value_field": "value",
"dimensions": []string{"app", "district"}, "dimensions": []interface{}{"app", "district"},
}, },
map[string]interface{}{ map[string]interface{}{
"type": "metrics", "type": "metrics",
"rule": "cool2", "rule": "cool2",
"series": "1,1,2,6,24,120,720,5040", "series": "1,1,2,6,24,120,720,5040",
"dimensions": []string{"app", "district"}, "dimensions": []interface{}{"app", "district"},
}, },
}, },
}, },
@ -688,7 +688,7 @@ func TestExtractKVMeta(t *testing.T) {
"type": "alerts", "type": "alerts",
"rule": "last-call", "rule": "last-call",
"series": "doing-it-til-we-fall", "series": "doing-it-til-we-fall",
"dimensions": []string{"who", "where"}, "dimensions": []interface{}{"who", "where"},
"stat_type": "guage", "stat_type": "guage",
"value_field": "status", "value_field": "status",
}, },
@ -696,7 +696,7 @@ func TestExtractKVMeta(t *testing.T) {
"type": "alerts", "type": "alerts",
"rule": "watch-out-now", "rule": "watch-out-now",
"series": "dem-gators-gonna-bite-ya", "series": "dem-gators-gonna-bite-ya",
"dimensions": []string{"how-fresh", "how-clean"}, "dimensions": []interface{}{"how-fresh", "how-clean"},
}, },
}, },
}, },
@ -750,7 +750,7 @@ func TestExtractKVMeta(t *testing.T) {
"type": "metrics", "type": "metrics",
"rule": "all-combos", "rule": "all-combos",
"series": "1,1,2,6,24,120,720,5040", "series": "1,1,2,6,24,120,720,5040",
"dimensions": []string{"fact", "orial"}, "dimensions": []interface{}{"fact", "orial"},
}, },
map[string]interface{}{ map[string]interface{}{
"type": "analytics", "type": "analytics",
@ -767,7 +767,7 @@ func TestExtractKVMeta(t *testing.T) {
"type": "alerts", "type": "alerts",
"rule": "last-call", "rule": "last-call",
"series": "doing-it-til-we-fall", "series": "doing-it-til-we-fall",
"dimensions": []string{"who", "where"}, "dimensions": []interface{}{"who", "where"},
"stat_type": "guage", "stat_type": "guage",
"value_field": "status", "value_field": "status",
}, },