Skip to main content

parse_thresholds

Function parse_thresholds 

Source
pub fn parse_thresholds(
    json_or_yaml: &str,
) -> Result<Vec<Threshold>, ThresholdError>
Expand description

Parses a list of thresholds from a JSON or YAML string.

The input must be an object with a "thresholds" key whose value is an array of threshold objects:

{ "thresholds": [{ "metric": "latency_p99", "operator": "lt", "value": 200.0 }] }

or equivalently in YAML:

thresholds:
  - metric: latency_p99
    operator: lt
    value: 200.0

JSON is attempted first; if that fails, YAML is attempted. If both fail, the JSON error is returned wrapped in ThresholdError::ParseError.

Each threshold is then validated:

  • value must be finite
  • For error_rate, value must be in [0.0, 1.0]