Skip to content

make peek sample use consistent data#997

Open
maxwest-uw wants to merge 1 commit into
mainfrom
msw/peek_sample_consistency
Open

make peek sample use consistent data#997
maxwest-uw wants to merge 1 commit into
mainfrom
msw/peek_sample_consistency

Conversation

@maxwest-uw

Copy link
Copy Markdown
Collaborator

Change Description

in hyrax_alerts, we define and allow the user to define pre_filter and post_filter functions that might affect the data, but peek_sample (used in hyrax_alerts.process_alerts() to do initial runtime setup) doesn't currently touch those functions, so we should check if those functions have been defined so that peek_sample can maintain data consistency.

Solution Description

check for the functions and then apply if them if available.

Note: I added the sample to _buffered before the sample is pre processed since we should assume that when it gets read again through process_alerts as part of the main batch process that it'll be mixed in with data in the __iter__ that hasn't been pre processed yet.

Code Quality

  • I have read the Contribution Guide and agree to the Code of Conduct
  • My code follows the code style of this project
  • My code builds (or compiles) cleanly without any errors or warnings
  • My code contains relevant comments and necessary documentation

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.80%. Comparing base (0ecc0a8) to head (4c314db).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #997      +/-   ##
==========================================
+ Coverage   65.78%   65.80%   +0.02%     
==========================================
  Files          85       85              
  Lines        8204     8210       +6     
==========================================
+ Hits         5397     5403       +6     
  Misses       2807     2807              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@maxwest-uw
maxwest-uw requested a review from drewoldag July 21, 2026 22:58

@drewoldag drewoldag left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I have an open question about this PR that I would like to bottom out before approving.

Comment on lines +208 to +216
if hasattr(self, "pre_filter"):
sample = self.pre_filter([sample])
if sample:
sample = sample[0] if isinstance(sample, list) else sample
self._buffered.append(sample)
# check if pre_process is defined and apply it to the sample
if hasattr(self, "pre_process"):
sample = self.pre_process([sample])
return sample[0] if isinstance(sample, list) else sample

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Before we merge this, let's think through if it makes sense to put this check here. I'm wondering it the same snippet of code might be better on the HyraxKafkaConsumer class in hyrax_alerts. i.e.

class HyraxKafkaConsumer(HyraxAlertsBaseConsumer, KafkaStreamDataset):
    def __init__(self, config, data_location=None):
        HyraxAlertsBaseConsumer.__init__(self, config=config, data_location=data_location)
        KafkaStreamDataset.__init__(self, config=config, data_location=data_location)

    def peek_sample(self):
        sample = super.peek_sample()
        # process `sample` with the new logic from this PR
        return sample

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder only because I think KafkaStreamDataset can be completely unaware of pre filtering and processing and therefore (hopefully) more reusable.

But if I'm missing something obvious, please let me know :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

my only question would be if that would not work nice with the wait/yield loop in the KafkaStreamDataset (i.e. what's the way that HyraxKafkaConsumer will know to continue the loop and wait for an alert if the alert returned out of super.peek_sample() get's pre-filtered and we need to wait for a sample again ?). It might require us to duplicate the loop in the overwritten version of the function which could get messy and lead to divergent functionality. let me give it a shot though !

assert [s["object_id"] for s in batches[0]] == ["first", "second"]


def test_peek_sample_pre_filter(monkeypatch):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same question as above, the tests looks reasonable, but I wonder if this belongs in hyrax_alerts.

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