diff --git a/go.mod b/go.mod index e5024496d1e..0ff485f07e3 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/spf13/afero v1.9.5 github.com/stretchr/testify v1.8.4 github.com/uber/jaeger-client-go v2.30.0+incompatible - github.com/weaveworks/common v0.0.0-20230714173453-d1f8877b91ce + github.com/weaveworks/common v0.0.0-20230728070032-dd9e68f319d5 go.uber.org/atomic v1.11.0 go.uber.org/goleak v1.2.1 golang.org/x/crypto v0.11.0 @@ -274,6 +274,3 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator // Replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus with a fork until https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/24288 is merged. replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus => github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.0.0-20230718193318-2bc9904b7ae8 - -// Use a fork of weaveworks/common while we work out if there is a better design for https://github.com/weaveworks/common/pull/293 -replace github.com/weaveworks/common => github.com/weaveworks/common v0.0.0-20230714173453-d1f8877b91ce diff --git a/go.sum b/go.sum index 35c7ff66d16..096e1889ccb 100644 --- a/go.sum +++ b/go.sum @@ -1264,8 +1264,8 @@ github.com/uber/jaeger-lib v2.2.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6 github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg= github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= github.com/vultr/govultr/v2 v2.17.2 h1:gej/rwr91Puc/tgh+j33p/BLR16UrIPnSr+AIwYWZQs= -github.com/weaveworks/common v0.0.0-20230714173453-d1f8877b91ce h1:8Gh0psRT42deLI53RVwLq2idJtRtDbdjhdX5LqnVznU= -github.com/weaveworks/common v0.0.0-20230714173453-d1f8877b91ce/go.mod h1:rgbeLfJUtEr+G74cwFPR1k/4N0kDeaeSv/qhUNE4hm8= +github.com/weaveworks/common v0.0.0-20230728070032-dd9e68f319d5 h1:nORobjToZAvi54wcuUXLq+XG2Rsr0XEizy5aHBHvqWQ= +github.com/weaveworks/common v0.0.0-20230728070032-dd9e68f319d5/go.mod h1:rgbeLfJUtEr+G74cwFPR1k/4N0kDeaeSv/qhUNE4hm8= github.com/weaveworks/promrus v1.2.0 h1:jOLf6pe6/vss4qGHjXmGz4oDJQA+AOCqEL3FvvZGz7M= github.com/weaveworks/promrus v1.2.0/go.mod h1:SaE82+OJ91yqjrE1rsvBWVzNZKcHYFtMUyS1+Ogs/KA= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index ece61ec7b8c..d0fba35efeb 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -33,7 +33,6 @@ import ( "github.com/prometheus/prometheus/scrape" "github.com/weaveworks/common/httpgrpc" "github.com/weaveworks/common/instrument" - "github.com/weaveworks/common/middleware" "github.com/weaveworks/common/mtime" "github.com/weaveworks/common/user" "go.uber.org/atomic" @@ -45,6 +44,7 @@ import ( "github.com/grafana/mimir/pkg/mimirpb" "github.com/grafana/mimir/pkg/util" "github.com/grafana/mimir/pkg/util/globalerror" + util_log "github.com/grafana/mimir/pkg/util/log" util_math "github.com/grafana/mimir/pkg/util/math" "github.com/grafana/mimir/pkg/util/pool" "github.com/grafana/mimir/pkg/util/push" @@ -1021,7 +1021,7 @@ func (d *Distributor) limitsMiddleware(next push.Func) push.Func { il := d.getInstanceLimits() if il.MaxInflightPushRequests > 0 && inflight > int64(il.MaxInflightPushRequests) { d.rejectedRequests.WithLabelValues(reasonDistributorMaxInflightPushRequests).Inc() - return nil, middleware.DoNotLogError{Err: errMaxInflightRequestsReached} + return nil, util_log.DoNotLogError{Err: errMaxInflightRequestsReached} } if il.MaxIngestionRate > 0 { diff --git a/pkg/ingester/ingester.go b/pkg/ingester/ingester.go index f386eb9b50c..7ba8277f532 100644 --- a/pkg/ingester/ingester.go +++ b/pkg/ingester/ingester.go @@ -47,7 +47,6 @@ import ( "github.com/prometheus/prometheus/util/zeropool" "github.com/thanos-io/objstore" "github.com/weaveworks/common/httpgrpc" - "github.com/weaveworks/common/middleware" "go.uber.org/atomic" "golang.org/x/exp/slices" "golang.org/x/sync/errgroup" @@ -715,7 +714,7 @@ func (i *Ingester) PushWithCleanup(ctx context.Context, pushReq *push.Request) ( defer pushReq.CleanUp() if err := i.checkRunning(); err != nil { - return nil, middleware.DoNotLogError{Err: err} + return nil, util_log.DoNotLogError{Err: err} } // We will report *this* request in the error too. diff --git a/pkg/ingester/instance_limits.go b/pkg/ingester/instance_limits.go index 4ee1c42d601..6716a1f7bfc 100644 --- a/pkg/ingester/instance_limits.go +++ b/pkg/ingester/instance_limits.go @@ -9,10 +9,10 @@ import ( "flag" "github.com/pkg/errors" - "github.com/weaveworks/common/middleware" "gopkg.in/yaml.v3" "github.com/grafana/mimir/pkg/util/globalerror" + util_log "github.com/grafana/mimir/pkg/util/log" ) const ( @@ -27,7 +27,7 @@ var ( errMaxIngestionRateReached = errors.New(globalerror.IngesterMaxIngestionRate.MessageWithPerInstanceLimitConfig("the write request has been rejected because the ingester exceeded the samples ingestion rate limit", maxIngestionRateFlag)) errMaxTenantsReached = errors.New(globalerror.IngesterMaxTenants.MessageWithPerInstanceLimitConfig("the write request has been rejected because the ingester exceeded the allowed number of tenants", maxInMemoryTenantsFlag)) errMaxInMemorySeriesReached = errors.New(globalerror.IngesterMaxInMemorySeries.MessageWithPerInstanceLimitConfig("the write request has been rejected because the ingester exceeded the allowed number of in-memory series", maxInMemorySeriesFlag)) - errMaxInflightRequestsReached = middleware.DoNotLogError{Err: errors.New(globalerror.IngesterMaxInflightPushRequests.MessageWithPerInstanceLimitConfig("the write request has been rejected because the ingester exceeded the allowed number of inflight push requests", maxInflightPushRequestsFlag))} + errMaxInflightRequestsReached = util_log.DoNotLogError{Err: errors.New(globalerror.IngesterMaxInflightPushRequests.MessageWithPerInstanceLimitConfig("the write request has been rejected because the ingester exceeded the allowed number of inflight push requests", maxInflightPushRequestsFlag))} ) // InstanceLimits describes limits used by ingester. Reaching any of these will result in Push method to return diff --git a/pkg/util/log/log.go b/pkg/util/log/log.go index aab9a6f0520..d2910850d7a 100644 --- a/pkg/util/log/log.go +++ b/pkg/util/log/log.go @@ -6,6 +6,7 @@ package log import ( + "context" "fmt" "io" "os" @@ -105,3 +106,9 @@ func Flush() error { return nil } + +type DoNotLogError struct{ Err error } + +func (i DoNotLogError) Error() string { return i.Err.Error() } +func (i DoNotLogError) Unwrap() error { return i.Err } +func (i DoNotLogError) ShouldLog(_ context.Context, _ time.Duration) bool { return false } diff --git a/vendor/github.com/weaveworks/common/middleware/grpc_logging.go b/vendor/github.com/weaveworks/common/middleware/grpc_logging.go index e5b0e670f69..66aa8e22167 100644 --- a/vendor/github.com/weaveworks/common/middleware/grpc_logging.go +++ b/vendor/github.com/weaveworks/common/middleware/grpc_logging.go @@ -17,6 +17,11 @@ const ( errorKey = "err" ) +// An error can implement ShouldLog() to control whether GRPCServerLog will log. +type OptionalLogging interface { + ShouldLog(ctx context.Context, duration time.Duration) bool +} + // GRPCServerLog logs grpc requests, errors, and latency. type GRPCServerLog struct { Log logging.Interface @@ -32,7 +37,8 @@ func (s GRPCServerLog) UnaryServerInterceptor(ctx context.Context, req interface if err == nil && s.DisableRequestSuccessLog { return resp, nil } - if errors.Is(err, DoNotLogError{}) { + var optional OptionalLogging + if errors.As(err, &optional) && !optional.ShouldLog(ctx, time.Since(begin)) { return resp, err } diff --git a/vendor/github.com/weaveworks/common/middleware/logging.go b/vendor/github.com/weaveworks/common/middleware/logging.go index c3c00b99377..fcb8453ffb7 100644 --- a/vendor/github.com/weaveworks/common/middleware/logging.go +++ b/vendor/github.com/weaveworks/common/middleware/logging.go @@ -46,14 +46,6 @@ func NewLogMiddleware(log logging.Interface, logRequestHeaders bool, logRequestA } } -// This can be used with `errors.Is` to see if the error marked itself as not to be logged. -// E.g. if the error is caused by overload, then we don't want to log it because that uses more resource. -type DoNotLogError struct{ Err error } - -func (i DoNotLogError) Error() string { return i.Err.Error() } -func (i DoNotLogError) Unwrap() error { return i.Err } -func (i DoNotLogError) Is(target error) bool { _, ok := target.(DoNotLogError); return ok } - // logWithRequest information from the request and context as fields. func (l Log) logWithRequest(r *http.Request) logging.Interface { localLog := l.Log @@ -91,9 +83,6 @@ func (l Log) Wrap(next http.Handler) http.Handler { statusCode, writeErr := wrapped.getStatusCode(), wrapped.getWriteError() if writeErr != nil { - if errors.Is(writeErr, DoNotLogError{}) { - return - } if errors.Is(writeErr, context.Canceled) { if l.LogRequestAtInfoLevel { requestLog.Infof("%s %s %s, request cancelled: %s ws: %v; %s", r.Method, uri, time.Since(begin), writeErr, IsWSHandshakeRequest(r), headers) diff --git a/vendor/modules.txt b/vendor/modules.txt index 49c2b366276..fc4e465d2a3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1025,7 +1025,7 @@ github.com/uber/jaeger-client-go/utils ## explicit github.com/uber/jaeger-lib/metrics github.com/uber/jaeger-lib/metrics/prometheus -# github.com/weaveworks/common v0.0.0-20230714173453-d1f8877b91ce => github.com/weaveworks/common v0.0.0-20230714173453-d1f8877b91ce +# github.com/weaveworks/common v0.0.0-20230728070032-dd9e68f319d5 ## explicit; go 1.14 github.com/weaveworks/common/errors github.com/weaveworks/common/grpc @@ -1488,4 +1488,3 @@ sigs.k8s.io/yaml # github.com/opentracing-contrib/go-stdlib => github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956 # github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheusremotewrite => github.com/charleskorn/opentelemetry-collector-contrib/pkg/translator/prometheusremotewrite v0.0.0-20230719070131-77d6f20f8ca9 # github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus => github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus v0.0.0-20230718193318-2bc9904b7ae8 -# github.com/weaveworks/common => github.com/weaveworks/common v0.0.0-20230714173453-d1f8877b91ce