def validate_field(self, fields): if len(fields) > 1: # Due to how the data is stored in snuba, multihistograms # are only possible when they are all measurements. if any(not is_measurement(field) for field in fields): detail = "You can only generate histogram for one column at a time unless they are all measurements." raise serializers.ValidationError(detail) return fields
def check_multihistogram_fields(fields): """ Returns multihistogram type if all the given fields are of the same histogram type. Return false otherwise, or if any of the fields are not a compatible histogram type. Possible histogram types: measurements, span_op_breakdowns :param [str] fields: The list of fields for which you want to generate histograms for. """ histogram_type = False for field in fields: if histogram_type is False: if is_measurement(field): histogram_type = "measurements" elif is_span_op_breakdown(field): histogram_type = "span_op_breakdowns" else: return False elif histogram_type == "measurements" and not is_measurement(field): return False elif histogram_type == "span_op_breakdowns" and not is_span_op_breakdown(field): return False return histogram_type
def populate_measurements(self, specs): start = before_now(minutes=5) for spec in specs: spec = HistogramSpec(*spec) for field, count in spec.fields: if not is_measurement(field): continue measurement = get_measurement_name(field) for i in range(count): data = deepcopy(self.data) data["timestamp"] = iso_format(start) data["start_timestamp"] = iso_format(start - timedelta(seconds=i)) value = random.random() * (spec.end - spec.start) + spec.start data["transaction"] = "/measurement/{}/value/{}".format(measurement, value) data["measurements"] = {measurement: {"value": value}} self.store_event(data, self.project.id)
def is_numeric_key(self, key): return key in self.numeric_keys or is_measurement(key)
def is_measurement(self): return is_measurement(self.name) and self.name not in SEARCH_MAP
def is_fuzzy_numeric_key(key): return key in FUZZY_NUMERIC_KEYS or snuba.is_measurement(key) or snuba.is_span_op_breakdown(key)
def is_numeric_key(self, key): return key in self.config.numeric_keys or is_measurement(key) or is_span_op_breakdown(key)