Skip to content

Commit

Permalink
fix/Total run time metrics should be bounded by the offset minutes si…
Browse files Browse the repository at this point in the history
…milar to flow run info (#57)

* total run time should be bounded by the offset minutes

* Format

* Add scrape intervall

* Add to readme
  • Loading branch information
jimid27 authored Dec 19, 2024
1 parent eacd21d commit e2da18e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ You can modify environment variables to change the behavior of the exporter.
| `PREFECT_CSRF_ENABLED` | Enable compatibilty with Prefect Servers using CSRF protection | `False` |
| `PAGINATION_ENABLED` | Enable pagination usage. (Uses more resources) | `True` |
| `PAGINATION_LIMIT` | Pagination limit | `200` |
| `SCRAPE_INTERVAL_SECONDS` | Interval in seconds to scrape metrics from Prefect API | `30` |
## Contributing
Expand Down
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ def metrics():
loglevel = str(os.getenv("LOG_LEVEL", "INFO"))
max_retries = int(os.getenv("MAX_RETRIES", "3"))
metrics_port = int(os.getenv("METRICS_PORT", "8000"))
offset_minutes = int(os.getenv("OFFSET_MINUTES", "5"))
offset_minutes = int(os.getenv("OFFSET_MINUTES", "3"))
url = str(os.getenv("PREFECT_API_URL", "http://localhost:4200/api"))
api_key = str(os.getenv("PREFECT_API_KEY", ""))
csrf_client_id = str(uuid.uuid4())
scrape_interval_seconds = int(os.getenv("SCRAPE_INTERVAL_SECONDS", "30"))
# Configure logging
logging.basicConfig(
level=loglevel, format="%(asctime)s - %(name)s - [%(levelname)s] %(message)s"
Expand Down Expand Up @@ -73,7 +74,7 @@ def metrics():

# Run the loop to collect Prefect metrics
while True:
time.sleep(5)
time.sleep(scrape_interval_seconds)


if __name__ == "__main__":
Expand Down
9 changes: 8 additions & 1 deletion metrics/flow_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ def get_all_flow_runs_info(self) -> list:
Returns:
dict: JSON response containing flow runs information.
"""
all_flow_runs = self._get_with_pagination()
all_flow_runs = self._get_with_pagination(
base_data={
"flow_runs": {
"operator": "and_",
"end_time": {"after_": f"{self.after_data_fmt}"},
}
}
)

return all_flow_runs
6 changes: 5 additions & 1 deletion metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ def __init__(
offset_minutes (int): Time offset in minutes.
max_retries (int): The maximum number of retries for HTTP requests.
logger (obj): The logger object.
csrf_enabled (bool): Whether CSRF is enabled.
client_id (str): The client ID for CSRF.
enable_pagination (bool): Whether pagination is enabled.
pagination_limit (int): The pagination limit.
"""

self.headers = headers
self.offset_minutes = offset_minutes
self.url = url
Expand Down

0 comments on commit e2da18e

Please sign in to comment.