Skip to content

Commit dd80a87

Browse files
committed
Ignore 'metric not found' if there are cached results from other targets.
Before if there was a query with multiple targets that differ only in metrics that are missing a subsequent targets were treated as invalid because carbonapi was querying only for missing metrics and getting an error from zipper. E.g. a query: group(presentmetric,missingmetric) | min() group(presentmetric,othermissingmetric) | max() or a query: group(presentmetric,missingmetric) | min() group(presentmetric,missingmetric) | max() would return results only for the first target.
1 parent 46d57c6 commit dd80a87

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

expr/expr.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package expr
33
import (
44
"context"
55
"errors"
6+
"net/http"
7+
"strings"
68

79
"github.com/ansel1/merry"
810
pb "github.com/go-graphite/protocol/carbonapi_v3_pb"
@@ -17,6 +19,7 @@ import (
1719
"github.com/go-graphite/carbonapi/pkg/parser"
1820
utilctx "github.com/go-graphite/carbonapi/util/ctx"
1921
zipper "github.com/go-graphite/carbonapi/zipper/interfaces"
22+
zipperTypes "github.com/go-graphite/carbonapi/zipper/types"
2023
)
2124

2225
var ErrZipperNotInit = errors.New("zipper not initialized")
@@ -95,7 +98,13 @@ func (eval Evaluator) Fetch(ctx context.Context, exprs []parser.Expr, from, unti
9598

9699
if len(multiFetchRequest.Metrics) > 0 {
97100
metrics, _, err := eval.zipper.Render(ctx, multiFetchRequest)
98-
// If we had only partial result, we want to do our best to actually do our job
101+
// If we had only partial result, we want to do our best to actually do our job. Ignore 404 ErrNotFound errors
102+
// if there are some metrics cached from previous targets as we actually have the data - if we included all
103+
// metrics in batch we would get no error and proceed normally. Without this queries with multiple targets like
104+
// target=group(existing,notexisting)&target=group(existing,othernotexisting) would miss some results.
105+
if merry.HTTPCode(err) == http.StatusNotFound && strings.Contains(err.Error(), zipperTypes.ErrNotFound.Error()) && len(targetValues) > 0 {
106+
err = nil
107+
}
99108
if err != nil && merry.HTTPCode(err) >= 400 && !haveFallbackSeries {
100109
return nil, err
101110
}

0 commit comments

Comments
 (0)