mirror of
https://github.com/carrotquest/django-clickhouse.git
synced 2025-07-10 16:12:24 +03:00
Fixes in statsd keys
This commit is contained in:
parent
578fc6c939
commit
38db27626c
|
@ -190,26 +190,26 @@ class ClickHouseModel(with_metaclass(ClickHouseModelMeta, InfiModel)):
|
||||||
storage = cls.get_storage()
|
storage = cls.get_storage()
|
||||||
import_key = cls.get_import_key()
|
import_key = cls.get_import_key()
|
||||||
|
|
||||||
with statsd.timer(statsd_key.format('pre_sync')):
|
with statsd.timer(statsd_key.format('steps.pre_sync')):
|
||||||
storage.pre_sync(import_key, lock_timeout=cls.get_lock_timeout())
|
storage.pre_sync(import_key, lock_timeout=cls.get_lock_timeout())
|
||||||
|
|
||||||
with statsd.timer(statsd_key.format('get_operations')):
|
with statsd.timer(statsd_key.format('steps.get_operations')):
|
||||||
operations = storage.get_operations(import_key, cls.get_sync_batch_size())
|
operations = storage.get_operations(import_key, cls.get_sync_batch_size())
|
||||||
|
|
||||||
if operations:
|
if operations:
|
||||||
with statsd.timer(statsd_key.format('get_sync_objects')):
|
with statsd.timer(statsd_key.format('steps.get_sync_objects')):
|
||||||
import_objects = cls.get_sync_objects(operations)
|
import_objects = cls.get_sync_objects(operations)
|
||||||
else:
|
else:
|
||||||
import_objects = []
|
import_objects = []
|
||||||
|
|
||||||
if import_objects:
|
if import_objects:
|
||||||
with statsd.timer(statsd_key.format('get_insert_batch')):
|
with statsd.timer(statsd_key.format('steps.get_insert_batch')):
|
||||||
batch = cls.get_insert_batch(import_objects)
|
batch = cls.get_insert_batch(import_objects)
|
||||||
|
|
||||||
with statsd.timer(statsd_key.format('insert')):
|
with statsd.timer(statsd_key.format('steps.insert')):
|
||||||
cls.insert_batch(batch)
|
cls.insert_batch(batch)
|
||||||
|
|
||||||
with statsd.timer(statsd_key.format('post_sync')):
|
with statsd.timer(statsd_key.format('steps.post_sync')):
|
||||||
storage.post_sync(import_key)
|
storage.post_sync(import_key)
|
||||||
|
|
||||||
storage.set_last_sync_time(import_key, now())
|
storage.set_last_sync_time(import_key, now())
|
||||||
|
@ -252,29 +252,29 @@ class ClickHouseMultiModel(ClickHouseModel):
|
||||||
storage = cls.get_storage()
|
storage = cls.get_storage()
|
||||||
import_key = cls.get_import_key()
|
import_key = cls.get_import_key()
|
||||||
|
|
||||||
with statsd.timer(statsd_key.format('pre_sync')):
|
with statsd.timer(statsd_key.format('steps.pre_sync')):
|
||||||
storage.pre_sync(import_key, lock_timeout=cls.get_lock_timeout())
|
storage.pre_sync(import_key, lock_timeout=cls.get_lock_timeout())
|
||||||
|
|
||||||
with statsd.timer(statsd_key.format('get_operations')):
|
with statsd.timer(statsd_key.format('steps.get_operations')):
|
||||||
operations = storage.get_operations(import_key, cls.get_sync_batch_size())
|
operations = storage.get_operations(import_key, cls.get_sync_batch_size())
|
||||||
|
|
||||||
if operations:
|
if operations:
|
||||||
with statsd.timer(statsd_key.format('get_sync_objects')):
|
with statsd.timer(statsd_key.format('steps.get_sync_objects')):
|
||||||
import_objects = cls.get_sync_objects(operations)
|
import_objects = cls.get_sync_objects(operations)
|
||||||
else:
|
else:
|
||||||
import_objects = []
|
import_objects = []
|
||||||
|
|
||||||
if import_objects:
|
if import_objects:
|
||||||
batches = {}
|
batches = {}
|
||||||
with statsd.timer(statsd_key.format('get_insert_batch')):
|
with statsd.timer(statsd_key.format('steps.get_insert_batch')):
|
||||||
for model_cls in cls.sub_models:
|
for model_cls in cls.sub_models:
|
||||||
batches[model_cls] = model_cls.get_insert_batch(import_objects)
|
batches[model_cls] = model_cls.get_insert_batch(import_objects)
|
||||||
|
|
||||||
with statsd.timer(statsd_key.format('insert')):
|
with statsd.timer(statsd_key.format('steps.insert')):
|
||||||
for model_cls, batch in batches.items():
|
for model_cls, batch in batches.items():
|
||||||
model_cls.insert_batch(batch)
|
model_cls.insert_batch(batch)
|
||||||
|
|
||||||
with statsd.timer(statsd_key.format('post_sync')):
|
with statsd.timer(statsd_key.format('steps.post_sync')):
|
||||||
storage.post_sync(import_key)
|
storage.post_sync(import_key)
|
||||||
storage.set_last_sync_time(import_key, now())
|
storage.set_last_sync_time(import_key, now())
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,8 @@ class Storage:
|
||||||
logger.debug('django-clickhouse: registered %s on %d items (%s) to storage'
|
logger.debug('django-clickhouse: registered %s on %d items (%s) to storage'
|
||||||
% (operation, len(pks), import_key))
|
% (operation, len(pks), import_key))
|
||||||
|
|
||||||
|
statsd_key = "%s.sync.%s.register_operations" % (config.STATSD_PREFIX, import_key)
|
||||||
|
with statsd.timer(statsd_key):
|
||||||
return self.register_operations(import_key, operation, *pks)
|
return self.register_operations(import_key, operation, *pks)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
|
|
|
@ -17,8 +17,6 @@ def sync_clickhouse_converter(cls): # type: (ClickHouseModel) -> None
|
||||||
:param cls: ClickHouseModel subclass
|
:param cls: ClickHouseModel subclass
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
statsd_key = "%s.sync.%s.time" % (config.STATSD_PREFIX, cls.__name__)
|
|
||||||
with statsd.timer(statsd_key):
|
|
||||||
cls.sync_batch_from_storage()
|
cls.sync_batch_from_storage()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user