From 7cb51905074143259de6916be4bf3b54af47bdcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Ortu=C3=B1o?= Date: Wed, 14 Dec 2022 15:02:19 +0100 Subject: [PATCH] remove github.com/prometheus/prometheus dependency (#242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miguel Ángel Ortuño After merging #239 we introduced a github.com/prometheus/prometheus dependency. @ go.mod - https://github.com/grafana/dskit/blob/main/go.mod#L28 Apart from being an old version, this is also causing some issues when validating CI in enterprise repositories. The purpose of this is to get rid of it. --- gate/gate.go | 35 +++++++++++++++++++++++++++++++++-- go.mod | 3 ++- go.sum | 4 ++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/gate/gate.go b/gate/gate.go index db799945f..486eae794 100644 --- a/gate/gate.go +++ b/gate/gate.go @@ -8,7 +8,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - promgate "github.com/prometheus/prometheus/util/gate" ) var ErrMaxConcurrent = errors.New("max concurrent requests inflight") @@ -49,7 +48,7 @@ func (noopGate) Done() {} // It can be called several times but not with the same registerer otherwise it // will panic when trying to register the same metric multiple times. func New(reg prometheus.Registerer, maxConcurrent int) Gate { - return NewInstrumented(reg, maxConcurrent, promgate.New(maxConcurrent)) + return NewInstrumented(reg, maxConcurrent, newGate(maxConcurrent)) } // NewInstrumented wraps a Gate implementation with one that records max number of inflight @@ -159,3 +158,35 @@ func (g *blockingGate) Done() { panic("gate.Done: more operations done than started") } } + +// A gate controls the maximum number of concurrently running and waiting queries. +type gate struct { + ch chan struct{} +} + +// newGate returns a query gate that limits the number of queries +// being concurrently executed. +func newGate(length int) *gate { + return &gate{ + ch: make(chan struct{}, length), + } +} + +// Start blocks until the gate has a free spot or the context is done. +func (g *gate) Start(ctx context.Context) error { + select { + case <-ctx.Done(): + return ctx.Err() + case g.ch <- struct{}{}: + return nil + } +} + +// Done releases a single spot in the gate. +func (g *gate) Done() { + select { + case <-g.ch: + default: + panic("gate.Done: more operations done than started") + } +} diff --git a/go.mod b/go.mod index 65402108e..701cd934b 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,6 @@ require ( github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.13.1 github.com/prometheus/common v0.37.0 - github.com/prometheus/prometheus v0.40.5 github.com/stretchr/testify v1.8.1 github.com/weaveworks/common v0.0.0-20221201103051-7c2720a9024d go.etcd.io/etcd/api/v3 v3.5.0 @@ -52,6 +51,7 @@ require ( github.com/gogo/googleapis v1.1.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/btree v1.0.0 // indirect + github.com/google/go-cmp v0.5.9 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-hclog v0.14.1 // indirect @@ -91,6 +91,7 @@ require ( google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect google.golang.org/protobuf v1.28.1 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect ) replace k8s.io/client-go v12.0.0+incompatible => k8s.io/client-go v0.21.4 diff --git a/go.sum b/go.sum index 33884fcf2..e43d0f903 100644 --- a/go.sum +++ b/go.sum @@ -217,6 +217,7 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -418,8 +419,6 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= -github.com/prometheus/prometheus v0.40.5 h1:wmk5yNrQlkQ2OvZucMhUB4k78AVfG34szb1UtopS8Vc= -github.com/prometheus/prometheus v0.40.5/go.mod h1:bxgdmtoSNLmmIVPGmeTJ3OiP67VmuY4yalE4ZP6L/j8= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -980,6 +979,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=