analytics: Remove Anomaly model.

This commit is contained in:
Rishi Gupta
2019-02-01 18:47:31 -08:00
parent 1f4de8328d
commit 85f7ac8172
6 changed files with 38 additions and 23 deletions

View File

@@ -9,7 +9,7 @@ from django.conf import settings
from django.db import connection, models from django.db import connection, models
from django.db.models import F from django.db.models import F
from analytics.models import Anomaly, BaseCount, \ from analytics.models import BaseCount, \
FillState, InstallationCount, RealmCount, StreamCount, \ FillState, InstallationCount, RealmCount, StreamCount, \
UserCount, installation_epoch, last_successful_fill UserCount, installation_epoch, last_successful_fill
from zerver.lib.logging_util import log_to_file from zerver.lib.logging_util import log_to_file
@@ -226,7 +226,6 @@ def do_drop_all_analytics_tables() -> None:
RealmCount.objects.all().delete() RealmCount.objects.all().delete()
InstallationCount.objects.all().delete() InstallationCount.objects.all().delete()
FillState.objects.all().delete() FillState.objects.all().delete()
Anomaly.objects.all().delete()
def do_drop_single_stat(property: str) -> None: def do_drop_single_stat(property: str) -> None:
UserCount.objects.filter(property=property).delete() UserCount.objects.filter(property=property).delete()

View File

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-02-02 02:47
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('analytics', '0012_add_on_delete'),
]
operations = [
migrations.RemoveField(
model_name='installationcount',
name='anomaly',
),
migrations.RemoveField(
model_name='realmcount',
name='anomaly',
),
migrations.RemoveField(
model_name='streamcount',
name='anomaly',
),
migrations.RemoveField(
model_name='usercount',
name='anomaly',
),
migrations.DeleteModel(
name='Anomaly',
),
]

View File

@@ -34,13 +34,6 @@ def last_successful_fill(property: str) -> Optional[datetime.datetime]:
return fillstate.end_time return fillstate.end_time
return fillstate.end_time - datetime.timedelta(hours=1) return fillstate.end_time - datetime.timedelta(hours=1)
# would only ever make entries here by hand
class Anomaly(models.Model):
info = models.CharField(max_length=1000) # type: str
def __str__(self) -> str:
return "<Anomaly: %s... %s>" % (self.info, self.id)
class BaseCount(models.Model): class BaseCount(models.Model):
# Note: When inheriting from BaseCount, you may want to rearrange # Note: When inheriting from BaseCount, you may want to rearrange
# the order of the columns in the migration to make sure they # the order of the columns in the migration to make sure they
@@ -49,7 +42,6 @@ class BaseCount(models.Model):
subgroup = models.CharField(max_length=16, null=True) # type: Optional[str] subgroup = models.CharField(max_length=16, null=True) # type: Optional[str]
end_time = models.DateTimeField() # type: datetime.datetime end_time = models.DateTimeField() # type: datetime.datetime
value = models.BigIntegerField() # type: int value = models.BigIntegerField() # type: int
anomaly = models.ForeignKey(Anomaly, on_delete=models.SET_NULL, null=True) # type: Optional[Anomaly]
class Meta: class Meta:
abstract = True abstract = True

View File

@@ -15,7 +15,7 @@ from analytics.lib.counts import COUNT_STATS, CountStat, DataCollector, \
do_drop_all_analytics_tables, do_drop_single_stat, \ do_drop_all_analytics_tables, do_drop_single_stat, \
do_fill_count_stat_at_hour, do_increment_logging_stat, \ do_fill_count_stat_at_hour, do_increment_logging_stat, \
process_count_stat, sql_data_collector process_count_stat, sql_data_collector
from analytics.models import Anomaly, BaseCount, \ from analytics.models import BaseCount, \
FillState, InstallationCount, RealmCount, StreamCount, \ FillState, InstallationCount, RealmCount, StreamCount, \
UserCount, installation_epoch, last_successful_fill UserCount, installation_epoch, last_successful_fill
from zerver.lib.actions import do_activate_user, do_create_user, \ from zerver.lib.actions import do_activate_user, do_create_user, \
@@ -846,7 +846,6 @@ class TestDeleteStats(AnalyticsTestCase):
RealmCount.objects.create(realm=user.realm, **count_args) RealmCount.objects.create(realm=user.realm, **count_args)
InstallationCount.objects.create(**count_args) InstallationCount.objects.create(**count_args)
FillState.objects.create(property='test', end_time=self.TIME_ZERO, state=FillState.DONE) FillState.objects.create(property='test', end_time=self.TIME_ZERO, state=FillState.DONE)
Anomaly.objects.create(info='test anomaly')
analytics = apps.get_app_config('analytics') analytics = apps.get_app_config('analytics')
for table in list(analytics.models.values()): for table in list(analytics.models.values()):
@@ -869,7 +868,6 @@ class TestDeleteStats(AnalyticsTestCase):
InstallationCount.objects.create(**count_args) InstallationCount.objects.create(**count_args)
FillState.objects.create(property='to_delete', end_time=self.TIME_ZERO, state=FillState.DONE) FillState.objects.create(property='to_delete', end_time=self.TIME_ZERO, state=FillState.DONE)
FillState.objects.create(property='to_save', end_time=self.TIME_ZERO, state=FillState.DONE) FillState.objects.create(property='to_save', end_time=self.TIME_ZERO, state=FillState.DONE)
Anomaly.objects.create(info='test anomaly')
analytics = apps.get_app_config('analytics') analytics = apps.get_app_config('analytics')
for table in list(analytics.models.values()): for table in list(analytics.models.values()):
@@ -877,11 +875,8 @@ class TestDeleteStats(AnalyticsTestCase):
do_drop_single_stat('to_delete') do_drop_single_stat('to_delete')
for table in list(analytics.models.values()): for table in list(analytics.models.values()):
if table._meta.db_table == 'analytics_anomaly': self.assertFalse(table.objects.filter(property='to_delete').exists())
self.assertTrue(table.objects.exists()) self.assertTrue(table.objects.filter(property='to_save').exists())
else:
self.assertFalse(table.objects.filter(property='to_delete').exists())
self.assertTrue(table.objects.filter(property='to_save').exists())
class TestActiveUsersAudit(AnalyticsTestCase): class TestActiveUsersAudit(AnalyticsTestCase):
def setUp(self) -> None: def setUp(self) -> None:

View File

@@ -51,8 +51,6 @@ set of database tables. Each of these tables has the following fields:
"messages_sent:client:day" in the UserCount table, this is the number of "messages_sent:client:day" in the UserCount table, this is the number of
messages sent by a particular user, from a particular client, on the day messages sent by a particular user, from a particular client, on the day
ending at end_time. ending at end_time.
- anomaly: Currently unused, but a key into the Anomaly table allowing
someone to indicate a data irregularity.
There are four tables: UserCount, StreamCount, RealmCount, and There are four tables: UserCount, StreamCount, RealmCount, and
InstallationCount. Every CountStat is initially collected into UserCount, InstallationCount. Every CountStat is initially collected into UserCount,

View File

@@ -57,7 +57,6 @@ MessageOutput = Dict[str, Union[List[Record], List[int], int]]
MESSAGE_BATCH_CHUNK_SIZE = 1000 MESSAGE_BATCH_CHUNK_SIZE = 1000
ALL_ZULIP_TABLES = { ALL_ZULIP_TABLES = {
'analytics_anomaly',
'analytics_fillstate', 'analytics_fillstate',
'analytics_installationcount', 'analytics_installationcount',
'analytics_realmcount', 'analytics_realmcount',
@@ -174,8 +173,6 @@ NON_EXPORTED_TABLES = {
# Fillstate will require some cleverness to do the right partial export. # Fillstate will require some cleverness to do the right partial export.
'analytics_fillstate', 'analytics_fillstate',
# This table isn't yet used for anything.
'analytics_anomaly',
# These are for unfinished features; we'll want to add them ot the # These are for unfinished features; we'll want to add them ot the
# export before they reach full production status. # export before they reach full production status.