Commit 6c5fa42c authored by Ben Kochie's avatar Ben Kochie Committed by Kamil Trzciński

Start rename of "metrics server" config

parent 04f0eac7
......@@ -7,6 +7,8 @@ import (
"path/filepath"
"strings"
"github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/network"
)
......@@ -67,18 +69,15 @@ func (c *configOptions) RunnerByName(name string) (*common.RunnerConfig, error)
return nil, fmt.Errorf("Could not find a runner with the name '%s'", name)
}
type configOptionsWithMetricsServer struct {
type configOptionsWithListenAddress struct {
configOptions
MetricsServerAddress string `long:"metrics-server" env:"METRICS_SERVER" description:"Metrics server listening address"`
MetricsServerAddress string `long:"metrics-server" env:"METRICS_SERVER" description:"(DEPRECATED) Metrics / pprof server listening address"` //DEPRECATED
ListenAddress string `long:"listen-address" env:"LISTEN_ADDRESS" description:"Metrics / pprof server listening address"`
}
func (c *configOptionsWithMetricsServer) metricsServerAddress() (string, error) {
address := c.config.MetricsServerAddress
if c.MetricsServerAddress != "" {
address = c.MetricsServerAddress
}
func (c *configOptionsWithListenAddress) listenAddress() (string, error) {
address := c.listenOrMetricsServerAddress()
if address == "" {
return "", nil
......@@ -95,6 +94,20 @@ func (c *configOptionsWithMetricsServer) metricsServerAddress() (string, error)
return address, nil
}
func (c *configOptionsWithListenAddress) listenOrMetricsServerAddress() string {
if c.ListenAddress != "" {
return c.ListenAddress
}
if c.MetricsServerAddress != "" {
logrus.Warnln("'metrics-server' command line option is deprecated and will be removed in one of future releases; please use 'listen-address' instead")
return c.MetricsServerAddress
}
return c.config.ListenOrServerMetricAddress()
}
func init() {
configFile := os.Getenv("CONFIG_FILE")
if configFile == "" {
......
......@@ -22,19 +22,19 @@ const (
configurationFromConfig metricsServerConfigurationType = "from-config"
)
func testMetricsServerSetting(t *testing.T, exampleName string, example metricsServerTestExample, testType metricsServerConfigurationType) {
func testListenAddressSetting(t *testing.T, exampleName string, example metricsServerTestExample, testType metricsServerConfigurationType) {
t.Run(fmt.Sprintf("%s-%s", exampleName, testType), func(t *testing.T) {
cfg := configOptionsWithMetricsServer{}
cfg := configOptionsWithListenAddress{}
cfg.config = &common.Config{}
if example.setAddress {
if testType == configurationFromCli {
cfg.MetricsServerAddress = example.address
cfg.ListenAddress = example.address
} else {
cfg.config.MetricsServerAddress = example.address
cfg.config.ListenAddress = example.address
}
}
address, err := cfg.metricsServerAddress()
address, err := cfg.listenAddress()
assert.Equal(t, example.expectedAddress, address)
if example.errorIsExpected {
assert.Error(t, err)
......@@ -55,7 +55,7 @@ func TestMetricsServer(t *testing.T) {
}
for exampleName, example := range examples {
testMetricsServerSetting(t, exampleName, example, configurationFromCli)
testMetricsServerSetting(t, exampleName, example, configurationFromConfig)
testListenAddressSetting(t, exampleName, example, configurationFromCli)
testListenAddressSetting(t, exampleName, example, configurationFromConfig)
}
}
......@@ -29,7 +29,7 @@ import (
)
type RunCommand struct {
configOptionsWithMetricsServer
configOptionsWithListenAddress
network common.Network
healthHelper
......@@ -379,21 +379,21 @@ func (mr *RunCommand) serveDebugData() {
}
func (mr *RunCommand) setupMetricsAndDebugServer() {
serverAddress, err := mr.metricsServerAddress()
listenAddress, err := mr.listenAddress()
if err != nil {
mr.log().Errorf("invalid metrics server address: %s", err.Error())
mr.log().Errorf("invalid listen address: %s", err.Error())
return
}
if serverAddress == "" {
if listenAddress == "" {
log.Infoln("Metrics server disabled")
return
}
// 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.
listener, err := net.Listen("tcp", serverAddress)
listener, err := net.Listen("tcp", listenAddress)
if err != nil {
log.Fatalln(err)
}
......@@ -405,7 +405,7 @@ func (mr *RunCommand) setupMetricsAndDebugServer() {
mr.serveMetrics()
mr.serveDebugData()
log.Infoln("Metrics server listening at", serverAddress)
log.Infoln("Metrics server listening at", listenAddress)
}
func (mr *RunCommand) Run() {
......
......@@ -264,15 +264,17 @@ type RunnerConfig struct {
}
type Config struct {
MetricsServerAddress string `toml:"metrics_server,omitempty" json:"metrics_server"`
Concurrent int `toml:"concurrent" json:"concurrent"`
CheckInterval int `toml:"check_interval" json:"check_interval" description:"Define active checking interval of jobs"`
LogLevel *string `toml:"log_level" json:"log_level" description:"Define log level (one of: panic, fatal, error, warning, info, debug)"`
User string `toml:"user,omitempty" json:"user"`
Runners []*RunnerConfig `toml:"runners" json:"runners"`
SentryDSN *string `toml:"sentry_dsn"`
ModTime time.Time `toml:"-"`
Loaded bool `toml:"-"`
MetricsServerAddress string `toml:"metrics_server,omitempty" json:"metrics_server"` // DEPRECATED
ListenAddress string `toml:"listen_address,omitempty" json:"listen_address"`
Concurrent int `toml:"concurrent" json:"concurrent"`
CheckInterval int `toml:"check_interval" json:"check_interval" description:"Define active checking interval of jobs"`
LogLevel *string `toml:"log_level" json:"log_level" description:"Define log level (one of: panic, fatal, error, warning, info, debug)"`
User string `toml:"user,omitempty" json:"user"`
Runners []*RunnerConfig `toml:"runners" json:"runners"`
SentryDSN *string `toml:"sentry_dsn"`
ModTime time.Time `toml:"-"`
Loaded bool `toml:"-"`
}
func (c *DockerConfig) GetNanoCPUs() (int64, error) {
......@@ -515,3 +517,13 @@ func (c *Config) GetCheckInterval() time.Duration {
}
return CheckInterval
}
func (c *Config) ListenOrServerMetricAddress() string {
if c.ListenAddress != "" {
return c.ListenAddress
}
log.Warnln("'metrics_server' configuration entry is deprecated and will be removed in one of future releases; please use 'listen_address' instead")
return c.MetricsServerAddress
}
......@@ -372,7 +372,7 @@ It accepts the following parameters.
| `--working-directory` | the current directory | Specify the root directory where all data will be stored when builds will be run with the **shell** executor |
| `--user` | the current user | Specify the user that will be used to execute builds |
| `--syslog` | `false` | Send all logs to SysLog (Unix) or EventLog (Windows) |
| `--metrics-server` | empty | Address (`<host>:<port>`) on which the Prometheus metrics HTTP server should be listening |
| `--listen-address` | empty | Address (`<host>:<port>`) on which the Prometheus metrics HTTP server should be listening |
### gitlab-runner run-single
......
......@@ -20,7 +20,7 @@ This defines global settings of GitLab Runner.
| `log_level` | Log level (options: debug, info, warn, error, fatal, panic). Note that this setting has lower priority than log-level set by command line argument --debug, -l or --log-level |
| `check_interval` | defines the interval length, in seconds, between new jobs check. The default value is `3`; if set to `0` or lower, the default value will be used. |
| `sentry_dsn` | enable tracking of all system level errors to sentry |
| `metrics_server` | address (`<host>:<port>`) on which the Prometheus metrics HTTP server should be listening |
| `listen_address` | address (`<host>:<port>`) on which the Prometheus metrics HTTP server should be listening |
Example:
......
......@@ -198,8 +198,8 @@ GitLab Runner process and should not be publicly available!
The metrics HTTP server can be configured in two ways:
- with a `metrics_server` global configuration option in `config.toml` file,
- with a `--metrics-server` command line option for the `run` command.
- with a `listen_address` global configuration option in `config.toml` file,
- with a `--listen-address` command line option for the `run` command.
In both cases the option accepts a string with the format `[host]:<port>`,
where:
......@@ -207,7 +207,7 @@ where:
- `host` can be an IP address or a host name,
- `port` is a valid TCP port or symbolic service name (like `http`). We recommend to use port `9252` which is already [allocated in Prometheus](https://github.com/prometheus/prometheus/wiki/Default-port-allocations).
If the metrics server address does not contain a port, it will default to `9252`.
If the listen address does not contain a port, it will default to `9252`.
Examples of addresses:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment