fix: eliminate Prometheus Counter anti-patterns and security issues - #92
Merged
theinterneti merged 2 commits intoNov 13, 2025
Merged
Conversation
…tions, regex parsing, XSS prevention - Fix Prometheus Counter anti-pattern by tracking last values internally instead of accessing private _value attribute - Add proper type annotations to __aexit__ with TracebackType import - Use regex for more robust PAF markdown parsing (handles edge cases better) - Add HTML escaping to prevent XSS vulnerabilities in test reports Addresses feedback from PR #26 review thread Co-authored-by: theinterneti <169108167+theinterneti@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update Phase 1 workflow enhancements for observability and API testing
fix: eliminate Prometheus Counter anti-patterns and security issues
Nov 13, 2025
theinterneti
marked this pull request as ready for review
November 13, 2025 17:57
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR addresses code quality issues identified in review feedback, focusing on eliminating Prometheus Counter anti-patterns, improving type safety, enhancing parsing robustness, and preventing XSS vulnerabilities.
Key changes:
- Replaced improper Prometheus Counter
_valueaccess with internal state tracking - Added proper type annotations to async context manager methods
- Improved PAF parsing from string splitting to regex-based parsing
- Added HTML escaping to prevent XSS in test report generation
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| prometheus_exporter.py | Eliminated Counter anti-pattern by tracking last values internally instead of accessing private _value attribute |
| recorder.py | Added proper type hints to __aexit__ parameters, removing type checking suppression |
| paf_memory.py | Replaced fragile string split parsing with regex for more robust PAF entry extraction |
| test_runner.py | Added html.escape() to prevent XSS injection in HTML test reports |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses code review feedback from PR #26: improper Counter manipulation, missing type annotations, fragile parsing, and XSS vulnerability.
Changes
Prometheus Counter tracking (prometheus_exporter.py)
_valueattribute access with internal state tracking_last_request_total,_last_cost_total,_last_savings_totaldictionaries.inc()with calculated deltasType annotations (recorder.py)
__aexit__:type[BaseException] | None,BaseException | None,TracebackType | None# type: ignore[no-untyped-def]suppressionPAF parsing (paf_memory.py)
r"- \*\*([A-Z]+-\d+)\*\*:\s*(.+)"XSS prevention (test_runner.py)
html.escape()to test case names and statuses in HTML report generation💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.