def create_tag_objects(keys, total_count, top_values): tag_keys_dict = OrderedDict() for top_value in top_values: key = top_value['tags_key'] if key not in tag_keys_dict: tag_keys_dict[key] = TagKey( key=key, top_values=[], count=total_count, ) tag_keys_dict[key].top_values.append( TagValue( key=key, value=top_value['tags_value'], times_seen=top_value['count'], first_seen=top_value['first_seen'], last_seen=top_value['last_seen'], )) # Add categories with no values for key in keys: if key not in tag_keys_dict: tag_keys_dict[key] = TagKey( key=key, top_values=[], count=total_count, ) return tag_keys_dict.values()
def __get_tag_key(self, project_id, group_id, environment_id, key): tag = u"tags[{}]".format(key) filters = {"project_id": get_project_list(project_id)} if environment_id: filters["environment"] = [environment_id] if group_id is not None: filters["issue"] = [group_id] conditions = [[tag, "!=", ""]] aggregations = [["uniq", tag, "values_seen"], ["count()", "", "count"]] result = snuba.query( conditions=conditions, filter_keys=filters, aggregations=aggregations, referrer="tagstore.__get_tag_key", ) if result is None or result["count"] == 0: raise TagKeyNotFound if group_id is None else GroupTagKeyNotFound else: data = { "key": key, "values_seen": result["values_seen"], "count": result["count"] } if group_id is None: return TagKey(**data) else: return GroupTagKey(group_id=group_id, **data)
def __get_tag_key(self, project_id, group_id, environment_id, key): start, end = self.get_time_range() tag = u'tags[{}]'.format(key) filters = { 'project_id': [project_id], 'environment': [environment_id], } if group_id is not None: filters['issue'] = [group_id] conditions = [[tag, '!=', '']] aggregations = [['uniq', tag, 'values_seen'], ['count()', '', 'count']] result = snuba.query(start, end, [], conditions, filters, aggregations, referrer='tagstore.__get_tag_key') if result is None or result['count'] == 0: raise TagKeyNotFound if group_id is None else GroupTagKeyNotFound else: data = { 'key': key, 'values_seen': result['values_seen'], 'count': result['count'], } if group_id is None: return TagKey(**data) else: return GroupTagKey(group_id=group_id, **data)
def _create_tag_key_tag_value_objects(self, key, data): tag_values = [] values_seen = 0 for datum in data: tag_values.append(TagValue( key=key, value=datum['value'], times_seen=datum['count'], last_seen=datum['last_seen'], first_seen=datum['first_seen'], )) values_seen += datum['count'] tag_key = TagKey( key=key, values_seen=len(tag_values), count=values_seen, top_values=tag_values, ) return tag_key
from six.moves import reduce from sentry import buffer from sentry.tagstore import TagKeyStatus from sentry.tagstore.base import TagStorage, TOP_VALUES_DEFAULT_LIMIT from sentry.utils import db from . import models from sentry.tagstore.types import TagKey, TagValue, GroupTagKey, GroupTagValue from sentry.tasks.post_process import index_event_tags transformers = { models.TagKey: lambda instance: TagKey( key=instance.key, values_seen=instance.values_seen, status=instance.status, ), models.TagValue: lambda instance: TagValue( key=instance.key, value=instance.value, times_seen=instance.times_seen, first_seen=instance.first_seen, last_seen=instance.last_seen, ), models.GroupTagKey: lambda instance: GroupTagKey( group_id=instance.group_id, key=instance.key, values_seen=instance.values_seen, ), models.GroupTagValue: lambda instance: GroupTagValue(
from operator import or_ from six.moves import reduce from sentry import buffer from sentry.tagstore import TagKeyStatus from sentry.tagstore.base import TagStorage, TOP_VALUES_DEFAULT_LIMIT from sentry.utils import db from . import models from sentry.tagstore.types import TagKey, TagValue, GroupTagKey, GroupTagValue from sentry.tasks.post_process import index_event_tags transformers = { models.TagKey: lambda instance: TagKey(key=instance.key, values_seen=instance.values_seen, status=instance.status), models.TagValue: lambda instance: TagValue( key=instance.key, value=instance.value, times_seen=instance.times_seen, first_seen=instance.first_seen, last_seen=instance.last_seen, ), models.GroupTagKey: lambda instance: GroupTagKey(group_id=instance.group_id, key=instance.key, values_seen=instance.values_seen), models.GroupTagValue: lambda instance: GroupTagValue(