Use rlock in read methods of scrape target

Signed-off-by: Ali Nazari <ali4nazari4@gmail.com>
This commit is contained in:
Ali Nazari 2025-10-08 09:06:09 +03:30
parent fe11cae637
commit f64ee61312
1 changed files with 4 additions and 4 deletions

View File

@ -190,9 +190,9 @@ func (t *Target) LabelsRange(f func(l labels.Label)) {
// DiscoveredLabels returns a copy of the target's labels before any processing.
func (t *Target) DiscoveredLabels(lb *labels.Builder) labels.Labels {
t.mtx.Lock()
t.mtx.RLock()
cfg, tLabels, tgLabels := t.scrapeConfig, t.tLabels, t.tgLabels
t.mtx.Unlock()
t.mtx.RUnlock()
PopulateDiscoveredLabels(lb, cfg, tLabels, tgLabels)
return lb.Labels()
}
@ -208,9 +208,9 @@ func (t *Target) SetScrapeConfig(scrapeConfig *config.ScrapeConfig, tLabels, tgL
// URL returns a copy of the target's URL.
func (t *Target) URL() *url.URL {
t.mtx.Lock()
t.mtx.RLock()
configParams := t.scrapeConfig.Params
t.mtx.Unlock()
t.mtx.RUnlock()
params := url.Values{}
for k, v := range configParams {