diff --git a/pkg/chunk/gcp/instrumentation.go b/pkg/chunk/gcp/instrumentation.go index ffde9ac00e8..44803e36bd5 100644 --- a/pkg/chunk/gcp/instrumentation.go +++ b/pkg/chunk/gcp/instrumentation.go @@ -6,7 +6,6 @@ import ( "strconv" "time" - "github.com/grafana/dskit/middleware" otgrpc "github.com/opentracing-contrib/go-grpc" opentracing "github.com/opentracing/opentracing-go" "github.com/prometheus/client_golang/prometheus" @@ -14,6 +13,8 @@ import ( "google.golang.org/api/option" google_http "google.golang.org/api/transport/http" "google.golang.org/grpc" + + "github.com/cortexproject/cortex/pkg/util/middleware" ) var ( diff --git a/pkg/querier/worker/scheduler_processor.go b/pkg/querier/worker/scheduler_processor.go index b835485a2f5..c810e6ce83f 100644 --- a/pkg/querier/worker/scheduler_processor.go +++ b/pkg/querier/worker/scheduler_processor.go @@ -9,7 +9,6 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/grafana/dskit/backoff" - dsmiddleware "github.com/grafana/dskit/middleware" "github.com/grafana/dskit/services" otgrpc "github.com/opentracing-contrib/go-grpc" "github.com/opentracing/opentracing-go" @@ -28,6 +27,7 @@ import ( "github.com/cortexproject/cortex/pkg/util/grpcclient" "github.com/cortexproject/cortex/pkg/util/httpgrpcutil" util_log "github.com/cortexproject/cortex/pkg/util/log" + cortexmiddleware "github.com/cortexproject/cortex/pkg/util/middleware" ) func newSchedulerProcessor(cfg Config, handler RequestHandler, log log.Logger, reg prometheus.Registerer) (*schedulerProcessor, []services.Service) { @@ -198,7 +198,7 @@ func (sp *schedulerProcessor) createFrontendClient(addr string) (client.PoolClie opts, err := sp.grpcConfig.DialOption([]grpc.UnaryClientInterceptor{ otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer()), middleware.ClientUserHeaderInterceptor, - dsmiddleware.PrometheusGRPCUnaryInstrumentation(sp.frontendClientRequestDuration), + cortexmiddleware.PrometheusGRPCUnaryInstrumentation(sp.frontendClientRequestDuration), }, nil) if err != nil { diff --git a/pkg/util/grpcclient/instrumentation.go b/pkg/util/grpcclient/instrumentation.go index cf3dd392d6a..dfe29164e68 100644 --- a/pkg/util/grpcclient/instrumentation.go +++ b/pkg/util/grpcclient/instrumentation.go @@ -1,22 +1,23 @@ package grpcclient import ( - dsmiddleware "github.com/grafana/dskit/middleware" otgrpc "github.com/opentracing-contrib/go-grpc" "github.com/opentracing/opentracing-go" "github.com/prometheus/client_golang/prometheus" "github.com/weaveworks/common/middleware" "google.golang.org/grpc" + + cortexmiddleware "github.com/cortexproject/cortex/pkg/util/middleware" ) func Instrument(requestDuration *prometheus.HistogramVec) ([]grpc.UnaryClientInterceptor, []grpc.StreamClientInterceptor) { return []grpc.UnaryClientInterceptor{ otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer()), middleware.ClientUserHeaderInterceptor, - dsmiddleware.PrometheusGRPCUnaryInstrumentation(requestDuration), + cortexmiddleware.PrometheusGRPCUnaryInstrumentation(requestDuration), }, []grpc.StreamClientInterceptor{ otgrpc.OpenTracingStreamClientInterceptor(opentracing.GlobalTracer()), middleware.StreamClientUserHeaderInterceptor, - dsmiddleware.PrometheusGRPCStreamInstrumentation(requestDuration), + cortexmiddleware.PrometheusGRPCStreamInstrumentation(requestDuration), } } diff --git a/vendor/github.com/grafana/dskit/middleware/grpc.go b/pkg/util/middleware/grpc.go similarity index 100% rename from vendor/github.com/grafana/dskit/middleware/grpc.go rename to pkg/util/middleware/grpc.go diff --git a/pkg/util/middleware/grpc_test.go b/pkg/util/middleware/grpc_test.go new file mode 100644 index 00000000000..e855f03e781 --- /dev/null +++ b/pkg/util/middleware/grpc_test.go @@ -0,0 +1,40 @@ +package middleware + +import ( + "net/http" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/weaveworks/common/httpgrpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func TestErrorCode_NoError(t *testing.T) { + a := errorCode(nil) + assert.Equal(t, a, "2xx") +} + +func TestErrorCode_Any5xx(t *testing.T) { + err := httpgrpc.Errorf(http.StatusNotImplemented, "Fail") + a := errorCode(err) + assert.Equal(t, a, "5xx") +} + +func TestErrorCode_Any4xx(t *testing.T) { + err := httpgrpc.Errorf(http.StatusConflict, "Fail") + a := errorCode(err) + assert.Equal(t, a, "4xx") +} + +func TestErrorCode_Canceled(t *testing.T) { + err := status.Errorf(codes.Canceled, "Fail") + a := errorCode(err) + assert.Equal(t, a, "cancel") +} + +func TestErrorCode_Unknown(t *testing.T) { + err := status.Errorf(codes.Unknown, "Fail") + a := errorCode(err) + assert.Equal(t, a, "error") +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 0131cfaaecc..74ee103834b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -363,7 +363,6 @@ github.com/grafana/dskit/backoff github.com/grafana/dskit/concurrency github.com/grafana/dskit/flagext github.com/grafana/dskit/internal/math -github.com/grafana/dskit/middleware github.com/grafana/dskit/multierror github.com/grafana/dskit/runutil github.com/grafana/dskit/services