-
Notifications
You must be signed in to change notification settings - Fork 832
Translate internal store errors to prometheus API errors. #2571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import ( | |
"context" | ||
"flag" | ||
"fmt" | ||
"net/http" | ||
"sort" | ||
"sync" | ||
"time" | ||
|
@@ -15,8 +14,6 @@ import ( | |
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/prometheus/common/model" | ||
"github.com/prometheus/prometheus/pkg/labels" | ||
"github.com/prometheus/prometheus/promql" | ||
"github.com/weaveworks/common/httpgrpc" | ||
|
||
"github.com/cortexproject/cortex/pkg/chunk/cache" | ||
"github.com/cortexproject/cortex/pkg/util" | ||
|
@@ -26,11 +23,10 @@ import ( | |
) | ||
|
||
var ( | ||
ErrQueryMustContainMetricName = QueryError("query must contain metric name") | ||
ErrMetricNameLabelMissing = errors.New("metric name label missing") | ||
ErrParialDeleteChunkNoOverlap = errors.New("interval for partial deletion has not overlap with chunk interval") | ||
) | ||
|
||
var ( | ||
indexEntriesPerChunk = promauto.NewHistogram(prometheus.HistogramOpts{ | ||
Namespace: "cortex", | ||
Name: "chunk_store_index_entries_per_chunk", | ||
|
@@ -44,6 +40,13 @@ var ( | |
}) | ||
) | ||
|
||
// Query errors are to be treated as user errors, rather than storage errors. | ||
type QueryError string | ||
|
||
func (e QueryError) Error() string { | ||
return string(e) | ||
} | ||
|
||
// StoreConfig specifies config for a ChunkStore | ||
type StoreConfig struct { | ||
ChunkCacheConfig cache.Config `yaml:"chunk_cache_config"` | ||
|
@@ -286,12 +289,12 @@ func (c *baseStore) validateQueryTimeRange(ctx context.Context, userID string, f | |
defer log.Span.Finish() | ||
|
||
if *through < *from { | ||
return false, httpgrpc.Errorf(http.StatusBadRequest, "invalid query, through < from (%s < %s)", through, from) | ||
return false, QueryError(fmt.Sprintf("invalid query, through < from (%s < %s)", through, from)) | ||
|
||
} | ||
|
||
maxQueryLength := c.limits.MaxQueryLength(userID) | ||
if maxQueryLength > 0 && (*through).Sub(*from) > maxQueryLength { | ||
return false, httpgrpc.Errorf(http.StatusBadRequest, validation.ErrQueryTooLong, (*through).Sub(*from), maxQueryLength) | ||
return false, QueryError(fmt.Sprintf(validation.ErrQueryTooLong, (*through).Sub(*from), maxQueryLength)) | ||
} | ||
|
||
now := model.Now() | ||
|
@@ -333,7 +336,7 @@ func (c *baseStore) validateQuery(ctx context.Context, userID string, from *mode | |
// Check there is a metric name matcher of type equal, | ||
metricNameMatcher, matchers, ok := extract.MetricNameMatcherFromMatchers(matchers) | ||
if !ok || metricNameMatcher.Type != labels.MatchEqual { | ||
return "", nil, false, httpgrpc.Errorf(http.StatusBadRequest, "query must contain metric name") | ||
return "", nil, false, ErrQueryMustContainMetricName | ||
} | ||
|
||
return metricNameMatcher.Value, matchers, false, nil | ||
|
@@ -357,7 +360,7 @@ func (c *store) getMetricNameChunks(ctx context.Context, userID string, from, th | |
|
||
maxChunksPerQuery := c.limits.MaxChunksPerQuery(userID) | ||
if maxChunksPerQuery > 0 && len(filtered) > maxChunksPerQuery { | ||
err := httpgrpc.Errorf(http.StatusBadRequest, "Query %v fetched too many chunks (%d > %d)", allMatchers, len(filtered), maxChunksPerQuery) | ||
err := QueryError(fmt.Sprintf("Query %v fetched too many chunks (%d > %d)", allMatchers, len(filtered), maxChunksPerQuery)) | ||
level.Error(log).Log("err", err) | ||
return nil, err | ||
} | ||
|
@@ -366,7 +369,7 @@ func (c *store) getMetricNameChunks(ctx context.Context, userID string, from, th | |
keys := keysFromChunks(filtered) | ||
allChunks, err := c.FetchChunks(ctx, filtered, keys) | ||
if err != nil { | ||
return nil, promql.ErrStorage{Err: err} | ||
return nil, err | ||
} | ||
|
||
// Filter out chunks based on the empty matchers in the query. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[thinking loudly] I'm a bit dubious about adding this further test here. The query-frontend integration test is become the place where everyone adds further cases and we risk to make it just more and more complicated. This case is already covered by the assertion you added to
TestQuerierWithChunksStorage
, so do we really need this too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally I suspected that status code is mangled by query-frontend and wanted to make sure that it is propagated properly. Repeating some of the tests between querier and query-frontend makes sense imho, and we should perhaps refactor the code to avoid duplicated code, but repeat those tests.