Skip to content

Commit

Permalink
Merge pull request #29 from Jeff-SearchPilot/main
Browse files Browse the repository at this point in the history
chelnak authored Mar 5, 2024

Partially verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
2 parents 0baffcc + 36eb3bb commit f245a02
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 9 additions & 1 deletion status_cake_exporter/_status_cake.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

from statuscake import ApiClient, Configuration
from statuscake.apis import MaintenanceWindowsApi, UptimeApi
from statuscake.exceptions import ApiValueError, ForbiddenException
from statuscake.exceptions import ApiValueError, ForbiddenException, ApiException
from typing_extensions import NotRequired, TypedDict

logger = logging.getLogger("status_cake")
@@ -223,6 +223,14 @@ def get_test_history(self, test_id: str) -> list[dict[str, Any]]:
response = uptime_api.list_uptime_test_history(test_id, **params)
return response

except ApiException as e:
if e.status == 429:
backoff=int(e.headers["x-ratelimit-reset"])
logger.debug(f"Hit statuscake API rate limit. Waiting {backoff} seconds before retrying...")
sleep(backoff)
return uptime_api.list_uptime_test_history(test_id, **params)

raise e
except Exception as e:
logger.error(f"Error while fetching test history: {e}")
raise e
12 changes: 7 additions & 5 deletions status_cake_exporter/_test_collector.py
Original file line number Diff line number Diff line change
@@ -78,8 +78,7 @@ def transform(

for i in tests:
logger.debug(f"Transforming test id: {i['id']}")
t.append(
{
test = {
"test_id": str(i["id"]),
"test_type": str(
i["test_type"]
@@ -88,12 +87,14 @@ def transform(
"test_url": i["website_url"],
"test_status_int": get_uptime_status(i["status"]),
"test_uptime_percent": str(i["uptime"]),
"test_performance": str(i["performance"]),
"maintenance_status_int": get_test_maintenance_status(
i["id"], tests_in_maintenance
),
}
)

if hasattr(i, 'performance'):
test["test_performance"]= str(i["performance"])
t.append(test)
logger.debug(f"Transformed test id: {i['id']}")

logger.debug(f"Test transformation complete. Returning {len(t)} metrics")
@@ -179,7 +180,8 @@ def collect(self):
)

for i in metrics:
performance_gauge.add_metric([i["test_id"]], (i["test_performance"]))
if 'test_performance' in i.keys():
performance_gauge.add_metric([i["test_id"]], (i["test_performance"]))

yield performance_gauge

0 comments on commit f245a02

Please sign in to comment.