-
Notifications
You must be signed in to change notification settings - Fork 5
Define metrics with Prometheus integration #33
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f125401
Define metrics with Prometheus integration, also updated cursorrules
timl3136 43aac5d
change naming and combine metricsLogic
timl3136 bedee71
naming
timl3136 3c295f6
Merge branch 'main' into prometheus-test-1
timl3136 4b57026
respond to comments
timl3136 6ac8143
respond to comments
timl3136 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,49 @@ | ||
| # Cursor Rules for Cadence Python Client | ||
|
|
||
| ## Package Management | ||
| - **Always use `uv` for Python package management** | ||
| - Use `uv run` for running Python commands instead of `python` directly | ||
| - Use `uv sync` for installing dependencies instead of `pip install` | ||
| - Use `uv tool run` for running development tools (pytest, mypy, ruff, etc.) | ||
| - Only use `pip` or `python` directly when specifically required by the tool or documentation | ||
|
|
||
| ## Examples | ||
| ```bash | ||
| # ✅ Correct | ||
| uv run python scripts/generate_proto.py | ||
| uv run python -m pytest tests/ | ||
| uv tool run mypy cadence/ | ||
| uv tool run ruff check | ||
|
|
||
| # ❌ Avoid | ||
| python scripts/generate_proto.py | ||
| pip install -e ".[dev]" | ||
| ``` | ||
|
|
||
| ## Virtual Environment | ||
| - The project uses `uv` for virtual environment management | ||
| - Always activate the virtual environment using `uv` commands | ||
| - Dependencies are managed through `pyproject.toml` and `uv.lock` | ||
|
|
||
| ## Testing | ||
| - Run tests with `uv run python -m pytest` | ||
| - Use `uv run` for any Python script execution | ||
| - Development tools should be run with `uv tool run` | ||
|
|
||
| ## Code Generation | ||
| - Use `uv run python scripts/generate_proto.py` for protobuf generation | ||
| - Use `uv run python scripts/dev.py` for development tasks | ||
|
|
||
| ## Code Quality | ||
| - **ALWAYS run linter and type checker after making code changes** | ||
| - Run linter with auto-fix: `uv tool run ruff check --fix` | ||
| - Run type checking: `uv tool run mypy cadence/` | ||
| - Use `uv tool run ruff check --fix && uv tool run mypy cadence/` to run both together | ||
| - **Standard workflow**: Make changes → Run linter → Run type checker → Commit | ||
|
|
||
| ## Development Workflow | ||
| 1. Make code changes | ||
| 2. Run `uv tool run ruff check --fix` (fixes formatting and linting issues) | ||
| 3. Run `uv tool run mypy cadence/` (checks type safety) | ||
| 4. Run `uv run python -m pytest` (run tests) | ||
| 5. Commit changes |
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,12 @@ | ||
| """Visibility and metrics collection components for Cadence client.""" | ||
|
|
||
| from .metrics import MetricsHandler, NoOpMetricsHandler, get_default_handler | ||
| from .prometheus import PrometheusMetrics, PrometheusConfig | ||
|
|
||
| __all__ = [ | ||
| "MetricsHandler", | ||
| "NoOpMetricsHandler", | ||
| "get_default_handler", | ||
| "PrometheusMetrics", | ||
| "PrometheusConfig", | ||
| ] | ||
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,86 @@ | ||
| """Core metrics collection interface and registry for Cadence client.""" | ||
|
|
||
| import logging | ||
| from enum import Enum | ||
| from typing import Dict, Optional, Protocol | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class MetricType(Enum): | ||
| """Types of metrics that can be collected.""" | ||
|
|
||
| COUNTER = "counter" | ||
| GAUGE = "gauge" | ||
| HISTOGRAM = "histogram" | ||
| SUMMARY = "summary" | ||
|
|
||
|
|
||
| class MetricsHandler(Protocol): | ||
timl3136 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Protocol for metrics collection backends.""" | ||
|
|
||
| def counter( | ||
| self, key: str, n: int = 1, tags: Optional[Dict[str, str]] = None | ||
| ) -> None: | ||
| """Send a counter metric.""" | ||
| ... | ||
|
|
||
| def gauge( | ||
| self, key: str, value: float, tags: Optional[Dict[str, str]] = None | ||
| ) -> None: | ||
| """Send a gauge metric.""" | ||
| ... | ||
|
|
||
| def timer( | ||
| self, key: str, duration: float, tags: Optional[Dict[str, str]] = None | ||
| ) -> None: | ||
| """Send a timer metric.""" | ||
| ... | ||
|
|
||
| def histogram( | ||
| self, key: str, value: float, tags: Optional[Dict[str, str]] = None | ||
| ) -> None: | ||
| """Send a histogram metric.""" | ||
| ... | ||
|
|
||
|
|
||
| class NoOpMetricsHandler: | ||
| """No-op metrics handler that discards all metrics.""" | ||
|
|
||
| def counter( | ||
| self, key: str, n: int = 1, tags: Optional[Dict[str, str]] = None | ||
| ) -> None: | ||
| pass | ||
|
|
||
| def gauge( | ||
| self, key: str, value: float, tags: Optional[Dict[str, str]] = None | ||
| ) -> None: | ||
| pass | ||
|
|
||
| def timer( | ||
| self, key: str, duration: float, tags: Optional[Dict[str, str]] = None | ||
| ) -> None: | ||
| pass | ||
|
|
||
| def histogram( | ||
| self, key: str, value: float, tags: Optional[Dict[str, str]] = None | ||
| ) -> None: | ||
| pass | ||
|
|
||
|
|
||
| # Global default handler | ||
| _default_handler: Optional[MetricsHandler] = None | ||
|
||
|
|
||
|
|
||
| def get_default_handler() -> MetricsHandler: | ||
| """Get the default global metrics handler.""" | ||
| global _default_handler | ||
| if _default_handler is None: | ||
| _default_handler = NoOpMetricsHandler() | ||
| return _default_handler | ||
|
|
||
|
|
||
| def set_default_handler(handler: MetricsHandler) -> None: | ||
| """Set the default global metrics handler.""" | ||
| global _default_handler | ||
| _default_handler = handler | ||
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.
MetricsEmitter and the prometheus stuff should be in a public package. Users need to specify it in the ClientOptions so it should be visibile. Maybe
cadence/metricsAdditionally we should go with
metricsas the package name. I don't think visibility accurately describes it.