Repository: prometheus/prometheus (language: go)

Issue:
--scrape.timestamp-tolerance is no longer respected
### What did you do?

https://github.com/prometheus/prometheus/pull/13624/ sets the scrape timestamp tolerance to `max(--scrape.timestamp-tolerance, scrape_interval/100)` which moves the tolerance, for a `30s` scrape interval,  from the current default `2ms` to `300ms`.

This outcome doesn’t appear to be intentional.

The aim of the change, was maybe to allow alignment even if the provided `--scrape.timestamp-tolerance` exceeds `scrape_interval/100` by limiting the tolerance to the threshold itself: `scrape_interval/100`.


Naturally, this will trigger some alignments that were previously ignored/skipped, we should make sure to doc that (release notes? PR?).
And `--scrape.timestamp-tolerance` flag description should be updated as well.
We'll also need to add some tests.

### What did you expect to see?

_No response_

### What did you see instead? Under which circumstances?

See https://cloud-native.slack.com/archives/C01AUBA4PFE/p1709828067522189?thread_ts=1709821162.017339&cid=C01AUBA4PFE

### System information

_No response_

### Prometheus version

```text
3d16d398815d03a756dd8361efe6d1580fba7fcc
```


### Prometheus configuration file

_No response_

### Alertmanager version

_No response_

### Alertmanager configuration file

_No response_

### Logs

_No response_


Discussion / hints:

Fix patch:
diff --git a/scrape/scrape.go b/scrape/scrape.go
index 11006dc243d..f6f33677360 100644
--- a/scrape/scrape.go
+++ b/scrape/scrape.go
@@ -1218,10 +1218,8 @@ mainLoop:
 		// and .Add on time.Time behave differently (see time package docs).
 		scrapeTime := time.Now().Round(0)
 		if AlignScrapeTimestamps {
-			tolerance := ScrapeTimestampTolerance
-			if maxTolerance := sl.interval / 100; tolerance < maxTolerance {
-				tolerance = maxTolerance
-			}
+			// Tolerance is clamped to maximum 1% of the scrape interval.
+			tolerance := min(sl.interval/100, ScrapeTimestampTolerance)
 			// For some reason, a tick might have been skipped, in which case we
 			// would call alignedScrapeTime.Add(interval) multiple times.
 			for scrapeTime.Sub(alignedScrapeTime) >= sl.interval {


Test patch: