Skip to content

Track extraction progress with a persisted watermark. Closes #1637 - #1720

Draft
rajsingh1301 wants to merge 4 commits into
GreedyBear-Project:developfrom
rajsingh1301:extraction-watermark-1637
Draft

rajsingh1301 wants to merge 4 commits into
GreedyBear-Project:developfrom
rajsingh1301:extraction-watermark-1637

Conversation

@rajsingh1301

@rajsingh1301 rajsingh1301 commented Oct 10, 2026 •

Copy link
Copy Markdown

Description

Extraction and payload extraction derived their time window from the wall clock, so any downtime lost the windows in between. Each run now continues from where the last one stopped, capped at INITIAL_EXTRACTION_TIMESPAN.

What changed:

  • New ExtractionRun model (indexed job_name, window, status, ioc_count, last_error, timestamps), read-only in the admin. The latest window_end of a job is its watermark. Both ExtractionJob and PayloadExtractionJob use it. CleanUp deletes old runs after EXTRACTION_RUN_RETENTION days (default 30) but always keeps the latest run of each job.
  • Each chunk is committed together with its new watermark in one transaction. If chunk 2 of 10 fails, chunk 1 is not repeated.
  • Only RecoverableError is retried (ElasticServerDownError and the new PayloadServerError inherit from it). Any other failure skips the chunk and records the error. A lost Elasticsearch connection during the scan now also counts as ElasticServerDownError.
  • PayloadExtractionJob no longer swallows request errors, so an outage of the payload server is retried. A malformed response is skipped and recorded.
  • The extraction window is cut off at today's midnight, so a late or catching-up run never extracts data from day d before the daily training. The training is triggered once the extraction has reached midnight, instead of by checking the wall clock. TrainModels is unchanged.
  • ElasticRepository.search() now takes a single window. The chunking moved to split_time_window().
  • A savepoint around create_honeypot and the bucket upsert keeps a chunk transaction usable when those fail on their own. After a rolled back chunk, the IOC and sensor caches are reloaded.

Points for review:

  • If an instance has IOCs but no run yet (first start after this update), the first run looks back one interval, as before. Otherwise it would extract the last 3 days a second time and double interaction_count. Because of this, _minutes_back_to_lookup is replaced by _extraction_window but not by a pure "watermark or INITIAL_EXTRACTION_TIMESPAN" rule.
  • I skipped the optional second extraction run after the training. The watermark ends exactly at midnight, so the next scheduled run picks up the rest.
  • No T-Pot was available to me. As discussed in the issue, the verification against real data is still open.

Related issues

Closes #1637

Type of change

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • Chore (refactoring, dependency updates, CI/CD changes, code cleanup, docs-only changes).

Checklist

Formalities

  • I have read and understood the rules about how to Contribute to this project.
  • I chose an appropriate title for the pull request in the form: <feature name>. Closes #999
  • My branch is based on develop.
  • The pull request is for the branch develop.
  • I have reviewed and verified any LLM-generated code included in this PR.

Docs and tests

  • I documented my code changes with docstrings and/or comments.
  • I have checked if my changes affect user-facing behavior that is described in the docs. If so, I also included an update to the wiki in the description of this PR.
  • Linter (Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.
  • I have added tests for the feature/bug I solved.
  • All the tests gave 0 errors.

GUI changes

Ignore this section if you did not make any changes to the GUI.

  • I have provided a screenshot of the result in the PR.
  • I have created new frontend tests for the new component or updated existing ones.

@regulartim

Copy link
Copy Markdown
Member

Hey @rajsingh1301 ! I just took a look at your PR. I will need so time to give it a proper review. I think I can do that next week. So you have to be a little patient.

@rajsingh1301

Copy link
Copy Markdown
Author

Hey @rajsingh1301 ! I just took a look at your PR. I will need so time to give it a proper review. I think I can do that next week. So you have to be a little patient.

No worries, take your time! Thanks for the update. Looking forward to your feedback! 😊

…ar-Project#1637

Extraction and payload extraction derived their time window from the
wall clock, so any downtime lost the windows in between. Each run now
continues from the end of the last processed window, capped at
INITIAL_EXTRACTION_TIMESPAN.

- add ExtractionRun model (per job_name) and ExtractionRunRepository;
  the latest window_end of a job is its watermark
- commit each chunk together with its watermark in one transaction, so
  a failure on chunk n never repeats chunks before it
- retry only RecoverableError (ElasticServerDownError, PayloadServerError);
  every other failure skips the chunk and records the error
- PayloadExtractionJob no longer swallows request errors
- cut the extraction window at today's midnight and trigger the daily
  training once the previous day is fully extracted, instead of relying
  on the wall clock
- ElasticRepository.search() takes a single window; chunking moved to
  split_time_window()
- refresh repository caches after a rolled back chunk
- clean up old runs, keeping the latest run of each job
@rajsingh1301
rajsingh1301 force-pushed the extraction-watermark-1637 branch from e22720a to 3f51846 Compare November 6, 2026 02:34
@rajsingh1301

Copy link
Copy Markdown
Author

Hi @regulartim, just a quick update: I rebased the PR onto the current develop and resolved the conflicts (including renumbering the migration to 0075). All tests pass locally.

No rush at all, I know you're busy. Whenever you have time for a review, I'm happy to make changes. And if you'd like me to prepare anything for the T-Pot verification, please let me know.

@regulartim regulartim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rajsingh1301 ! First of all, I am very sorry, that this took so long. But I wanted to take my time to make a proper review and there was a lt going on in the past weeks.

Overall, your work is very solid. Good job. I ran it against a T-Pot and, so far, everything runs smoothly. I'd like to give you access to a T-Pot, such that you can test your code yourself. I contacted you on LinkedIn for that.

If possible, don't force push if you make further changes, so I can review only changes since my last review. Thanks! :)

Comment thread docker/env_file_template Resolved
@rajsingh1301

Copy link
Copy Markdown
Author

Hey @rajsingh1301 ! First of all, I am very sorry, that this took so long. But I wanted to take my time to make a proper review and there was a lt going on in the past weeks.

Overall, your work is very solid. Good job. I ran it against a T-Pot and, so far, everything runs smoothly. I'd like to give you access to a T-Pot, such that you can test your code yourself. I contacted you on LinkedIn for that.

If possible, don't force push if you make further changes, so I can review only changes since my last review. Thanks! :)

Hi @regulartim, thank you :) so much for the detailed review and for testing it on a T-Pot, I really appreciate it!
Unfortunately, I haven't received any message on LinkedIn. Could you please try again? Here is my profile:https://www.linkedin.com/in/mayank-raj-b1b949339/
I won't force push from now on; all further changes will come as new commits. I'll start working on your comments now.

…L_EXTRACTION_TIMESPAN docs, test day_completed reset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants