Skip to content

Fix high memory alert ratio - #2

Open
jarlyn95 wants to merge 1 commit into
weilixiong:mainfrom
jarlyn95:codex/fix-memory-alert-ratio
Open

Fix high memory alert ratio#2
jarlyn95 wants to merge 1 commit into
weilixiong:mainfrom
jarlyn95:codex/fix-memory-alert-ratio

Conversation

@jarlyn95

Copy link
Copy Markdown

Summary

Fixes #1. The HighMemoryUsage alert no longer divides process_resident_memory_bytes by itself; it now compares resident process memory against machine_memory_bytes.

Changes

  • Update HighMemoryUsage to use process_resident_memory_bytes / machine_memory_bytes > 0.9.
  • Add alert-expression validation that rejects rules where a metric is divided by itself before upload.
  • Add Python unittest coverage for the recommended rules and a self-division regression case.
  • Fix a build.py f-string literal so the required build command can run on current Python versions.
  • Commit the generated diagnostic metadata and .logd bundle from python3 build.py.

Testing

  • python -m py_compile build.py tools/monitoring_setup.py tools/test_monitoring_setup.py
  • python -m unittest tools.test_monitoring_setup -v
  • python tools/monitoring_setup.py --alerts --dry-run
  • wsl python3 -m py_compile build.py tools/monitoring_setup.py tools/test_monitoring_setup.py
  • wsl python3 -m unittest tools.test_monitoring_setup -v
  • wsl python3 build.py generated diagnostic/build-2b54872c.logd and diagnostic/build-2b54872c.json; it exited non-zero because this local WSL environment is missing most non-frontend toolchains, while the frontend module passed.

Checklist

  • Relevant modules affected by these changes build locally
  • Tests pass locally
  • Diagnostic build log is committed in this PR
  • Documentation has been updated, if applicable
  • Configuration or schema changes are documented, if applicable
  • No generated build artifacts are committed, except the required diagnostic build log
  • Changes are scoped to the PR purpose and avoid unrelated cleanup
  • Security, privacy, and error-handling implications have been considered

  • I would like to request that my diagnostic build log is removed before merging

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adjusts the recommended Prometheus HighMemoryUsage alert expression to use a meaningful memory ratio and adds a pre-upload validation step (with tests) to prevent self-division regressions in alert rules.

Changes:

  • Fix HighMemoryUsage expression to compare process_resident_memory_bytes against machine_memory_bytes.
  • Add alert-expression validation in upload_prometheus_rules() and unit tests for both recommended rules and a self-division regression.
  • Fix a build.py f-string/quoting issue and commit diagnostic build artifacts.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tools/monitoring_setup.py Updates HighMemoryUsage and adds self-division validation before uploading rules.
tools/test_monitoring_setup.py Adds unittests covering recommended rules and a self-division regression case.
build.py Fixes printing of a string containing an apostrophe.
diagnostic/build-2b54872c.json Adds build diagnostic metadata for the PR.
diagnostic/build-2b54872c.logd Adds the encrypted diagnostic bundle referenced by the JSON metadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +21 to +22
self.assertIn("process_resident_memory_bytes", rule["expr"])
self.assertIn("machine_memory_bytes", rule["expr"])
Comment thread tools/monitoring_setup.py
Comment on lines +201 to +208
METRIC_REF_RE = r"[A-Za-z_:][A-Za-z0-9_:]*(?:\s*\{[^{}]*\})?(?:\s*\[[^\[\]]+\])?"
DIVISION_RE = re.compile(
rf"(?<![A-Za-z0-9_:])(?P<left>{METRIC_REF_RE})\s*/\s*(?P<right>{METRIC_REF_RE})(?![A-Za-z0-9_:])"
)


def _normalize_metric_ref(metric_ref: str) -> str:
return re.sub(r"\s+", "", metric_ref)
"name": "frontend",
"status": "PASS",
"elapsed_seconds": 12.151,
"artifact": "/mnt/c/Users/jarlyn/Documents/make money/zeroeye-memory-bounty/frontend/dist",
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.

[$30 BOUNTY] [Python] Fix HighMemoryUsage alert ratio expression

3 participants