-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Problem
The generate() method in bin/goatsearch.py spans approximately 200 lines (232-430) and handles multiple responsibilities:
- Dataset listing (lines 240-265)
- Job status polling (lines 280-338)
- Result collection with pagination (lines 345-419)
- Event transformation (lines 399-414)
- Search metadata updates (lines 421-425)
While PEP 8 does not specify a maximum function length, the Clean Code in Python guide (TestDriven.io) recommends that functions should:
- Be comprehensible in 5-10 minutes of review
- Follow the Single Responsibility Principle
- Be easily testable
The current structure makes it difficult to:
- Test individual behaviors in isolation
- Understand the flow at a glance
- Modify one aspect without risking others
Proposed Refactoring
Extract logical sections into focused methods:
| New Method | Lines | Responsibility |
|---|---|---|
_list_datasets() |
240-265 | Handle no-query case, return datasets |
_poll_job_status() |
280-338 | Poll until running/complete, yield status events |
_collect_results() |
345-419 | Paginate and yield result events |
_transform_event() |
399-414 | Convert API response to Splunk event format |
After refactoring, generate() becomes orchestration:
def generate(self):
if not self.can_run:
return
if not self.query and not self.sid:
yield from self._list_datasets()
return
self._prepare_event_search()
if not self.job_id:
yield from self.event_log
return
yield from self._poll_and_collect_results()Acceptance Criteria
-
generate()reduced to orchestration logic (~30 lines) - Extracted methods are single-responsibility
- No behavioral changes (refactor only)
- All existing functionality preserved
- Tests pass (if Add end-to-end test infrastructure for CriblSearch #26 is complete)
References
- Clean Code in Python - TestDriven.io
- PEP 8 – Style Guide for Python Code (does not specify line limits, but emphasizes readability)
Related Code
bin/goatsearch.pylines 232-430
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers