statsd metrics set up

This commit is contained in:
M1ha 2018-11-16 17:41:54 +05:00
parent e0fe50d534
commit 61066e0ec7
2 changed files with 7 additions and 1 deletions

View File

@ -6,6 +6,8 @@ from typing import List, TypeVar, Type
from django.db.models import Model as DjangoModel from django.db.models import Model as DjangoModel
from infi.clickhouse_orm import engines as infi_engines from infi.clickhouse_orm import engines as infi_engines
from infi.clickhouse_orm.database import Database from infi.clickhouse_orm.database import Database
from infi.clickhouse_orm.models import Model as InfiModel
from statsd.defaults.django import statsd
from django_clickhouse.database import connections from django_clickhouse.database import connections
from .configuration import config from .configuration import config
@ -72,7 +74,10 @@ class CollapsingMergeTree(InsertOnlyEngineMixin, infi_engines.CollapsingMergeTre
:return: A list of model_cls objects :return: A list of model_cls objects
""" """
new_objs = super(CollapsingMergeTree, self).get_insert_batch(model_cls, database, objects) new_objs = super(CollapsingMergeTree, self).get_insert_batch(model_cls, database, objects)
old_objs = self.get_final_versions(model_cls, new_objs)
statsd_key = "%s.sync.%s.get_final_versions" % (config.STATSD_PREFIX, model_cls.__name__)
with statsd.timer(statsd_key):
old_objs = self.get_final_versions(model_cls, new_objs)
for obj in old_objs: for obj in old_objs:
self.set_obj_sign(obj, -1) self.set_obj_sign(obj, -1)

View File

@ -43,6 +43,7 @@ class SyncTest(TransactionTestCase):
ClickHouseCollapseTestModel.sync_batch_from_storage() ClickHouseCollapseTestModel.sync_batch_from_storage()
synced_data = list(self.db.select('SELECT * FROM $table FINAL', model_class=ClickHouseCollapseTestModel)) synced_data = list(self.db.select('SELECT * FROM $table FINAL', model_class=ClickHouseCollapseTestModel))
self.assertGreaterEqual(1, len(synced_data))
self.assertEqual(obj.created_date, synced_data[0].created_date) self.assertEqual(obj.created_date, synced_data[0].created_date)
self.assertEqual(obj.value, synced_data[0].value) self.assertEqual(obj.value, synced_data[0].value)
self.assertEqual(obj.id, synced_data[0].id) self.assertEqual(obj.id, synced_data[0].id)