Closed austince closed 5 years ago
Thanks for the quick review @aknysh. Sounds good, I'll make sure of that. Has there been any discussion around adding a testing framework?
type StringSet map[string]bool
func set(slice []string) StringSet {
boolMap := make(StringSet, len(slice))
for i := range slice {
boolMap[slice[i]] = true
}
return boolMap
}
func shouldIncludeDimension(dimName string, includeSet, excludeSet StringSet) bool {
// blacklist first
if excludeSet != nil && excludeSet[dimName] {
return false
}
// if no whitelist, keep it as it passed the blacklist
if includeSet == nil {
return true
}
// otherwise, check the whitelist
return includeSet[dimName]
}
func main() {
println(shouldIncludeDimension("dim1", nil, set([]string{"dim1"}))) // false, in exclude set
println(shouldIncludeDimension("dim2", set([]string{"dim1"}), nil)) // false, not in include set
println(shouldIncludeDimension("dim3", set([]string{"dim1"}), set([]string{"dim2"}))) // false, not in include set yet also not in exclude set
println(shouldIncludeDimension("dim1", nil, nil)) // true, no include or exclude set specified
println(shouldIncludeDimension("dim1", nil, set([]string{"dim2"}))) // true, no include set specified and not in exclude set
println(shouldIncludeDimension("dim1", set([]string{"dim1"}), set([]string{"dim2"}))) // true, in the include set, not in exclude set
println(shouldIncludeDimension("dim1", set([]string{"dim1"}), set([]string{"dim1"}))) // false, in the include set, but also in exclude set
}
I think we should be good - here's a runnable example of the current logic.
Thanks @aknysh - I'm not sure if I'll have time soon but might in a few weeks.
Been using the exclude feature that we put in yesterday (#28) and liking it, but found it would be useful to have a whitelist option as well. Tried to match inclusion/exclusion logic of
INCLUDE_METRICS
/EXCLUDE_METRICS
.