func()

in swim/labels.go [66:101]


func (lo LabelOptions) validateLabel(current map[string]string, key, value string) error {
	if isInternalLabel(key) {
		// we ignore internal labels in the limits
		return nil
	}

	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
	}

	// 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

	_, 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
}