From 61066e0ec7ed2613a159f9f7967a5dfe0ccabd9c Mon Sep 17 00:00:00 2001 From: M1ha Date: Fri, 16 Nov 2018 17:41:54 +0500 Subject: [PATCH] statsd metrics set up --- src/django_clickhouse/engines.py | 7 ++++++- tests/test_sync.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/django_clickhouse/engines.py b/src/django_clickhouse/engines.py index dbf1761..ed144d9 100644 --- a/src/django_clickhouse/engines.py +++ b/src/django_clickhouse/engines.py @@ -6,6 +6,8 @@ from typing import List, TypeVar, Type from django.db.models import Model as DjangoModel from infi.clickhouse_orm import engines as infi_engines 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 .configuration import config @@ -72,7 +74,10 @@ class CollapsingMergeTree(InsertOnlyEngineMixin, infi_engines.CollapsingMergeTre :return: A list of model_cls 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: self.set_obj_sign(obj, -1) diff --git a/tests/test_sync.py b/tests/test_sync.py index d8c9939..9b5a995 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -43,6 +43,7 @@ class SyncTest(TransactionTestCase): ClickHouseCollapseTestModel.sync_batch_from_storage() 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.value, synced_data[0].value) self.assertEqual(obj.id, synced_data[0].id)