[DataForge] Align events to the nearist interval (#211951)

## Summary
 
This PR changes the behavior of `indexing.alignEventsToInterval: true`
(`--align-events-to-interval`) to align the events to the nearest
interval instead of being based on when the command was called. This
change is to help increase the predictability of the documents. This
will also decrease the effects of the index latency on the events.

### Before

If the script was started at `2025-02-20T00:50:34.203Z` with `--interval
10000` then the events will be offset every `10` seconds from the start
time.

### After

If the script was started at `2025-02-20T00:50:34.203Z` with `--interval
10000` then the events will be offset from `2025-02-20T00:50:00.000Z`
every `10` seconds from the start time.

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Chris Cowan 2025-02-24 12:34:49 -07:00 committed by GitHub
parent 681cef4590
commit 57f83bc201
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,7 +36,9 @@ export async function indexSchedule(config: Config, client: Client, logger: Tool
const compiledSchedule = config.schedule.map(parseSchedule(now));
for (const schedule of compiledSchedule) {
const interval = schedule.interval ?? config.indexing.interval;
const startTs = moment(schedule.start);
const startTs = config.indexing.alignEventsToInterval
? moment(schedule.start).startOf('minute')
: moment(schedule.start);
const end =
schedule.end === false && startTs.isAfter(now)
? moment(schedule.start + interval)