scrape: fix 'target_limit exceeded error' when reloading conf with 0
Signed-off-by: Arunprasad Rajkumar <arajkuma@redhat.com>
This commit is contained in:
parent
dea37853d9
commit
5527e26efc
|
@ -225,11 +225,10 @@ type scrapePool struct {
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
|
|
||||||
// mtx must not be taken after targetMtx.
|
// mtx must not be taken after targetMtx.
|
||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
config *config.ScrapeConfig
|
config *config.ScrapeConfig
|
||||||
client *http.Client
|
client *http.Client
|
||||||
loops map[uint64]loop
|
loops map[uint64]loop
|
||||||
targetLimitHit bool // Internal state to speed up the target_limit checks.
|
|
||||||
|
|
||||||
targetMtx sync.Mutex
|
targetMtx sync.Mutex
|
||||||
// activeTargets and loops must always be synchronized to have the same
|
// activeTargets and loops must always be synchronized to have the same
|
||||||
|
@ -574,20 +573,14 @@ func (sp *scrapePool) sync(targets []*Target) {
|
||||||
// refreshTargetLimitErr returns an error that can be passed to the scrape loops
|
// refreshTargetLimitErr returns an error that can be passed to the scrape loops
|
||||||
// if the number of targets exceeds the configured limit.
|
// if the number of targets exceeds the configured limit.
|
||||||
func (sp *scrapePool) refreshTargetLimitErr() error {
|
func (sp *scrapePool) refreshTargetLimitErr() error {
|
||||||
if sp.config == nil || sp.config.TargetLimit == 0 && !sp.targetLimitHit {
|
if sp.config == nil || sp.config.TargetLimit == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
l := len(sp.activeTargets)
|
if l := len(sp.activeTargets); l > int(sp.config.TargetLimit) {
|
||||||
if l <= int(sp.config.TargetLimit) && !sp.targetLimitHit {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
var err error
|
|
||||||
sp.targetLimitHit = l > int(sp.config.TargetLimit)
|
|
||||||
if sp.targetLimitHit {
|
|
||||||
targetScrapePoolExceededTargetLimit.Inc()
|
targetScrapePoolExceededTargetLimit.Inc()
|
||||||
err = fmt.Errorf("target_limit exceeded (number of targets: %d, limit: %d)", l, sp.config.TargetLimit)
|
return fmt.Errorf("target_limit exceeded (number of targets: %d, limit: %d)", l, sp.config.TargetLimit)
|
||||||
}
|
}
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyLabelLimits(lset labels.Labels, limits *labelLimits) error {
|
func verifyLabelLimits(lset labels.Labels, limits *labelLimits) error {
|
||||||
|
|
|
@ -423,6 +423,10 @@ func TestScrapePoolTargetLimit(t *testing.T) {
|
||||||
validateIsRunning()
|
validateIsRunning()
|
||||||
validateErrorMessage(true)
|
validateErrorMessage(true)
|
||||||
|
|
||||||
|
reloadWithLimit(0)
|
||||||
|
validateIsRunning()
|
||||||
|
validateErrorMessage(false)
|
||||||
|
|
||||||
reloadWithLimit(51)
|
reloadWithLimit(51)
|
||||||
validateIsRunning()
|
validateIsRunning()
|
||||||
validateErrorMessage(false)
|
validateErrorMessage(false)
|
||||||
|
|
Loading…
Reference in New Issue