mirror of
https://github.com/prometheus/prometheus.git
synced 2026-04-22 22:57:16 -04:00
scrape: Introduce an offsetSeed option for deterministic scrape offset calculation and utilize it in tests
Signed-off-by: Ridwan Sharif <ridwanmsharif@google.com>
This commit is contained in:
parent
695db71c68
commit
8e8cd480cb
2 changed files with 11 additions and 11 deletions
|
|
@ -149,8 +149,9 @@ type Options struct {
|
|||
// because of an early startup scrape.
|
||||
InitialScrapeOffset time.Duration
|
||||
|
||||
// private option for testability.
|
||||
// private options for testability.
|
||||
skipJitterOffsetting bool
|
||||
offsetSeed uint64
|
||||
}
|
||||
|
||||
// Manager maintains a set of scrape pools and manages start/stop cycles
|
||||
|
|
@ -269,6 +270,11 @@ func (m *Manager) reload() {
|
|||
|
||||
// setOffsetSeed calculates a global offsetSeed per server relying on extra label set.
|
||||
func (m *Manager) setOffsetSeed(labels labels.Labels) error {
|
||||
if m.opts.offsetSeed != 0 {
|
||||
m.offsetSeed = m.opts.offsetSeed
|
||||
return nil
|
||||
}
|
||||
|
||||
h := fnv.New64a()
|
||||
hostname, err := osutil.GetFQDN()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -6823,6 +6823,7 @@ func TestScrapeOffsetDistribution(t *testing.T) {
|
|||
|
||||
app := teststorage.NewAppendable()
|
||||
opts := &Options{
|
||||
offsetSeed: 1,
|
||||
HTTPClientOptions: []config_util.HTTPClientOption{
|
||||
config_util.WithDialContextFunc(func(ctx context.Context, _, _ string) (net.Conn, error) {
|
||||
srvConn, cliConn := net.Pipe()
|
||||
|
|
@ -6868,20 +6869,13 @@ func TestScrapeOffsetDistribution(t *testing.T) {
|
|||
|
||||
scrapeManager.reload()
|
||||
|
||||
time.Sleep(22 * time.Second)
|
||||
numScrapes := 4
|
||||
time.Sleep((time.Duration(numScrapes) * interval) + time.Second)
|
||||
synctest.Wait()
|
||||
|
||||
scrapeManager.Stop()
|
||||
|
||||
maxScrapes := 0
|
||||
for _, times := range scrapeTimes {
|
||||
if len(times) > maxScrapes {
|
||||
maxScrapes = len(times)
|
||||
}
|
||||
}
|
||||
require.Positive(t, maxScrapes, "Expected at least one scrape")
|
||||
|
||||
for i := 0; i < maxScrapes; i++ {
|
||||
for i := range numScrapes {
|
||||
uniqueTimes := make(map[time.Duration]struct{})
|
||||
for _, times := range scrapeTimes {
|
||||
if i < len(times) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue