Ejemplo n.º 1
0
 def serialize(self, obj, attrs, user):
     env = obj.snuba_query.environment
     # Temporary: Translate aggregate back here from `tags[sentry:user]` to `user` for the frontend.
     aggregate = translate_aggregate_field(obj.snuba_query.aggregate,
                                           reverse=True)
     return {
         "id": six.text_type(obj.id),
         "name": obj.name,
         "organizationId": six.text_type(obj.organization_id),
         "status": obj.status,
         "dataset": obj.snuba_query.dataset,
         "query": obj.snuba_query.query,
         "aggregate": aggregate,
         "thresholdType": obj.threshold_type,
         "resolveThreshold": obj.resolve_threshold,
         # TODO: Start having the frontend expect seconds
         "timeWindow": obj.snuba_query.time_window / 60,
         "environment": env.name if env else None,
         # TODO: Start having the frontend expect seconds
         "resolution": obj.snuba_query.resolution / 60,
         "thresholdPeriod": obj.threshold_period,
         "triggers": attrs.get("triggers", []),
         "projects": sorted(attrs.get("projects", [])),
         "includeAllProjects": obj.include_all_projects,
         "dateModified": obj.date_modified,
         "dateCreated": obj.date_added,
         "createdBy": attrs.get("created_by", None),
     }
Ejemplo n.º 2
0
 def validate_aggregate(self, aggregate):
     try:
         if not check_aggregate_column_support(aggregate):
             raise serializers.ValidationError(
                 "Invalid Metric: We do not currently support this field.")
     except InvalidSearchQuery as e:
         raise serializers.ValidationError(f"Invalid Metric: {e}")
     return translate_aggregate_field(aggregate)