Skip to content
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

feat: if timescale is down don't crash #420

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions helpers/telemetry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import asyncio
import logging
from datetime import datetime

import django
from asgiref.sync import sync_to_async
from psycopg2 import OperationalError
from shared.django_apps.pg_telemetry.models import SimpleMetric as PgSimpleMetric
from shared.django_apps.ts_telemetry.models import SimpleMetric as TsSimpleMetric

Expand All @@ -11,6 +13,8 @@

from .timeseries import timeseries_enabled

log = logging.getLogger(__name__)


def fire_and_forget(fn):
"""
Expand Down Expand Up @@ -131,14 +135,19 @@
)

if timeseries_enabled():
TsSimpleMetric.objects.create(
timestamp=timestamp,
name=name,
value=value,
repo_slug=self.repo_slug,
owner_slug=self.owner_slug,
commit_slug=self.commit_slug,
)
try:
TsSimpleMetric.objects.create(

Check warning on line 139 in helpers/telemetry.py

View check run for this annotation

Codecov - QA / codecov/patch

helpers/telemetry.py#L138-L139

Added lines #L138 - L139 were not covered by tests

Check warning on line 139 in helpers/telemetry.py

View check run for this annotation

Codecov Public QA / codecov/patch

helpers/telemetry.py#L138-L139

Added lines #L138 - L139 were not covered by tests
timestamp=timestamp,
name=name,
value=value,
repo_slug=self.repo_slug,
owner_slug=self.owner_slug,
commit_slug=self.commit_slug,
)
except OperationalError:
log.warning(

Check warning on line 148 in helpers/telemetry.py

View check run for this annotation

Codecov - QA / codecov/patch

helpers/telemetry.py#L147-L148

Added lines #L147 - L148 were not covered by tests

Check warning on line 148 in helpers/telemetry.py

View check run for this annotation

Codecov Public QA / codecov/patch

helpers/telemetry.py#L147-L148

Added lines #L147 - L148 were not covered by tests
"Failed to create TsSimpleMetric object, Timescale may be unavailable. However we will continue the current task."
)

@fire_and_forget
async def attempt_log_simple_metric(self, name: str, value: float):
Expand Down
Loading