From 724ee47c8b21d17efa9f91740c04bb23a2788d8d Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Thu, 20 May 2021 18:12:30 -0400 Subject: [PATCH] add metric calls for other packages --- peer/http3/worker.go | 2 ++ peer/server.go | 2 ++ store/caching.go | 2 ++ store/speedwalk/speedwalk.go | 3 +++ 4 files changed, 9 insertions(+) diff --git a/peer/http3/worker.go b/peer/http3/worker.go index d2b625b..91dfd02 100644 --- a/peer/http3/worker.go +++ b/peer/http3/worker.go @@ -20,7 +20,9 @@ var getReqCh = make(chan *blobRequest, 20000) func InitWorkers(server *Server, workers int) { stopper := stop.New(server.grp) for i := 0; i < workers; i++ { + metrics.RoutinesQueue.WithLabelValues("http3", "worker").Inc() go func(worker int) { + defer metrics.RoutinesQueue.WithLabelValues("http3", "worker").Dec() for { select { case <-stopper.Ch(): diff --git a/peer/server.go b/peer/server.go index 708fe53..4061ea5 100644 --- a/peer/server.go +++ b/peer/server.go @@ -89,7 +89,9 @@ func (s *Server) listenAndServe(listener net.Listener) { log.Error(errors.Prefix("accepting conn", err)) } else { s.grp.Add(1) + metrics.RoutinesQueue.WithLabelValues("peer", "server-handleconn").Inc() go func() { + defer metrics.RoutinesQueue.WithLabelValues("peer", "server-handleconn").Dec() s.handleConnection(conn) s.grp.Done() }() diff --git a/store/caching.go b/store/caching.go index 6f1d4d4..cd05b41 100644 --- a/store/caching.go +++ b/store/caching.go @@ -66,7 +66,9 @@ func (c *CachingStore) Get(hash string) (stream.Blob, shared.BlobTrace, error) { } // there is no need to wait for the blob to be stored before we return it // TODO: however this should be refactored to limit the amount of routines that the process can spawn to avoid a possible DoS + metrics.RoutinesQueue.WithLabelValues("store", "cache-put").Inc() go func() { + defer metrics.RoutinesQueue.WithLabelValues("store", "cache-put").Dec() err = c.cache.Put(hash, blob) if err != nil { log.Errorf("error saving blob to underlying cache: %s", errors.FullTrace(err)) diff --git a/store/speedwalk/speedwalk.go b/store/speedwalk/speedwalk.go index 9b899e4..1d4b981 100644 --- a/store/speedwalk/speedwalk.go +++ b/store/speedwalk/speedwalk.go @@ -6,6 +6,8 @@ import ( "runtime" "sync" + "github.com/lbryio/reflector.go/internal/metrics" + "github.com/lbryio/lbry.go/v2/extras/errors" "github.com/karrick/godirwalk" @@ -24,6 +26,7 @@ func AllFiles(startDir string, basename bool) ([]string, error) { paths := make([]string, 0, 1000) pathWG := &sync.WaitGroup{} pathWG.Add(1) + metrics.RoutinesQueue.WithLabelValues("speedwalk", "worker").Inc() go func() { defer pathWG.Done() for {