-
Notifications
You must be signed in to change notification settings - Fork 3
/
suffix.go
48 lines (42 loc) · 937 Bytes
/
suffix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package prometheusremotewrite
import "strings"
func metricSuffixes(input string) (s1, s2 string) {
switch strings.Count(input, "_") {
case 0, 1:
return
default:
input, s2 = lastCutByte(input, '_')
_, s1 = lastCutByte(input, '_')
}
return s1, s2
}
func lastCutByte(s string, sep byte) (before, after string) {
if i := strings.LastIndexByte(s, sep); i >= 0 {
return s[:i], s[i+1:]
}
return s, ""
}
// IsValidSuffix checks suffix of histogram series.
func IsValidSuffix(suffix string) bool {
switch suffix {
case "max", "sum", "count", "total":
return true
}
return false
}
// IsValidCumulativeSuffix checks suffix of summary series.
func IsValidCumulativeSuffix(suffix string) bool {
switch suffix {
case "sum", "count", "total":
return true
}
return false
}
// IsValidUnit checks unit suffix.
func IsValidUnit(unit string) bool {
switch unit {
case "seconds", "bytes":
return true
}
return false
}