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-22 13:40:17 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-06-30 13:03:46 +0300
commit4e36ad35d4c963f3210c3cd84b5b037b7aa192bf (patch)
treeb85e7ef5574acf06dd1e3fa99f4c8448299fd142
parentd4f94e91332482c6d8e9e81f9db48ebb71c08fb5 (diff)
blackbox: Introduce probe type
We're about to introduce a new probe type for HTTP-based pushes. As a preparatory step, add a new probe type to the blackbox configuration which allows the admin to discern between these types. For now, only "fetch" probes are supported -- "push" probes will be added in a subsequent commit. In order to maintain backwards compatibility with old configurations, specifying no type will fall back to "fetch" probes.
-rw-r--r--internal/blackbox/blackbox.go33
-rw-r--r--internal/blackbox/config.go19
-rw-r--r--internal/blackbox/config_test.go9
3 files changed, 52 insertions, 9 deletions
diff --git a/internal/blackbox/blackbox.go b/internal/blackbox/blackbox.go
index 4dac46eee..e9259a78e 100644
--- a/internal/blackbox/blackbox.go
+++ b/internal/blackbox/blackbox.go
@@ -2,6 +2,7 @@ package blackbox
import (
"context"
+ "fmt"
"net"
"time"
@@ -137,7 +138,25 @@ func (b Blackbox) Run() error {
func (b Blackbox) runProbes() {
for ; ; time.Sleep(b.cfg.sleepDuration) {
for _, probe := range b.cfg.Probes {
- b.doProbe(probe)
+ entry := log.WithFields(map[string]interface{}{
+ "probe": probe.Name,
+ "type": probe.Type,
+ })
+
+ entry.Info("starting probe")
+
+ var err error
+ switch probe.Type {
+ case Fetch:
+ err = b.fetch(probe)
+ default:
+ err = fmt.Errorf("unsupported probe type: %q", probe.Type)
+ }
+ if err != nil {
+ entry.WithError(err).Error("probe failed")
+ }
+
+ entry.Info("finished probe")
}
}
}
@@ -149,21 +168,15 @@ func servePrometheus(l net.Listener) error {
)
}
-func (b Blackbox) doProbe(probe Probe) {
+func (b Blackbox) fetch(probe Probe) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
- entry := log.WithField("probe", probe.Name)
- entry.Info("starting probe")
-
clone, err := stats.PerformHTTPClone(ctx, probe.URL, probe.User, probe.Password, false)
if err != nil {
- entry.WithError(err).Error("probe failed")
- return
+ return err
}
- entry.Info("finished probe")
-
setGauge := func(gv *prometheus.GaugeVec, value float64) {
gv.WithLabelValues(probe.Name).Set(value)
}
@@ -171,4 +184,6 @@ func (b Blackbox) doProbe(probe Probe) {
b.fetchReferenceDiscoveryMetrics.measure(probe.Name, clone.ReferenceDiscovery)
b.httpPostMetrics.measure(probe.Name, &clone.FetchPack)
setGauge(b.wantedRefs, float64(clone.FetchPack.RefsWanted()))
+
+ return nil
}
diff --git a/internal/blackbox/config.go b/internal/blackbox/config.go
index 6e8da380b..8f966c67d 100644
--- a/internal/blackbox/config.go
+++ b/internal/blackbox/config.go
@@ -24,11 +24,23 @@ type Config struct {
Probes []Probe `toml:"probe"`
}
+// ProbeType is the type of the probe.
+type ProbeType string
+
+const (
+ // Fetch exercises the equivalent of git-fetch(1) with measurements for packfile negotiation
+ // and receiving the packfile.
+ Fetch = ProbeType("fetch")
+)
+
// Probe is the configuration for a specific endpoint whose clone performance should be exercised.
type Probe struct {
// Name is the name of the probe. This is used both for logging and for exported
// Prometheus metrics.
Name string `toml:"name"`
+ // Type is the type of the probe. See ProbeType for the supported types. Defaults to `Fetch`
+ // if no type was given.
+ Type ProbeType `toml:"type"`
// URL is the URL of the Git repository that should be probed. For now, only the
// HTTP transport is supported.
URL string `toml:"url"`
@@ -68,6 +80,13 @@ func ParseConfig(raw string) (Config, error) {
return Config{}, fmt.Errorf("all probes must have a 'name' attribute")
}
+ switch probe.Type {
+ case "", Fetch:
+ probe.Type = Fetch
+ default:
+ return Config{}, fmt.Errorf("unsupported probe type: %q", probe.Type)
+ }
+
parsedURL, err := url.Parse(probe.URL)
if err != nil {
return Config{}, err
diff --git a/internal/blackbox/config_test.go b/internal/blackbox/config_test.go
index 9e240761b..be11c89d5 100644
--- a/internal/blackbox/config_test.go
+++ b/internal/blackbox/config_test.go
@@ -49,9 +49,18 @@ func TestConfigParseFailures(t *testing.T) {
expectedErr: errors.New("missing prometheus_listen_addr"),
},
{
+ desc: "invalid probe type",
+ in: "prometheus_listen_addr = 'foo'\n[[probe]]\nname='foo'\nurl='http://foo/bar'\ntype='foo'",
+ expectedErr: errors.New("unsupported probe type: \"foo\""),
+ },
+ {
desc: "valid configuration",
in: "prometheus_listen_addr = 'foo'\n[[probe]]\nname='foo'\nurl='http://foo/bar'\n",
},
+ {
+ desc: "valid configuration with explicit type",
+ in: "prometheus_listen_addr = 'foo'\n[[probe]]\nname='foo'\nurl='http://foo/bar'\ntype='fetch'",
+ },
}
for _, tc := range testCases {