refactor: no rate limits must return nil.
This commit is contained in:
parent
987e8a93bd
commit
aeffe1036d
2 changed files with 11 additions and 1 deletions
|
@ -308,7 +308,7 @@ func ParseErrorPages(labels map[string]string, labelPrefix string, labelRegex *r
|
||||||
|
|
||||||
// ParseRateSets parse rate limits to create Rate struct
|
// ParseRateSets parse rate limits to create Rate struct
|
||||||
func ParseRateSets(labels map[string]string, labelPrefix string, labelRegex *regexp.Regexp) map[string]*types.Rate {
|
func ParseRateSets(labels map[string]string, labelPrefix string, labelRegex *regexp.Regexp) map[string]*types.Rate {
|
||||||
rateSets := make(map[string]*types.Rate)
|
var rateSets map[string]*types.Rate
|
||||||
|
|
||||||
for lblName, rawValue := range labels {
|
for lblName, rawValue := range labels {
|
||||||
if strings.HasPrefix(lblName, labelPrefix) && len(rawValue) > 0 {
|
if strings.HasPrefix(lblName, labelPrefix) && len(rawValue) > 0 {
|
||||||
|
@ -318,6 +318,10 @@ func ParseRateSets(labels map[string]string, labelPrefix string, labelRegex *reg
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rateSets == nil {
|
||||||
|
rateSets = make(map[string]*types.Rate)
|
||||||
|
}
|
||||||
|
|
||||||
limitName := submatch[1]
|
limitName := submatch[1]
|
||||||
|
|
||||||
ep, ok := rateSets[limitName]
|
ep, ok := rateSets[limitName]
|
||||||
|
|
|
@ -1118,6 +1118,12 @@ func TestParseRateSets(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
desc: "no rate limits labels",
|
||||||
|
labels: map[string]string{},
|
||||||
|
expected: nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
|
|
Loading…
Reference in a new issue