Skip to content

Commit

Permalink
Merge pull request #5743 from nyaruka/remove_unneeded_gauge
Browse files Browse the repository at this point in the history
Remove gauges from analytics abstraction
  • Loading branch information
rowanseymour authored Dec 11, 2024
2 parents 5a82b3e + 7f4c579 commit 934a84a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 39 deletions.
7 changes: 1 addition & 6 deletions temba/channels/android/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from temba.msgs.models import Msg
from temba.notifications.incidents.builtin import ChannelOutdatedAppIncidentType
from temba.notifications.models import Incident
from temba.utils import analytics, json
from temba.utils import json

from ..models import Channel, SyncEvent
from .claim import UnsupportedAndroidChannelError, get_or_create_channel
Expand Down Expand Up @@ -50,8 +50,6 @@ def register(request):
@csrf_exempt
@transaction.non_atomic_requests
def sync(request, channel_id):
start = time.time()

if request.method != "POST":
return HttpResponse(status=500, content="POST Required")

Expand Down Expand Up @@ -236,7 +234,4 @@ def sync(request, channel_id):
sync_event.outgoing_command_count = len([_ for _ in outgoing_cmds if _["cmd"] != "ack"])
sync_event.save()

# keep track of how long a sync takes
analytics.gauges({"temba.relayer_sync": time.time() - start})

return JsonResponse(result)
21 changes: 0 additions & 21 deletions temba/utils/analytics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class AnalyticsBackend(metaclass=abc.ABCMeta):
slug: str = None
hook_templates = {}

def gauges(self, values: dict):
"""
Records gauge values
"""

def track(self, user, event: str, properties: dict):
"""
Tracks a user event
Expand Down Expand Up @@ -52,11 +47,6 @@ class ConsoleBackend(AnalyticsBackend):

slug = "console"

def gauges(self, values: dict):
if not settings.TESTING: # pragma: no cover
for name, value in values.items():
print(f"[analytics] gauge={name} value={value}")

def track(self, user, event: str, properties: dict):
if not settings.TESTING: # pragma: no cover
print(f"[analytics] event={event} user={user.email}")
Expand All @@ -68,17 +58,6 @@ def get_backends() -> list:
return list(backends.values())


def gauges(values: dict):
"""
Reports a gauge value
"""
for backend in get_backends():
try:
backend.gauges(values)
except Exception:
logger.exception(f"error reporting gauges on {backend.slug}")


def identify(user, brand, org):
"""
Creates and identifies a new user to our analytics backends
Expand Down
12 changes: 0 additions & 12 deletions temba/utils/analytics/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ class AnalyticsTest(TembaTest):
def setUp(self):
super().setUp()

@patch("temba.utils.analytics.base.get_backends")
def test_gauges(self, mock_get_backends):
good = MagicMock()
mock_get_backends.return_value = [BadBackend(), good]

analytics.gauges({"foo_level": 123})

good.gauges.assert_called_once_with({"foo_level": 123})

@patch("temba.utils.analytics.base.get_backends")
def test_track(self, mock_get_backends):
good = MagicMock()
Expand Down Expand Up @@ -92,9 +83,6 @@ class BadBackend(AnalyticsBackend):
slug = "bad"
hook_templates = {"frame-top": "bad/frame_top.html"}

def gauges(self, values: dict):
raise ValueError("boom")

def track(self, user, event: str, properties: dict):
raise ValueError("boom")

Expand Down

0 comments on commit 934a84a

Please sign in to comment.