nightingale icon indicating copy to clipboard operation
nightingale copied to clipboard

When setting up a suppression rule, is it necessary to trim the spaces before and after the 'value' field?

Open hatmen opened this issue 1 year ago • 0 comments

使用屏蔽规则时遇到ident前后存在空格,导致屏蔽规则不生效。

ident上报时存在空格,导致"==",没有正确匹配到,是否可以使用strings.TrimSpace优化下这块代码,避免其他同学遇到同样问题。

func matchTag(value string, filter models.TagFilter) bool {
	switch filter.Func {
	case "==":
		return strings.TrimSpace(filter.Value) == strings.TrimSpace(value)
	case "!=":
		return strings.TrimSpace(filter.Value) != strings.TrimSpace(value)
	case "in":
		_, has := filter.Vset[value]
		return has
	case "not in":
		_, has := filter.Vset[value]
		return !has
	case "=~":
		return filter.Regexp.MatchString(value)
	case "!~":
		return !filter.Regexp.MatchString(value)
	}
	// unexpect func
	return false
}

hatmen avatar May 29 '23 08:05 hatmen