Skip to content
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

[pull] master from cortexproject:master #582

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* [ENHANCEMENT] All: Handling CMK Access Denied errors. #5420 #5542
* [ENHANCEMENT] Querier: Retry store gateway client connection closing gRPC error. #5558
* [ENHANCEMENT] QueryFrontend: Add generic retry for all APIs. #5561.
* [ENHANCEMENT] QueryFrontend: Add metric for number of series requests. #5373
* [BUGFIX] Ruler: Validate if rule group can be safely converted back to rule group yaml from protobuf message #5265
* [BUGFIX] Querier: Convert gRPC `ResourceExhausted` status code from store gateway to 422 limit error. #5286
* [BUGFIX] Alertmanager: Route web-ui requests to the alertmanager distributor when sharding is enabled. #5293
Expand Down
6 changes: 1 addition & 5 deletions pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"google.golang.org/grpc/codes"

"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -284,10 +283,7 @@ func TestDistributor_Push(t *testing.T) {
request := makeWriteRequest(tc.samples.startTimestampMs, tc.samples.num, tc.metadata)
response, err := ds[0].Push(ctx, request)
assert.Equal(t, tc.expectedResponse, response)
if err != nil {
err = errors.Cause(err)
}
assert.Equal(t, tc.expectedError, err)
assert.Equal(t, status.Code(tc.expectedError), status.Code(err))

// Check tracked Prometheus metrics. Since the Push() response is sent as soon as the quorum
// is reached, when we reach this point the 3rd ingester may not have received series/metadata
Expand Down
3 changes: 3 additions & 0 deletions pkg/querier/tripperware/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ func NewQueryTripperware(
return RoundTripFunc(func(r *http.Request) (*http.Response, error) {
isQuery := strings.HasSuffix(r.URL.Path, "/query")
isQueryRange := strings.HasSuffix(r.URL.Path, "/query_range")
isSeries := strings.HasSuffix(r.URL.Path, "/series")

op := "query"
if isQueryRange {
op = "query_range"
} else if isSeries {
op = "series"
}

tenantIDs, err := tenant.TenantIDs(r.Context())
Expand Down
12 changes: 6 additions & 6 deletions pkg/ring/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"sync"

"go.uber.org/atomic"
"google.golang.org/grpc/status"

"github.com/pkg/errors"
"go.uber.org/atomic"
"github.com/cortexproject/cortex/pkg/util/httpgrpcutil"
)

type batchTracker struct {
Expand Down Expand Up @@ -152,7 +152,7 @@ func (b *batchTracker) record(instance instance, err error) {
if err != nil {
// Track the number of errors by error family, and if it exceeds maxFailures
// shortcut the waiting rpc.
wrappedErr := errors.Wrapf(err, "addr=%s state=%s zone=%s", instance.desc.Addr, instance.desc.State, instance.desc.Zone)
wrappedErr := httpgrpcutil.WrapHTTPGrpcError(err, "addr=%s state=%s zone=%s", instance.desc.Addr, instance.desc.State, instance.desc.Zone)
errCount := instance.itemTrackers[i].recordError(wrappedErr)
// We should return an error if we reach the maxFailure (quorum) on a given error family OR
// we dont have any remaining ingesters to try
Expand All @@ -162,13 +162,13 @@ func (b *batchTracker) record(instance instance, err error) {
// Ex: 5xx, _, 5xx -> return 5xx
if errCount > int32(sampleTrackers[i].maxFailures) {
if b.rpcsFailed.Inc() == 1 {
b.err <- errors.Wrap(sampleTrackers[i].getError(), "maxFailure (quorum) on a given error family")
b.err <- httpgrpcutil.WrapHTTPGrpcError(sampleTrackers[i].getError(), "maxFailure (quorum) on a given error family")
}
continue
}
if sampleTrackers[i].remaining.Dec() == 0 {
if b.rpcsFailed.Inc() == 1 {
b.err <- errors.Wrap(sampleTrackers[i].getError(), "not enough remaining instances to try")
b.err <- httpgrpcutil.WrapHTTPGrpcError(sampleTrackers[i].getError(), "not enough remaining instances to try")
}
continue
}
Expand All @@ -187,7 +187,7 @@ func (b *batchTracker) record(instance instance, err error) {
// Ex: 4xx, 5xx, 2xx
if sampleTrackers[i].remaining.Dec() == 0 {
if b.rpcsFailed.Inc() == 1 {
b.err <- errors.Wrap(sampleTrackers[i].getError(), "not enough remaining instances to try")
b.err <- httpgrpcutil.WrapHTTPGrpcError(sampleTrackers[i].getError(), "not enough remaining instances to try")
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/util/httpgrpcutil/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package httpgrpcutil

import (
"fmt"
"net/http"

"github.com/weaveworks/common/httpgrpc"
)

func WrapHTTPGrpcError(err error, format string, args ...interface{}) error {
if err == nil {
return nil
}
msg := fmt.Sprintf(format, args...)
resp, ok := httpgrpc.HTTPResponseFromError(err)
if !ok {
return httpgrpc.Errorf(http.StatusInternalServerError, "%s, %s", msg, err)
}
return httpgrpc.ErrorFromHTTPResponse(&httpgrpc.HTTPResponse{
Code: resp.Code,
Headers: resp.Headers,
Body: []byte(fmt.Sprintf("%s, %s", msg, err)),
})
}
Loading