diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-02-26 16:36:28 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-03-07 10:43:04 +0300 |
commit | 5a0d0dd8a020c73d7fe8bab59fe297e543eaef4a (patch) | |
tree | e11b5af2259e167f74a8b885ff2eabb08516b03f | |
parent | 35a0d3ebf0fd0418218875a34c54beb5b4e01b34 (diff) |
Enable Prometheus for praefect
Eventhough the listeners were added before, it was chosen to keep that
MR more focussed and the config for the listener was to be added later.
This commit adds the configuration option, in line with how Gitaly does
it.
-rw-r--r-- | changelogs/unreleased/zj-praefect-prometheus.yml | 5 | ||||
-rw-r--r-- | cmd/praefect/main.go | 12 | ||||
-rw-r--r-- | config.praefect.toml.example | 2 | ||||
-rw-r--r-- | internal/praefect/config/config.go | 7 |
4 files changed, 23 insertions, 3 deletions
diff --git a/changelogs/unreleased/zj-praefect-prometheus.yml b/changelogs/unreleased/zj-praefect-prometheus.yml new file mode 100644 index 000000000..dbc02885b --- /dev/null +++ b/changelogs/unreleased/zj-praefect-prometheus.yml @@ -0,0 +1,5 @@ +--- +title: Add prometheus listener to Praefect +merge_request: 1108 +author: +type: added diff --git a/cmd/praefect/main.go b/cmd/praefect/main.go index 23e5aa89e..a6d99e080 100644 --- a/cmd/praefect/main.go +++ b/cmd/praefect/main.go @@ -6,11 +6,13 @@ import ( "flag" "fmt" "net" + "net/http" "os" "os/signal" "syscall" "time" + "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/praefect" "gitlab.com/gitlab-org/gitaly/internal/praefect/config" @@ -60,6 +62,16 @@ func configure() (config.Config, error) { logger = conf.ConfigureLogger() tracing.Initialize(tracing.WithServiceName("praefect")) + if conf.PrometheusListenAddr != "" { + logger.WithField("address", conf.PrometheusListenAddr).Info("Starting prometheus listener") + promMux := http.NewServeMux() + promMux.Handle("/metrics", promhttp.Handler()) + + go func() { + http.ListenAndServe(conf.PrometheusListenAddr, promMux) + }() + } + return conf, nil } diff --git a/config.praefect.toml.example b/config.praefect.toml.example index f21880772..9f041a3f3 100644 --- a/config.praefect.toml.example +++ b/config.praefect.toml.example @@ -3,6 +3,8 @@ # # TCP address to listen on listen_addr = "127.0.0.1:2305" # socket_path = "/home/git/gitlab/tmp/sockets/private/praefect.socket" +# +prometheus_listen_addr = "127.0.0.1:10101" # # You can optionally configure Praefect to output JSON-formatted log messages to stdout # [logging] diff --git a/internal/praefect/config/config.go b/internal/praefect/config/config.go index 7c58ef277..0aecae847 100644 --- a/internal/praefect/config/config.go +++ b/internal/praefect/config/config.go @@ -10,9 +10,10 @@ import ( // Config is a container for everything found in the TOML config file type Config struct { - ListenAddr string `toml:"listen_addr" split_words:"true"` - GitalyServers []*GitalyServer `toml:"gitaly_server", split_words:"true"` - Logging config.Logging `toml:"logging"` + ListenAddr string `toml:"listen_addr" split_words:"true"` + GitalyServers []*GitalyServer `toml:"gitaly_server", split_words:"true"` + Logging config.Logging `toml:"logging"` + PrometheusListenAddr string `toml:"prometheus_listen_addr", split_words:"true"` } // GitalyServer allows configuring the servers that RPCs are proxied to |