Skip to content

Commit

Permalink
Expose disabling staleness markers
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Gwizdala <[email protected]>
  • Loading branch information
thampiotr authored and ptodev committed Aug 27, 2024
1 parent e6cfa72 commit 7e93ba8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
11 changes: 11 additions & 0 deletions scrape/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,14 @@ func (m *Manager) TargetsDroppedCounts() map[string]int {
}
return counts
}

// DisableEndOfRunStalenessMarkers disables the end-of-run staleness markers for the provided targets in the given
// targetSet. When the end-of-run staleness is disabled for a target, when it goes away, there will be no staleness
// markers written for its series.
func (m *Manager) DisableEndOfRunStalenessMarkers(targetSet string, targets []*Target) {
m.mtxScrape.Lock()
defer m.mtxScrape.Unlock()
if pool, ok := m.scrapePools[targetSet]; ok {
pool.disableEndOfRunStalenessMarkers(targets)
}
}
22 changes: 19 additions & 3 deletions scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
config_util "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/prometheus/common/version"
"go.uber.org/atomic"

"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/discovery/targetgroup"
Expand Down Expand Up @@ -554,6 +555,16 @@ func (sp *scrapePool) refreshTargetLimitErr() error {
return nil
}

func (sp *scrapePool) disableEndOfRunStalenessMarkers(targets []*Target) {
sp.mtx.Lock()
defer sp.mtx.Unlock()
for i := range targets {
if l, ok := sp.loops[targets[i].hash()]; ok {
l.disableEndOfRunStalenessMarkers()
}
}
}

func verifyLabelLimits(lset labels.Labels, limits *labelLimits) error {
if limits == nil {
return nil
Expand Down Expand Up @@ -854,7 +865,7 @@ type scrapeLoop struct {
cancel func()
stopped chan struct{}

disabledEndOfRunStalenessMarkers bool
disabledEndOfRunStalenessMarkers atomic.Bool

reportExtraMetrics bool
appendMetadataToWAL bool
Expand Down Expand Up @@ -1264,7 +1275,7 @@ mainLoop:

close(sl.stopped)

if !sl.disabledEndOfRunStalenessMarkers {
if !sl.disabledEndOfRunStalenessMarkers.Load() {
sl.endOfRunStaleness(last, ticker, sl.interval)
}
}
Expand Down Expand Up @@ -1425,6 +1436,11 @@ func (sl *scrapeLoop) endOfRunStaleness(last time.Time, ticker *time.Ticker, int
case <-time.After(interval / 10):
}

// Check if end-of-run staleness markers have been disabled while we were waiting.
if sl.disabledEndOfRunStalenessMarkers.Load() {
return
}

// Call sl.append again with an empty scrape to trigger stale markers.
// If the target has since been recreated and scraped, the
// stale markers will be out of order and ignored.
Expand Down Expand Up @@ -1459,7 +1475,7 @@ func (sl *scrapeLoop) stop() {
}

func (sl *scrapeLoop) disableEndOfRunStalenessMarkers() {
sl.disabledEndOfRunStalenessMarkers = true
sl.disabledEndOfRunStalenessMarkers.Store(true)
}

func (sl *scrapeLoop) getCache() *scrapeCache {
Expand Down

0 comments on commit 7e93ba8

Please sign in to comment.