Skip to content

Commit

Permalink
Add scrape manager test for disabling staleness marker.
Browse files Browse the repository at this point in the history
  • Loading branch information
thampiotr committed May 3, 2024
1 parent f6d4a83 commit a71d93a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions scrape/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
"gopkg.in/yaml.v2"

"github.com/prometheus/prometheus/config"
Expand Down Expand Up @@ -703,3 +704,51 @@ scrape_configs:
reload(scrapeManager, cfg2)
require.ElementsMatch(t, []string{"job1", "job3"}, scrapeManager.ScrapePools())
}

func TestManagerDisableEndOfRunStalenessMarkers(t *testing.T) {
configForJob := func(jobName string) *config.ScrapeConfig {
return &config.ScrapeConfig{
JobName: jobName,
ScrapeInterval: model.Duration(1 * time.Minute),
ScrapeTimeout: model.Duration(1 * time.Minute),
}
}

cfg := &config.Config{ScrapeConfigs: []*config.ScrapeConfig{
configForJob("one"),
configForJob("two"),
}}

m := NewManager(&Options{}, nil, &nopAppendable{})
defer m.Stop()
require.NoError(t, m.ApplyConfig(cfg))

// Pass targets to the manager.
tgs := map[string][]*targetgroup.Group{
"one": {{Targets: []model.LabelSet{{"__address__": "h1"}, {"__address__": "h2"}, {"__address__": "h3"}}}},
"two": {{Targets: []model.LabelSet{{"__address__": "h4"}}}},
}
m.updateTsets(tgs)
m.reload()

activeTargets := m.TargetsActive()
targetsToDisable := []*Target{
activeTargets["one"][0],
activeTargets["one"][2],
NewTarget(labels.FromStrings("__address__", "h4"), labels.EmptyLabels(), nil), // non-existent target.
}

// Disable end of run staleness markers for some targets.
m.DisableEndOfRunStalenessMarkers("one", targetsToDisable)
// This should be a no-op
m.DisableEndOfRunStalenessMarkers("non-existent-job", targetsToDisable)

// Check that the end of run staleness markers are disabled for the correct targets.
for _, group := range []string{"one", "two"} {
for _, tg := range activeTargets[group] {
loop := m.scrapePools[group].loops[tg.hash()].(*scrapeLoop)
expectedDisabled := slices.Contains(targetsToDisable, tg)
require.Equal(t, expectedDisabled, loop.disabledEndOfRunStalenessMarkers.Load())
}
}
}

0 comments on commit a71d93a

Please sign in to comment.