Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from randlabs/updated_deps
Browse files Browse the repository at this point in the history
Updated dependencies and minor improvements
  • Loading branch information
mxmauro authored Aug 2, 2023
2 parents d020db6 + de0f7f1 commit e2f8918
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ module github.com/randlabs/go-metrics
go 1.19

require (
github.com/prometheus/client_golang v1.15.1
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/client_model v0.4.0
github.com/randlabs/go-webserver v1.2.2
github.com/randlabs/go-webserver v1.3.0
github.com/randlabs/rundown-protection v1.0.5
google.golang.org/protobuf v1.30.0
google.golang.org/protobuf v1.31.0
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/fasthttp/router v1.4.19 // indirect
github.com/fasthttp/router v1.4.20 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.47.0 // indirect
github.com/valyala/fasthttp v1.48.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/sys v0.10.0 // indirect
)
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/fasthttp/router v1.4.19 h1:RLE539IU/S4kfb4MP56zgP0TIBU9kEg0ID9GpWO0vqk=
github.com/fasthttp/router v1.4.19/go.mod h1:+Fh3YOd8x1+he6ZS+d2iUDBH9MGGZ1xQFUor0DE9rKE=
github.com/fasthttp/router v1.4.20 h1:yPeNxz5WxZGojzolKqiP15DTXnxZce9Drv577GBrDgU=
github.com/fasthttp/router v1.4.20/go.mod h1:um867yNQKtERxBm+C+yzgWxjspTiQoA8z86Ec3fK/tc=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI=
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8=
github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc=
github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM=
github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc=
github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
github.com/randlabs/go-webserver v1.2.2 h1:Ma/jgCVuCfFQR31tJ+3CTdIkO4tBn/28mQL/yowwi1c=
github.com/randlabs/go-webserver v1.2.2/go.mod h1:y6pQkb39r0AIFeVaAF6bMlvPZsCKhdFt6iU9yhAoM2E=
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/randlabs/go-webserver v1.3.0 h1:wcE4q+YQ+gnq02dtRzub54fTdFIxbytSwvc/KeQFoxA=
github.com/randlabs/go-webserver v1.3.0/go.mod h1:sd4pL0J4nZ9eTKsrvD3pC0R6/Cm5P8cVjcJH1yYFrM0=
github.com/randlabs/rundown-protection v1.0.5 h1:Bq9GMTuWvZI3915VkVLVysayQfSfHmWwuhD6feawhfU=
github.com/randlabs/rundown-protection v1.0.5/go.mod h1:rccYmsidTaGDOvZSAF9eYsLzMVvh9tj043JyTicfQ5o=
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.47.0 h1:y7moDoxYzMooFpT5aHgNgVOQDrS3qlkfiP9mDtGGK9c=
github.com/valyala/fasthttp v1.47.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
github.com/valyala/fasthttp v1.48.0 h1:oJWvHb9BIZToTQS3MuQ2R3bJZiNSa2KiNdeI8A+79Tc=
github.com/valyala/fasthttp v1.48.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
5 changes: 4 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const (
strContentTypeApplicationJSON = "application/json"
)

// -----------------------------------------------------------------------------

func (mws *Controller) getHealthHandler() webserver.HandlerFunc {
return func(req *request.RequestContext) error {
// Get current health status from callback
Expand Down Expand Up @@ -44,7 +46,8 @@ func (mws *Controller) getMetricsHandler() webserver.HandlerFunc {
return webserver.HandlerFromHttpHandler(promhttp.HandlerFor(
mws.registry,
promhttp.HandlerOpts{
EnableOpenMetrics: true,
EnableOpenMetrics: true,
MaxRequestsInFlight: 5,
},
))
}
Expand Down
12 changes: 6 additions & 6 deletions middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
func (mws *Controller) createAliveMiddleware() webserver.MiddlewareFunc {
return func(next webserver.HandlerFunc) webserver.HandlerFunc {
return func(req *request.RequestContext) error {
if mws.rundownProt.Acquire() {
err := next(req)
mws.rundownProt.Release()
return err
} else {
req.Error("", http.StatusServiceUnavailable)
// Process the request if we are not shutting down
if !mws.rundownProt.Acquire() {
req.Error(http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)
return nil
}
defer mws.rundownProt.Release()

return next(req)
}
}
}
4 changes: 4 additions & 0 deletions prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type VectorMetric []struct {

// -----------------------------------------------------------------------------

// CreateCounterWithCallback creates a single counter metric where its data is populated by calling a callback
func (mws *Controller) CreateCounterWithCallback(name string, help string, handler ValueHandler) error {
coll := prometheus.NewCounterFunc(
prometheus.CounterOpts{
Expand All @@ -30,6 +31,7 @@ func (mws *Controller) CreateCounterWithCallback(name string, help string, handl
return mws.registry.Register(coll)
}

// CreateCounterVecWithCallback creates a vector of counters metric where their data are populated by calling a callback
func (mws *Controller) CreateCounterVecWithCallback(
name string, help string, variableLabels []string, subItems VectorMetric,
) error {
Expand Down Expand Up @@ -66,6 +68,7 @@ func (mws *Controller) CreateCounterVecWithCallback(
return mws.registry.Register(coll)
}

// CreateGaugeWithCallback creates a single gauge metric where its data is populated by calling a callback
func (mws *Controller) CreateGaugeWithCallback(name string, help string, handler ValueHandler) error {
coll := prometheus.NewGaugeFunc(
prometheus.GaugeOpts{
Expand All @@ -77,6 +80,7 @@ func (mws *Controller) CreateGaugeWithCallback(name string, help string, handler
return mws.registry.Register(coll)
}

// CreateGaugeVecWithCallback creates a vector of gauges metric where their data are populated by calling a callback
func (mws *Controller) CreateGaugeVecWithCallback(
name string, help string, variableLabels []string, subItems VectorMetric,
) error {
Expand Down

0 comments on commit e2f8918

Please sign in to comment.