in swim/labels.go [103:140]
func (lo LabelOptions) validateLabels(current map[string]string, additional map[string]string) error {
// keep track of all labels that are new in this operation to calculate if
// we are exceeding the maximum allowed number of labels
additionalLabelCount := 0
for key, value := range additional {
if isInternalLabel(key) {
// we ignore internal labels in the limits
continue
}
if len(key) > lo.KeySize || len(value) > lo.ValueSize {
// if the either the key or the value of the label is bigger then
// the max allowed size an error is returned
return ErrLabelSizeExceeded
}
_, has := current[key]
if !has {
// only add a count to the countAfter if the key we are looking
// at is a new key
additionalLabelCount++
}
}
// get the count of the current labels, internal labels will not be counted
currentCount := countNonInternalLabels(current)
if additionalLabelCount > 0 && (currentCount+additionalLabelCount) > lo.Count {
// Only when we add additional labels we check if the new count
// (exluding internal labels) will exceed the amount of labels that is
// configured. If that is the case we will return an error
return ErrLabelSizeExceeded
}
// all is ok
return nil
}