From 935df8622a391e527f563c2bc94c50223396233d Mon Sep 17 00:00:00 2001 From: junotx Date: Fri, 2 Apr 2021 10:50:31 +0800 Subject: [PATCH] make func more readable for alerting Signed-off-by: junotx --- pkg/api/alerting/v2alpha1/types.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/api/alerting/v2alpha1/types.go b/pkg/api/alerting/v2alpha1/types.go index e2856ceb5..3b218b355 100644 --- a/pkg/api/alerting/v2alpha1/types.go +++ b/pkg/api/alerting/v2alpha1/types.go @@ -192,7 +192,7 @@ func (q *AlertingRuleQueryParams) Filter(rules []*GettableAlertingRule) []*Getta } func (q *AlertingRuleQueryParams) matches(rule *GettableAlertingRule) bool { - if q.NameContainFilter != "" && !containsI(rule.Name, q.NameContainFilter) { + if q.NameContainFilter != "" && !containsCaseInsensitive(rule.Name, q.NameContainFilter) { return false } if q.State != "" && q.State != rule.State { @@ -210,7 +210,7 @@ func (q *AlertingRuleQueryParams) matches(rule *GettableAlertingRule) bool { } } for k, v := range q.LabelContainFilters { - if fv, ok := rule.Labels[k]; !ok || !containsI(fv, v) { + if fv, ok := rule.Labels[k]; !ok || !containsCaseInsensitive(fv, v) { return false } } @@ -340,7 +340,7 @@ func (q *AlertQueryParams) matches(alert *Alert) bool { } } for k, v := range q.LabelContainFilters { - if fv, ok := alert.Labels[k]; !ok || !containsI(fv, v) { + if fv, ok := alert.Labels[k]; !ok || !containsCaseInsensitive(fv, v) { return false } } @@ -527,8 +527,8 @@ func NewBulkItemErrorServerResponse(ruleName string, err error) *BulkItemRespons } } -// containsI reports whether substr is case-insensitive within s. -func containsI(s, substr string) bool { +// containsCaseInsensitive reports whether substr is case-insensitive within s. +func containsCaseInsensitive(s, substr string) bool { return strings.Contains( strings.ToLower(s), strings.ToLower(substr))