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

prometheus.go « cache « middleware « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0cc2bb314fa5259de811f2cb16fe75d698f7773 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cache

import (
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promauto"
	"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/protoregistry"
)

var (
	rpcTotal = promauto.NewCounter(
		prometheus.CounterOpts{
			Name: "gitaly_cacheinvalidator_rpc_total",
			Help: "Total number of RPCs encountered by cache invalidator",
		},
	)
	rpcOpTypes = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "gitaly_cacheinvalidator_optype_total",
			Help: "Total number of operation types encountered by cache invalidator",
		},
		[]string{"type"},
	)
	methodErrTotals = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "gitaly_cacheinvalidator_error_total",
			Help: "Total number of cache invalidation errors by method",
		},
		[]string{"method"},
	)
)

// counter functions are package vars to allow for overriding in tests
var (
	countMethodErr = func(method string) { methodErrTotals.WithLabelValues(method).Inc() }
	countRPCType   = func(mInfo protoregistry.MethodInfo) {
		rpcTotal.Inc()

		switch mInfo.Operation {
		case protoregistry.OpAccessor:
			rpcOpTypes.WithLabelValues("accessor").Inc()
		case protoregistry.OpMutator:
			rpcOpTypes.WithLabelValues("mutator").Inc()
		case protoregistry.OpMaintenance:
			rpcOpTypes.WithLabelValues("maintenance").Inc()
		default:
			rpcOpTypes.WithLabelValues("unknown").Inc()
		}
	}
)