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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-06-09 15:34:10 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-06-14 08:52:28 +0300
commit64cda09950f43fdb7072f22755a8bb05c9d5f589 (patch)
tree0dc6168958d620d71bb9fb8d67473a1f98be8a9c
parent3c46992fd115a581a5bf25bf142652eb7c57f236 (diff)
blackbox: Implement logic on a Blackbox struct receiver
Right now, the implenetation of Blackbox logic always gets a configuration passed in as it is not associated to any structure. This shortcoming keeps us from having all logic like for example also the Prometheus counters as part of the struct, which means that they currently live as globals. Let's prepare to get rid of these globals by creating a new `Blackbox` structure and implement blackbox logic as receiver functions. For now, the struct only hosts the configuration.
-rw-r--r--cmd/gitaly-blackbox/main.go4
-rw-r--r--internal/blackbox/blackbox.go28
2 files changed, 23 insertions, 9 deletions
diff --git a/cmd/gitaly-blackbox/main.go b/cmd/gitaly-blackbox/main.go
index 3ef2d7352..0c96fa144 100644
--- a/cmd/gitaly-blackbox/main.go
+++ b/cmd/gitaly-blackbox/main.go
@@ -53,7 +53,9 @@ func run(configPath string) error {
return err
}
+ bb := blackbox.New(config)
+
log.Configure(log.Loggers, config.Logging.Format, config.Logging.Level)
- return blackbox.Run(config)
+ return bb.Run()
}
diff --git a/internal/blackbox/blackbox.go b/internal/blackbox/blackbox.go
index 5cbf5268d..34d2d45b4 100644
--- a/internal/blackbox/blackbox.go
+++ b/internal/blackbox/blackbox.go
@@ -12,23 +12,35 @@ import (
"gitlab.com/gitlab-org/labkit/monitoring"
)
+// Blackbox encapsulates all details required to run the blackbox prober.
+type Blackbox struct {
+ cfg Config
+}
+
+// New creates a new Blackbox structure.
+func New(cfg Config) Blackbox {
+ return Blackbox{
+ cfg: cfg,
+ }
+}
+
// Run starts the blackbox. It sets up and serves the Prometheus listener and starts a Goroutine
// which runs the probes.
-func Run(cfg Config) error {
- listener, err := net.Listen("tcp", cfg.PrometheusListenAddr)
+func (b Blackbox) Run() error {
+ listener, err := net.Listen("tcp", b.cfg.PrometheusListenAddr)
if err != nil {
return err
}
- go runProbes(cfg)
+ go b.runProbes()
return servePrometheus(listener)
}
-func runProbes(cfg Config) {
- for ; ; time.Sleep(cfg.sleepDuration) {
- for _, probe := range cfg.Probes {
- doProbe(probe)
+func (b Blackbox) runProbes() {
+ for ; ; time.Sleep(b.cfg.sleepDuration) {
+ for _, probe := range b.cfg.Probes {
+ b.doProbe(probe)
}
}
}
@@ -40,7 +52,7 @@ func servePrometheus(l net.Listener) error {
)
}
-func doProbe(probe Probe) {
+func (b Blackbox) doProbe(probe Probe) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()