You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
problems=append(problems, promlint.Problem{Metric: name, Text: "recording rule name must be level:metric:operations. if there is no obvious operations, use 'sum'"})
74
+
returnproblems
75
+
}
76
+
77
+
// Enforce metric segment prefix: it should start with operator_suboperator like metrics do
problems=append(problems, promlint.Problem{Metric: name, Text: fmt.Sprintf("metric (second segment in level:metric:operations) need to start with \"%s\"", expectedPrefix)})
86
+
}
87
+
}
88
+
89
+
// Single/Multiple operations: detect ops in expr and enforce suffix rules
90
+
{
91
+
aggOps:=detectOps(rr.Expr, promAggOps)
92
+
timeOps:=detectOps(rr.Expr, promTimeOps)
93
+
total:=len(aggOps) +len(timeOps)
94
+
opsPart:=parts[2]
95
+
iftotal==1 {
96
+
iflen(aggOps) ==1 {
97
+
expected:=aggOps[0]
98
+
if!strings.HasSuffix(opsPart, expected) {
99
+
problems=append(problems, promlint.Problem{Metric: name, Text: fmt.Sprintf("single aggregation detected in expr: operations (third segment in level:metric:operations) should end with '%s'", expected)})
problems=append(problems, promlint.Problem{Metric: name, Text: fmt.Sprintf("single time operation detected in expr: operations (third segment in level:metric:operations) should end with '%s<duration>'", expected)})
106
+
}
107
+
}
108
+
} elseiftotal>1 {
109
+
present:=false
110
+
for_, op:=rangeappend(aggOps, timeOps...) {
111
+
ifstrings.Contains(opsPart, op) {
112
+
present=true
113
+
break
114
+
}
115
+
}
116
+
if!present {
117
+
problems=append(problems, promlint.Problem{Metric: name, Text: "multiple operations detected in expr: at least one operation should appear in operations (third segment in level:metric:operations)"})
0 commit comments