in swim/memberlist.go [345:378]
func (m *memberlist) SetLocalLabels(labels map[string]string) error {
if err := m.node.labelLimits.validateLabels(m.local.Labels, labels); err != nil {
// the labels operation violates the label limits that has been configured
return err
}
m.updateLocalMember(func(member *Member) bool {
// ensure that there is a new copy of the labels to work with.
labelsCopy := member.Labels.copy()
// keep track if we made changes to the labels
changes := false
// copy the key-value pairs to our internal labels. By not setting the map
// of labels to the Labels value of the local member we prevent removing labels
// that the user did not specify in the new map.
for key, value := range labels {
old, had := labelsCopy[key]
labelsCopy[key] = value
if !had || old != value {
changes = true
}
}
if changes {
// only if there are changes we put the copied labels on the member.
member.Labels = labelsCopy
}
return changes
})
return nil
}