mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/promscrape: use target arg in ScrapeWork cache
This commit is contained in:
parent
402543e7c6
commit
8af9370bf2
2 changed files with 12 additions and 4 deletions
|
@ -728,7 +728,7 @@ func (stc *StaticConfig) appendScrapeWork(dst []*ScrapeWork, swc *scrapeWorkConf
|
|||
func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabels map[string]string) (*ScrapeWork, error) {
|
||||
bb := scrapeWorkKeyBufPool.Get()
|
||||
defer scrapeWorkKeyBufPool.Put(bb)
|
||||
bb.B = appendScrapeWorkKey(bb.B[:0], extraLabels, metaLabels)
|
||||
bb.B = appendScrapeWorkKey(bb.B[:0], target, extraLabels, metaLabels)
|
||||
keyStrUnsafe := bytesutil.ToUnsafeString(bb.B)
|
||||
if needSkipScrapeWork(keyStrUnsafe) {
|
||||
return nil, nil
|
||||
|
@ -745,7 +745,9 @@ func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabel
|
|||
|
||||
var scrapeWorkKeyBufPool bytesutil.ByteBufferPool
|
||||
|
||||
func appendScrapeWorkKey(dst []byte, extraLabels, metaLabels map[string]string) []byte {
|
||||
func appendScrapeWorkKey(dst []byte, target string, extraLabels, metaLabels map[string]string) []byte {
|
||||
dst = append(dst, target...)
|
||||
dst = append(dst, ',')
|
||||
dst = appendSortedKeyValuePairs(dst, extraLabels)
|
||||
dst = appendSortedKeyValuePairs(dst, metaLabels)
|
||||
return dst
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"crypto/tls"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -444,6 +445,11 @@ func resetNonEssentialFields(sws []*ScrapeWork) {
|
|||
}
|
||||
}
|
||||
|
||||
// String returns human-readable representation for sw.
|
||||
func (sw *ScrapeWork) String() string {
|
||||
return strconv.Quote(sw.key())
|
||||
}
|
||||
|
||||
func TestGetFileSDScrapeWorkSuccess(t *testing.T) {
|
||||
f := func(data string, expectedSws []*ScrapeWork) {
|
||||
t.Helper()
|
||||
|
@ -463,7 +469,7 @@ func TestGetFileSDScrapeWorkSuccess(t *testing.T) {
|
|||
}
|
||||
}
|
||||
if !reflect.DeepEqual(sws, expectedSws) {
|
||||
t.Fatalf("unexpected scrapeWork; got\n%v\nwant\n%v", sws, expectedSws)
|
||||
t.Fatalf("unexpected scrapeWork; got\n%+v\nwant\n%+v", sws, expectedSws)
|
||||
}
|
||||
}
|
||||
f(`
|
||||
|
@ -608,7 +614,7 @@ func TestGetStaticScrapeWorkSuccess(t *testing.T) {
|
|||
}
|
||||
resetNonEssentialFields(sws)
|
||||
if !reflect.DeepEqual(sws, expectedSws) {
|
||||
t.Fatalf("unexpected scrapeWork; got\n%v\nwant\n%v", sws, expectedSws)
|
||||
t.Fatalf("unexpected scrapeWork; got\n%+v\nwant\n%+v", sws, expectedSws)
|
||||
}
|
||||
}
|
||||
f(``, nil)
|
||||
|
|
Loading…
Reference in a new issue