diff --git a/shynet/analytics/migrations/0003_auto_20200410_1325.py b/shynet/analytics/migrations/0003_auto_20200410_1325.py new file mode 100644 index 0000000..488933b --- /dev/null +++ b/shynet/analytics/migrations/0003_auto_20200410_1325.py @@ -0,0 +1,21 @@ +# Generated by Django 3.0.5 on 2020-04-10 17:25 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('analytics', '0002_auto_20200410_0258'), + ] + + operations = [ + migrations.RemoveField( + model_name='hit', + name='metadata_raw', + ), + migrations.RemoveField( + model_name='session', + name='metadata_raw', + ), + ] diff --git a/shynet/analytics/models.py b/shynet/analytics/models.py index c81b1f6..2f3218e 100644 --- a/shynet/analytics/models.py +++ b/shynet/analytics/models.py @@ -35,16 +35,6 @@ class Session(models.Model): latitude = models.FloatField(null=True) time_zone = models.TextField(blank=True) - # Additional metadata, stored as JSON string - metadata_raw = models.TextField() - - @property - def metadata(self): - try: - return json.loads(self.metadata_raw) - except: # Metadata is not crucial; in the case of a read error, just ignore it - return {} - class Hit(models.Model): session = models.ForeignKey(Session, on_delete=models.CASCADE) @@ -60,13 +50,4 @@ class Hit(models.Model): referrer = models.TextField(blank=True) loadTime = models.FloatField(null=True) httpStatus = models.IntegerField(null=True) - - # Additional metadata, stored as JSON string - metadata_raw = models.TextField() - - @property - def metadata(self): - try: - return json.loads(self.metadata_raw) - except: # Metadata is not crucial; in the case of a read error, just ignore it - return {} + \ No newline at end of file diff --git a/shynet/analytics/tasks.py b/shynet/analytics/tasks.py index 5848a57..1cf910e 100644 --- a/shynet/analytics/tasks.py +++ b/shynet/analytics/tasks.py @@ -50,7 +50,6 @@ def ingress_request( log.debug(f"Linked to service {service}") # Create or update session - session_metadata = payload.get("sessionMetadata", {}) session = Session.objects.filter( service=service, last_seen__gt=timezone.now() - timezone.timedelta(minutes=30), @@ -70,7 +69,6 @@ def ingress_request( browser=f"{ua.browser.family or ''} {ua.browser.version_string or ''}".strip(), device=f"{ua.device.model or ''}", os=f"{ua.os.family or ''} {ua.os.version_string or ''}".strip(), - metadata_raw=json.dumps(session_metadata), asn=ip_data.get("asn", ""), country=ip_data.get("country", ""), longitude=ip_data.get("longitude"), @@ -79,16 +77,11 @@ def ingress_request( ) else: log.debug("Updating old session with new data...") - # Update old metadata with new metadata - new_metadata = session.metadata - new_metadata.update(session_metadata) - session.metadata_raw = json.dumps(new_metadata) # Update last seen time session.last_seen = timezone.now() session.save() # Create or update hit - hit_metadata = payload.get("hitMetadata", {}) idempotency = payload.get("idempotency") idempotency_path = f"hit_idempotency_{idempotency}" hit = None @@ -103,9 +96,6 @@ def ingress_request( log.debug("Hit is a heartbeat; updating old hit with new data...") hit.heartbeats += 1 hit.duration = (timezone.now() - hit.start).total_seconds() - new_metadata = hit.metadata - new_metadata.update(hit_metadata) - hit.metadata_raw = json.dumps(new_metadata) hit.save() if hit is None: log.debug("Hit is a page load; creating new hit...") @@ -116,10 +106,10 @@ def ingress_request( location=location, referrer=payload.get("referrer", ""), loadTime=payload.get("loadTime"), - metadata_raw=json.dumps(hit_metadata), ) # Set idempotency (if applicable) if idempotency is not None: cache.set(idempotency_path, hit.pk, timeout=30 * 60) except Exception as e: - log.error(e) + log.exception(e) + raise e diff --git a/shynet/analytics/templates/analytics/scripts/page.js b/shynet/analytics/templates/analytics/scripts/page.js index fa54c98..f2f80df 100644 --- a/shynet/analytics/templates/analytics/scripts/page.js +++ b/shynet/analytics/templates/analytics/scripts/page.js @@ -13,12 +13,6 @@ window.onload = function () { loadTime: window.performance.timing.domContentLoadedEventEnd - window.performance.timing.navigationStart, - hitMetadata: - typeof shynetHitMetadata !== "undefined" ? shynetHitMetadata : {}, - sessionMetadata: - typeof shynetSessionMetadata !== "undefined" - ? shynetSessionMetadata - : {}, }) ); }