Merge pull request #4066 from krasi-georgiev/race-DiscoveredLabels

add mutex for DiscoveredLabels
This commit is contained in:
Björn Rabenstein 2018-04-10 15:36:56 +02:00 committed by GitHub
commit f8dcf9b272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -110,6 +110,8 @@ func (t *Target) Labels() labels.Labels {
// DiscoveredLabels returns a copy of the target's labels before any processing.
func (t *Target) DiscoveredLabels() labels.Labels {
t.mtx.Lock()
defer t.mtx.Unlock()
lset := make(labels.Labels, len(t.discoveredLabels))
copy(lset, t.discoveredLabels)
return lset
@ -117,6 +119,8 @@ func (t *Target) DiscoveredLabels() labels.Labels {
// SetDiscoveredLabels sets new DiscoveredLabels
func (t *Target) SetDiscoveredLabels(l labels.Labels) {
t.mtx.Lock()
defer t.mtx.Unlock()
t.discoveredLabels = l
}