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

server.go « hook « service « gitaly « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bc3b739d60ea1332c999e3fa26792956bb2bf830 (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
50
51
52
53
54
55
56
package hook

import (
	"strconv"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promauto"
	"gitlab.com/gitlab-org/gitaly/internal/git"
	"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
	gitalyhook "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
	"gitlab.com/gitlab-org/gitaly/internal/log"
	"gitlab.com/gitlab-org/gitaly/internal/streamcache"
	"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)

var (
	packObjectsCacheEnabled = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "gitaly_pack_objects_cache_enabled",
			Help: "If set to 1, indicates that the cache for PackObjectsHook has been enabled in this process",
		},
		[]string{"dir", "max_age"},
	)
)

type server struct {
	cfg              config.Cfg
	manager          gitalyhook.Manager
	gitCmdFactory    git.CommandFactory
	packObjectsCache streamcache.Cache
}

// NewServer creates a new instance of a gRPC namespace server
func NewServer(cfg config.Cfg, manager gitalyhook.Manager, gitCmdFactory git.CommandFactory) gitalypb.HookServiceServer {
	srv := &server{
		cfg:              cfg,
		manager:          manager,
		gitCmdFactory:    gitCmdFactory,
		packObjectsCache: streamcache.NullCache{},
	}

	if poc := cfg.PackObjectsCache; poc.Enabled {
		maxAge := poc.MaxAge.Duration()
		srv.packObjectsCache = streamcache.New(
			poc.Dir,
			maxAge,
			log.Default(),
		)
		packObjectsCacheEnabled.WithLabelValues(
			poc.Dir,
			strconv.Itoa(int(maxAge.Seconds())),
		).Set(1)
	}

	return srv
}