-
Notifications
You must be signed in to change notification settings - Fork 3
BED-7975: Add support for log upload & download (support bundles) #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
StranDutton
wants to merge
4
commits into
main
Choose a base branch
from
feature/BED-7975-support-bundle-upload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6d4132d
feat: add OpenHound support for log upload & download (BED-7975)
StranDutton df580e9
docs: add AGENTS.md with branch naming convention
StranDutton d9fd1fe
fix: correct management poll path to /api/v2/clients/management/avail…
StranDutton 7a12620
feat: implement /start and /end lifecycle calls for management operat…
StranDutton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Agent Guidelines | ||
|
|
||
| ## Branch Naming | ||
|
|
||
| All branches **must** follow one of these formats or the CI pipeline will reject the push: | ||
|
|
||
| ``` | ||
| fix/<description> | ||
| patch/<description> | ||
| feature/<description> | ||
| minor/<description> | ||
| major/<description> | ||
| ``` | ||
|
|
||
| **Examples:** | ||
| - `feature/BED-1234-add-support-bundle-upload` | ||
| - `fix/BED-5678-correct-management-endpoint-path` | ||
| - `patch/bump-pydantic-version` | ||
|
|
||
| Use lowercase `<description>` with hyphens. Include the ticket ID when one exists. |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import logging | ||
| import tempfile | ||
| import zipfile | ||
| from datetime import UTC, datetime | ||
| from pathlib import Path | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| # Glob patterns that match the platform log and all rotated backups. | ||
| # The CustomLogger writes to <base_path>/openhound.log and rotates to | ||
| # <base_path>/openhound.log.YYYY-MM-DD_HH(-MM-SS)?. | ||
| _PLATFORM_LOG_PATTERNS = ["openhound.log", "openhound.log.*"] | ||
|
|
||
| # Glob patterns that match extension/job run logs and all rotated backups. | ||
| # The CustomLogger writes to <base_path>/ext_<name>.log and rotates to | ||
| # <base_path>/ext_<name>.log.YYYY-MM-DD_HH(-MM-SS)?. | ||
| _JOB_LOG_PATTERNS = ["ext_*.log", "ext_*.log.*"] | ||
|
|
||
|
|
||
| def collect_log_files(log_base_path: Path) -> list[Path]: | ||
| """Collect all current and rotated log files from the log directory. | ||
|
|
||
| Finds the platform log (openhound.log) and all job run logs (ext_*.log), | ||
| including any rotated backup files produced by CustomLogger's | ||
| RotatingFileHandler. | ||
|
|
||
| Args: | ||
| log_base_path: The directory where OpenHound writes its log files. | ||
| This is CustomLogger.base_path after setup() has been called. | ||
|
|
||
| Returns: | ||
| Sorted list of Path objects for each log file found. Empty if the | ||
| directory does not exist or contains no matching files. | ||
| """ | ||
| if not log_base_path.is_dir(): | ||
| logger.warning( | ||
| f"Log directory does not exist, support bundle will be empty: {log_base_path}" | ||
| ) | ||
| return [] | ||
|
|
||
| found: set[Path] = set() | ||
| for pattern in _PLATFORM_LOG_PATTERNS + _JOB_LOG_PATTERNS: | ||
| found.update(log_base_path.glob(pattern)) | ||
|
|
||
| log_files = sorted(f for f in found if f.is_file()) | ||
|
|
||
| if not log_files: | ||
| logger.warning( | ||
| f"No log files found in {log_base_path}; support bundle will be empty." | ||
| ) | ||
| else: | ||
| logger.debug(f"Collected {len(log_files)} log file(s) for support bundle.") | ||
|
|
||
| return log_files | ||
|
|
||
|
|
||
| def create_support_bundle(collector_name: str, log_base_path: Path) -> Path: | ||
| """Collect all log files and zip them into a named support bundle. | ||
|
|
||
| The zip file is written to a temporary directory so it does not pollute | ||
| the log directory. The caller is responsible for deleting the file after | ||
| it has been uploaded. | ||
|
|
||
| Filename format: <collector_name>_support_bundle_YYYY-MM-DD-HH-MM-SS.zip | ||
| (UTC timestamp, dashes as separators to match the acceptance criteria.) | ||
|
|
||
| Files inside the zip are stored flat (basename only, no directory prefix). | ||
| If two rotated backups share the same basename they will collide; this is | ||
| not expected given CustomLogger's naming conventions. | ||
|
|
||
| Args: | ||
| collector_name: The configured collector name (used in the zip filename). | ||
| log_base_path: The directory where OpenHound writes its log files. | ||
|
|
||
| Returns: | ||
| Path to the created zip file inside a temporary directory. | ||
| """ | ||
| timestamp = datetime.now(UTC).strftime("%Y-%m-%d-%H-%M-%S") | ||
| zip_name = f"{collector_name}_support_bundle_{timestamp}.zip" | ||
|
|
||
| tmp_dir = Path(tempfile.mkdtemp()) | ||
| zip_path = tmp_dir / zip_name | ||
|
|
||
| log_files = collect_log_files(log_base_path) | ||
|
|
||
| with zipfile.ZipFile(zip_path, "w", compression=zipfile.ZIP_DEFLATED) as zf: | ||
| for log_file in log_files: | ||
| zf.write(log_file, arcname=log_file.name) | ||
|
|
||
| logger.info( | ||
| f"Created support bundle '{zip_name}' with {len(log_files)} log file(s) " | ||
| f"at {zip_path}." | ||
| ) | ||
| return zip_path | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to confirm whether or not we want to include rotated backups in the bundle