Graphite: Improve functions endpoint (#111902)

Handle HTML response for functions endpoint

- If the endpoint starts with < return an error
- Update tests
- Catch error in FE and use default functions
This commit is contained in:
Andreas Christou
2025-10-01 20:04:34 +01:00
committed by GitHub
parent 0da9d49896
commit 4e2c3f19df
3 changed files with 39 additions and 7 deletions
+7 -1
View File
@@ -294,7 +294,13 @@ func (s *Service) handleFunctions(ctx context.Context, dsInfo *datasourceInfo, _
_, rawBody, statusCode, err := doGraphiteRequest[map[string]any](ctx, dsInfo, s.logger, req, true)
if err != nil {
return nil, statusCode, fmt.Errorf("version request failed: %v", err)
return nil, statusCode, fmt.Errorf("functions request failed: %v", err)
}
// It's possible that a HTML response may be returned
// This isn't valid so we'll return an error and use the default functions
if strings.HasPrefix(string(*rawBody), "<") {
return []byte{}, http.StatusNotAcceptable, fmt.Errorf("invalid functions response received from Graphite")
}
if rawBody == nil {