Adjust flag

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
Julien Pivotto 2020-10-07 18:25:52 +02:00
parent 6b618ecf02
commit 627ff84599
2 changed files with 8 additions and 5 deletions

View File

@ -239,8 +239,8 @@ func main() {
a.Flag("rules.alert.resend-delay", "Minimum amount of time to wait before resending an alert to Alertmanager."). a.Flag("rules.alert.resend-delay", "Minimum amount of time to wait before resending an alert to Alertmanager.").
Default("1m").SetValue(&cfg.resendDelay) Default("1m").SetValue(&cfg.resendDelay)
a.Flag("scrape.timestamp-tolerance", "Adjust scrape timestamps by up to this amount to align them to the intended schedule. Experimental."). a.Flag("scrape.adjust-timestamps", "Adjust scrape timestamps by up to 2ms to align them to the intended schedule. Experimental.").
Hidden().Default("2ms").DurationVar(&scrape.ScrapeTimestampTolerance) Hidden().Default("true").BoolVar(&scrape.AlignScrapeTimestamps)
a.Flag("alertmanager.notification-queue-capacity", "The capacity of the queue for pending Alertmanager notifications."). a.Flag("alertmanager.notification-queue-capacity", "The capacity of the queue for pending Alertmanager notifications.").
Default("10000").IntVar(&cfg.notifier.QueueCapacity) Default("10000").IntVar(&cfg.notifier.QueueCapacity)

View File

@ -50,7 +50,10 @@ import (
// Temporary tolerance for scrape appends timestamps alignment, to enable better // Temporary tolerance for scrape appends timestamps alignment, to enable better
// compression at the TSDB level. // compression at the TSDB level.
// See https://github.com/prometheus/prometheus/issues/7846 // See https://github.com/prometheus/prometheus/issues/7846
var ScrapeTimestampTolerance = 2 * time.Millisecond const scrapeTimestampTolerance = 2 * time.Millisecond
// Enable or disable the tolerance for scrape described above.
var AlignScrapeTimestamps = true
var errNameLabelMandatory = fmt.Errorf("missing metric name (%s label)", labels.MetricName) var errNameLabelMandatory = fmt.Errorf("missing metric name (%s label)", labels.MetricName)
@ -1009,14 +1012,14 @@ mainLoop:
// increase in TSDB. // increase in TSDB.
// See https://github.com/prometheus/prometheus/issues/7846 // See https://github.com/prometheus/prometheus/issues/7846
scrapeTime := time.Now() scrapeTime := time.Now()
if interval > 100*ScrapeTimestampTolerance { if AlignScrapeTimestamps && interval > 100*scrapeTimestampTolerance {
// For some reason, a tick might have been skipped, in which case we // For some reason, a tick might have been skipped, in which case we
// would call alignedScrapeTime.Add(interval) multiple times. // would call alignedScrapeTime.Add(interval) multiple times.
for scrapeTime.Sub(alignedScrapeTime) >= interval { for scrapeTime.Sub(alignedScrapeTime) >= interval {
alignedScrapeTime = alignedScrapeTime.Add(interval) alignedScrapeTime = alignedScrapeTime.Add(interval)
} }
// Align the scrape time if we are in the tolerance boundaries. // Align the scrape time if we are in the tolerance boundaries.
if scrapeTime.Sub(alignedScrapeTime) <= ScrapeTimestampTolerance { if scrapeTime.Sub(alignedScrapeTime) <= scrapeTimestampTolerance {
scrapeTime = alignedScrapeTime scrapeTime = alignedScrapeTime
} }
} }