Skip to content

Commit 868da3e

Browse files
authored
Merge pull request #326 from bookingcom/dams/info-500
return 404 instead of 500 when info-ing a non-existing metric
2 parents 8ea4ba7 + 9bd6c6d commit 868da3e

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

app/carbonapi/http_handlers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,14 @@ func (app *App) infoHandler(w http.ResponseWriter, r *http.Request) {
951951
request.IncCall()
952952
infos, err := app.backend.Info(ctx, request)
953953
if err != nil {
954+
var notFound dataTypes.ErrNotFound
955+
if errors.As(err, &notFound) {
956+
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
957+
toLog.HttpCode = http.StatusNotFound
958+
toLog.Reason = "info not found"
959+
logAsError = true
960+
return
961+
}
954962
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
955963
toLog.HttpCode = http.StatusInternalServerError
956964
toLog.Reason = err.Error()

app/carbonzipper/http_handlers.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,18 @@ func (app *App) infoHandler(w http.ResponseWriter, req *http.Request) {
456456
infos, errs := backend.Infos(ctx, bs, request)
457457
err = errorsFanIn(ctx, errs, len(bs))
458458
if err != nil {
459+
460+
var notFound types.ErrNotFound
461+
if errors.As(err, &notFound) {
462+
accessLogger.Error("info not found",
463+
zap.Int("http_code", http.StatusNotFound),
464+
zap.Error(err),
465+
zap.Duration("runtime_seconds", time.Since(t0)),
466+
)
467+
http.Error(w, "info: not found", http.StatusNotFound)
468+
return
469+
}
470+
459471
accessLogger.Error("info failed",
460472
zap.Int("http_code", http.StatusInternalServerError),
461473
zap.Error(err),

pkg/backend/net/net.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ func (b Backend) Info(ctx context.Context, request types.InfoRequest) ([]types.I
392392
request.Trace.AddMarshal(t0)
393393

394394
_, resp, err := b.call(ctx, request.Trace, u, body)
395+
396+
if code, ok := err.(ErrHTTPCode); ok && code == http.StatusNotFound {
397+
return nil, types.ErrInfoNotFound
398+
}
399+
395400
if err != nil {
396401
return nil, errors.Wrap(err, "HTTP call failed")
397402
}

0 commit comments

Comments
 (0)