Skip to content
Snippets Groups Projects
Commit d057c11d authored by Jan Christophersen's avatar Jan Christophersen
Browse files

Use 9252 as default port for metrics server

parent 3d2d0cc2
No related branches found
No related tags found
No related merge requests found
...@@ -2,10 +2,13 @@ package commands ...@@ -2,10 +2,13 @@ package commands
import ( import (
"fmt" "fmt"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common" "net"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/network"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/network"
) )
func getDefaultConfigFile() string { func getDefaultConfigFile() string {
...@@ -70,12 +73,22 @@ type configOptionsWithMetricsServer struct { ...@@ -70,12 +73,22 @@ type configOptionsWithMetricsServer struct {
MetricsServerAddress string `long:"metrics-server" env:"METRICS_SERVER" description:"Metrics server listening address"` MetricsServerAddress string `long:"metrics-server" env:"METRICS_SERVER" description:"Metrics server listening address"`
} }
func (c *configOptionsWithMetricsServer) metricsServerAddress() string { func (c *configOptionsWithMetricsServer) metricsServerAddress() (string, error) {
address := c.config.MetricsServerAddress
if c.MetricsServerAddress != "" { if c.MetricsServerAddress != "" {
return c.MetricsServerAddress address = c.MetricsServerAddress
}
_, port, err := net.SplitHostPort(address)
if err != nil && !strings.Contains(err.Error(), "missing port in address") {
return address, err
} }
return c.config.MetricsServerAddress if len(port) == 0 {
return fmt.Sprintf("%s:%d", address, common.DefaultMetricsServerPort), nil
}
return c.config.MetricsServerAddress, nil
} }
func init() { func init() {
......
...@@ -370,14 +370,21 @@ func (mr *RunCommand) serveDebugData() { ...@@ -370,14 +370,21 @@ func (mr *RunCommand) serveDebugData() {
} }
func (mr *RunCommand) setupMetricsAndDebugServer() { func (mr *RunCommand) setupMetricsAndDebugServer() {
if mr.metricsServerAddress() == "" { serverAddress, err := mr.metricsServerAddress()
if err != nil {
mr.log().Errorf("invalid metrics server address: %s", err.Error())
return
}
if serverAddress == "" {
log.Infoln("Metrics server disabled") log.Infoln("Metrics server disabled")
return return
} }
// We separate out the listener creation here so that we can return an error if // We separate out the listener creation here so that we can return an error if
// the provided address is invalid or there is some other listener error. // the provided address is invalid or there is some other listener error.
listener, err := net.Listen("tcp", mr.metricsServerAddress()) listener, err := net.Listen("tcp", serverAddress)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
...@@ -389,7 +396,7 @@ func (mr *RunCommand) setupMetricsAndDebugServer() { ...@@ -389,7 +396,7 @@ func (mr *RunCommand) setupMetricsAndDebugServer() {
mr.serveMetrics() mr.serveMetrics()
mr.serveDebugData() mr.serveDebugData()
log.Infoln("Metrics server listening at", mr.metricsServerAddress()) log.Infoln("Metrics server listening at", serverAddress)
} }
func (mr *RunCommand) Run() { func (mr *RunCommand) Run() {
......
...@@ -22,5 +22,6 @@ const DefaultRestoreCacheAttempts = 1 ...@@ -22,5 +22,6 @@ const DefaultRestoreCacheAttempts = 1
const KubernetesPollInterval = 3 const KubernetesPollInterval = 3
const KubernetesPollTimeout = 180 const KubernetesPollTimeout = 180
const AfterScriptTimeout = 5 * time.Minute const AfterScriptTimeout = 5 * time.Minute
const DefaultMetricsServerPort = 9252
var PreparationRetryInterval = 3 * time.Second var PreparationRetryInterval = 3 * time.Second
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment