// analyzeWithThreshold returns false if any data point is out of the prediction range.
// Return an error if the evaluation could not be executed normally.
analyzeWithThreshold returns false if any data point is out of the prediction range.
Return an error if the evaluation could not be executed normally.
// analyzeWithThreshold returns false if any data point is out of the prediction range . // Return an error if the evaluation could not be executed normally .
func (a *metricsAnalyzer) analyzeWithThreshold(ctx context.Context) (bool, error) {
	if err := a.cfg.Expected.Validate(); err != nil {
		return false, fmt.Errorf("\"expected\" is required to analyze with the THRESHOLD strategy")
	}
	now := time.Now()
	queryRange := metrics.QueryRange{
		From: now.Add(-a.cfg.Interval.Duration()),
		To:   now,
	}
	points, err := a.provider.QueryPoints(ctx, a.cfg.Query, queryRange)
	if err != nil {
		return false, fmt.Errorf("failed to run query: %w", err)
	}
	var outiler metrics.DataPoint
	expected := true
	for i := range points {
		if a.cfg.Expected.InRange(points[i].Value) {
			continue
		}
		expected = false
		outiler = points[i]
		break
	}
	if !expected {
		a.logPersister.Errorf("[%s] Failed because it found a data point (%s) that is outside the expected range (%s). Performed query: %q", a.id, &outiler, &a.cfg.Expected, a.cfg.Query)
		return false, nil
	}
	return true, nil
}
func ( a * metricsAnalyzer ) analyzeWithThreshold ( ctx context . Context ) ( bool , error ) { if err := a . cfg . Expected . Validate ( ) ; err != nil { return false , fmt . Errorf ( " \" \" " ) } now := time . Now ( ) queryRange := metrics . QueryRange { From : now . Add ( - a . cfg . Interval . Duration ( ) ) , To : now , } points , err := a . provider . QueryPoints ( ctx , a . cfg . Query , queryRange ) if err != nil { return false , fmt . Errorf ( " " , err ) } var outiler metrics . DataPoint expected := true for i := range points { if a . cfg . Expected . InRange ( points [ i ] . Value ) { continue } expected = false outiler = points [ i ] break } if ! expected { a . logPersister . Errorf ( " " , a . id , & outiler , & a . cfg . Expected , a . cfg . Query ) return false , nil } return true , nil }
analyzeWithThreshold returns false if any data point is out of the prediction range.
analyzeWithThreshold returns false if any data point is out of the prediction range .