diff options
author | Igor Wiedler <iwiedler@gitlab.com> | 2020-04-27 18:26:29 +0300 |
---|---|---|
committer | Igor Wiedler <iwiedler@gitlab.com> | 2020-04-27 18:26:29 +0300 |
commit | 1ed3180b610563430d3a51db3659f45205687aab (patch) | |
tree | c0667e93b45cd710aee70780aa65b394fb0f7099 | |
parent | fc85da228e669e88b001667b8314ce2e4e7f9510 (diff) |
use labkit monitoring.Start() to get auto pprof on metrics port
-rw-r--r-- | app.go | 18 | ||||
-rw-r--r-- | app_config.go | 2 | ||||
-rw-r--r-- | main.go | 2 |
3 files changed, 19 insertions, 3 deletions
@@ -3,15 +3,18 @@ package main import ( "crypto/tls" "errors" + "fmt" + "net" "net/http" + "os" "sync" ghandlers "github.com/gorilla/handlers" - "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/rs/cors" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/labkit/errortracking" "gitlab.com/gitlab-org/labkit/metrics" + "gitlab.com/gitlab-org/labkit/monitoring" mimedb "gitlab.com/lupine/go-mimedb" "gitlab.com/gitlab-org/gitlab-pages/internal/acme" @@ -430,8 +433,17 @@ func (a *theApp) listenMetricsFD(wg *sync.WaitGroup, fd uintptr) { go func() { defer wg.Done() - handler := promhttp.Handler() - err := listenAndServe(fd, handler, false, nil, nil) + l, err := net.FileListener(os.NewFile(fd, "[socket]")) + if err != nil { + capturingFatal(fmt.Errorf("failed to listen on FD %d: %v", fd, err), errortracking.WithField("listener", "metrics")) + } + + monitoringOpts := []monitoring.Option{ + monitoring.WithBuildInformation(a.Version, ""), + monitoring.WithListener(l), + } + + err = monitoring.Start(monitoringOpts...) if err != nil { capturingFatal(err, errortracking.WithField("listener", "metrics")) } diff --git a/app_config.go b/app_config.go index 245a9e0d..a39067a6 100644 --- a/app_config.go +++ b/app_config.go @@ -38,6 +38,8 @@ type appConfig struct { SentryDSN string SentryEnvironment string CustomHeaders []string + + Version string } // GitlabServerURL returns URL to a GitLab instance. @@ -239,6 +239,8 @@ func loadConfig() appConfig { initErrorReporting(config.SentryDSN, config.SentryEnvironment) } + config.Version = VERSION + log.WithFields(log.Fields{ "artifacts-server": *artifactsServer, "artifacts-server-timeout": *artifactsServerTimeout, |