Repository navigation
Conversation
The post-migration `stats aggregate` command reset every aggregation bookmark to the year 2000 and then aggregated the whole history in a single synchronous pass. That pass never completes, so the bookmark is never advanced; the hourly aggregation then re-processes ~26 years of events forever, re-stamping historical stats docs and triggering a full-corpus reindex every cycle. - stats/event_generator.py (rdm + videos): set `updated_timestamp` to the ingestion time on migrated events, mirroring invenio-stats' live EventsIndexer (processors.py). Without it the aggregator's skip guard can never treat migrated buckets as already-processed. - rdm/cli.py: rewrite `stats aggregate` to backfill a bounded date range month-by-month with `update_bookmark=False`, so it never resets or moves the live aggregation bookmarks (safe to run on a live system). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Migrated events no longer get an updated_timestamp: with it, the aggregator skips every migrated bucket once the live bookmark moves past the ingestion time, so the backfill depended on pausing the stats beat. Without it the skip guard never fires and the requested date range is always aggregated. stats aggregate no longer calls reindex_stats (which moves the stats_reindex bookmark): the regular task reindexes the records, as every aggregate is written with a fresh updated_timestamp. Docs no longer tell to delete or reset the stats-bookmarks index, and the tests cover the month chunks and that no bookmark is written. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the code path behind #664 (stats aggregation/reindex loop after legacy-stats migration).
Problem
The post-migration
stats aggregatecommand reset every aggregation bookmark to the year 2000 and then aggregated the whole history in a single synchronous pass. That pass never completes, soset_bookmark(the last line ofinvenio_statsStatAggregator.run()) is never reached — the bookmark stays at 2000 and the hourly aggregation re-processes ~26 years of events forever, re-stamping historical stats docs and triggering a full-corpus reindex (reindex_stats) every cycle.Changes
cds_migrator_kit/rdm/stats/event_generator.py(and the videos equivalent): setupdated_timestampto the ingestion time on migrated events, mirroring invenio-stats' liveEventsIndexer(processors.py). Previously absent for the RDM path — which disables the aggregator's skip guard for migrated buckets. Ingestion time (not the historical event time) is required so a live backfill still treats the buckets as pending.cds_migrator_kit/rdm/cli.py— rewritestats aggregate:BOOKMARK_START_DATE = 2000-...constant and the delete-all-bookmarks + reset logic;--start-date, process[start, end]month-by-month (_month_chunks);aggregate_events(..., update_bookmark=False)so the live bookmarks are never reset or moved — safe to run on a live system.Notes for reviewers / operators
closes #664
🤖 Generated with Claude Code
Update after review (supersedes the points below where they differ)
The goal is to migrate the stats events and aggregate them without changing any bookmark. The first version of this PR did not fully reach that, so the following was changed and justified:
1. Migrated events carry no
updated_timestamp(reverted from the first version)StatAggregator.agg_iterskips a bucket whenmax(updated_timestamp) < live bookmark. The live bookmark moves forward every hour with the beat.updated_timestampon the events, a backfill started more than ~1h after ingestion (or after the next beat) would find every migrated bucket "already aggregated" and silently aggregate nothing. It would only work with the stats beat paused.last_updateis null and the guard never fires: every bucket of the requested range is aggregated, whatever the bookmark is.timestamp, not byupdated_timestamp, so the--start-date/--end-daterange is unaffected.updated_timestampbefore this PR and is left as it was (the same timing caveat applies there).2.
stats aggregatechanges no bookmark, not evenstats_reindexaggregate_events(..., update_bookmark=False), month by month.reindex_stats(...)call at the end was removed: it sets thestats_reindexbookmark to now.updated_timestamp(agg_iter, even for a bucket of 2017), and the regularreindex_statstask selects the aggregate documents withupdated_timestamp >= its bookmark, collects theirparent_recidand reindexes those records. A backfill is therefore picked up by its next run (also if the task was paused: its bookmark stays old)._idis fixed (<key>-<day>) and the count is recomputed from the raw events, so nothing is counted twice.3. Operator notes
invenio migration stats aggregate --start-date <first day> --end-date <last day before the first live event>(the first description wroteinvenio cds-migrator-kit rdm stats aggregate, which is not the command).--end-dateto the day before the first live event: a day that already holds live events newer than the live bookmark is skipped by the aggregator, so its migrated events would be missed.index_intervalof the aggregation configuration, not the chunks.migration_cli/openshift_migration-recipe.md),step_by_step_documentation.mdand the videos README no longer tell to delete or reset thestats-bookmarksindex.4. Tests
tests/cds-rdm/test_stats_aggregate.py: month chunks (start mid-month, single day, year rollover and leap year),update_bookmark=Falseon every call, noreindex_statsand noset_bookmark,--start-daterequired and the range validated.Still to verify on sandbox
Ingest events of one collection, run
aggregatefor a narrow range, and check that: the bookmark documents are unchanged, the aggregate indices grow, and the migrated records show the stats after the nextreindex_statsrun.