def __attrs_post_init__()

in lib/metric-config-parser/metric_config_parser/alert.py [0:0]


    def __attrs_post_init__(self):
        """Validate that the right parameters have been set depending on the alert type."""
        if self.type == AlertType.CI_OVERLAP:
            none_fields = ["min", "max", "window_size", "max_relative_change"]
        elif self.type == AlertType.THRESHOLD:
            none_fields = ["window_size", "max_relative_change"]
            if self.min is None and self.max is None:
                raise ValueError(
                    "Either 'max' or 'min' needs to be set when defining a threshold alert"
                )
            if self.min and self.parameters and len(self.min) != len(self.parameters):
                raise ValueError(
                    "Number of 'min' thresholds not matching number of parameters to monitor. "
                    + "A 'min' threshold needs to be specified for each percentile."
                )
            if self.max and self.parameters and len(self.max) != len(self.parameters):
                raise ValueError(
                    "Number of 'max' thresholds not matching number of parameters to monitor. "
                    + "A 'max' threshold needs to be specified for each percentile."
                )
        elif self.type == AlertType.AVG_DIFF:
            none_fields = ["min", "max"]
            if self.window_size is None:
                raise ValueError("'window_size' needs to be specified when using avg_diff alert")
            if self.max_relative_change is None:
                raise ValueError("'max_relative_change' to be specified when using avg_diff alert")

        for field in none_fields:
            if getattr(self, field) is not None:
                raise ValueError(
                    f"For alert of type {str(self.type)}, the parameter {field} must not be set"
                )