Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2019-10-21 23:45:45 +0300
committerPaul Okstad <pokstad@gitlab.com>2019-10-21 23:45:45 +0300
commitcf7c6ca4f45aa0eea5780f34e739dc221f66fb11 (patch)
treeaabc7d0db2ef98b3daa9935215c778ab42a191c2 /streamio
parentfe09d608d335767411fd908b852819d7ee5effed (diff)
Count streamio method calls
Diffstat (limited to 'streamio')
-rw-r--r--streamio/stream.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/streamio/stream.go b/streamio/stream.go
index 379556afe..3e90f0e42 100644
--- a/streamio/stream.go
+++ b/streamio/stream.go
@@ -8,9 +8,22 @@ import (
"io"
"os"
"strconv"
+
+ "github.com/prometheus/client_golang/prometheus"
+)
+
+var (
+ methodCount = prometheus.NewCounterVec(
+ prometheus.CounterOpts{
+ Name: "gitaly_streamio_method_calls_total",
+ Help: "Usage counters of gitaly streamio methods",
+ }, []string{"method"},
+ )
)
func init() {
+ prometheus.MustRegister(methodCount)
+
bufSize64, err := strconv.ParseInt(os.Getenv("GITALY_STREAMIO_WRITE_BUFFER_SIZE"), 10, 32)
if err == nil && bufSize64 > 0 {
WriteBufferSize = int(bufSize64)
@@ -30,7 +43,11 @@ type receiveReader struct {
err error
}
+func countMethod(method string) { methodCount.WithLabelValues(method).Inc() }
+
func (rr *receiveReader) Read(p []byte) (int, error) {
+ countMethod("reader.Read")
+
if len(rr.data) == 0 {
rr.data, rr.err = rr.receiver()
}
@@ -44,6 +61,8 @@ func (rr *receiveReader) Read(p []byte) (int, error) {
// WriteTo implements io.WriterTo.
func (rr *receiveReader) WriteTo(w io.Writer) (int64, error) {
+ countMethod("reader.WriteTo")
+
var written int64
// Deal with left-over state in rr.data and rr.err, if any
@@ -93,6 +112,8 @@ type sendWriter struct {
}
func (sw *sendWriter) Write(p []byte) (int, error) {
+ countMethod("writer.Write")
+
var sent int
for len(p) > 0 {
@@ -114,6 +135,8 @@ func (sw *sendWriter) Write(p []byte) (int, error) {
// ReadFrom implements io.ReaderFrom.
func (sw *sendWriter) ReadFrom(r io.Reader) (int64, error) {
+ countMethod("writer.ReadFrom")
+
var nRead int64
buf := make([]byte, WriteBufferSize)