mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Improve Prometheus Alert Rule error message (#29390)
* provide better ctx for prom err * rework * Update pkg/tsdb/prometheus/prometheus.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/tsdb/prometheus/prometheus.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * call func Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/tsdb/prometheus"
|
||||
|
||||
gocontext "context"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
@@ -159,11 +161,7 @@ func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange *
|
||||
|
||||
resp, err := c.HandleRequest(context.Ctx, getDsInfo.Result, req)
|
||||
if err != nil {
|
||||
if errors.Is(err, gocontext.DeadlineExceeded) {
|
||||
return nil, fmt.Errorf("alert execution exceeded the timeout")
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("tsdb.HandleRequest() error %v", err)
|
||||
return nil, toCustomError(err)
|
||||
}
|
||||
|
||||
for _, v := range resp.Results {
|
||||
@@ -360,3 +358,18 @@ func FrameToSeriesSlice(frame *data.Frame) (tsdb.TimeSeriesSlice, error) {
|
||||
|
||||
return seriesSlice, nil
|
||||
}
|
||||
|
||||
func toCustomError(err error) error {
|
||||
// is context timeout
|
||||
if errors.Is(err, gocontext.DeadlineExceeded) {
|
||||
return fmt.Errorf("alert execution exceeded the timeout")
|
||||
}
|
||||
|
||||
// is Prometheus error
|
||||
if prometheus.IsAPIError(err) {
|
||||
return prometheus.ConvertAPIError(err)
|
||||
}
|
||||
|
||||
// generic fallback
|
||||
return fmt.Errorf("tsdb.HandleRequest() error %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user