mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Replace deprecated prometheus.InstrumentHandler and unsafe time.Ticker
This commit is contained in:
parent
e959927d0a
commit
8fb2c9c33c
5 changed files with 124 additions and 34 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
|
@ -59,7 +60,16 @@ func MakeHTMLAPI(metricsName string, f func(http.ResponseWriter, *http.Request)
|
|||
}
|
||||
}
|
||||
|
||||
return prometheus.InstrumentHandler(metricsName, http.HandlerFunc(withSpan))
|
||||
return promhttp.InstrumentHandlerCounter(
|
||||
promauto.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: metricsName,
|
||||
Help: "Total number of http requests for HTML resources",
|
||||
},
|
||||
[]string{"code"},
|
||||
),
|
||||
http.HandlerFunc(withSpan),
|
||||
)
|
||||
}
|
||||
|
||||
// MakeInternalAPI turns a util.JSONRequestHandler function into an http.Handler.
|
||||
|
|
|
@ -85,7 +85,7 @@ func (t *Cache) AddTransaction(accessToken, txnID string, res *util.JSONResponse
|
|||
// It guarantees that an entry will be present in cache for at least cleanupPeriod & at most 2 * cleanupPeriod.
|
||||
// This cycles the txnMaps forward, i.e. back map is assigned the front and front is assigned an empty map.
|
||||
func cacheCleanService(t *Cache) {
|
||||
ticker := time.Tick(t.cleanupPeriod)
|
||||
ticker := time.NewTicker(t.cleanupPeriod).C
|
||||
for range ticker {
|
||||
t.Lock()
|
||||
t.txnsMaps[1] = t.txnsMaps[0]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue