Skip to content

Commit

Permalink
Metrics: Disable toggle. Set default port to 9090
Browse files Browse the repository at this point in the history
  • Loading branch information
reynico committed Feb 28, 2022
1 parent 6126d6d commit 9a61725
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 39 deletions.
33 changes: 15 additions & 18 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const (
type Config struct {
ServerURL string
Addr string
MetricsEnabled bool
MetricsAddr string
GRPCAddr string
GRPCAllowInsecure bool
Expand Down Expand Up @@ -658,28 +657,26 @@ func (h *Headscale) Serve() error {
log.Info().
Msgf("listening and serving HTTP on: %s", h.cfg.Addr)

if h.cfg.MetricsEnabled {
promRouter := h.createPrometheusRouter()
promRouter := h.createPrometheusRouter()

promHTTPServer := &http.Server{
Addr: h.cfg.MetricsAddr,
Handler: promRouter,
ReadTimeout: HTTPReadTimeout,
WriteTimeout: 0,
}
promHTTPServer := &http.Server{
Addr: h.cfg.MetricsAddr,
Handler: promRouter,
ReadTimeout: HTTPReadTimeout,
WriteTimeout: 0,
}

var promHTTPListener net.Listener
promHTTPListener, err = net.Listen("tcp", h.cfg.MetricsAddr)
var promHTTPListener net.Listener
promHTTPListener, err = net.Listen("tcp", h.cfg.MetricsAddr)

if err != nil {
return fmt.Errorf("failed to bind to TCP address: %w", err)
}
if err != nil {
return fmt.Errorf("failed to bind to TCP address: %w", err)
}

errorGroup.Go(func() error { return promHTTPServer.Serve(promHTTPListener) })
errorGroup.Go(func() error { return promHTTPServer.Serve(promHTTPListener) })

log.Info().
Msgf("listening and serving metrics on: %s", h.cfg.MetricsAddr)
}
log.Info().
Msgf("listening and serving metrics on: %s", h.cfg.MetricsAddr)

return errorGroup.Wait()
}
Expand Down
1 change: 0 additions & 1 deletion cmd/headscale/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ func getHeadscaleConfig() headscale.Config {
return headscale.Config{
ServerURL: viper.GetString("server_url"),
Addr: viper.GetString("listen_addr"),
MetricsEnabled: viper.GetBool("metrics_enabled"),
MetricsAddr: viper.GetString("metrics_listen_addr"),
GRPCAddr: viper.GetString("grpc_listen_addr"),
GRPCAllowInsecure: viper.GetBool("grpc_allow_insecure"),
Expand Down
3 changes: 1 addition & 2 deletions cmd/headscale/headscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ func (*Suite) TestConfigLoading(c *check.C) {
// Test that config file was interpreted correctly
c.Assert(viper.GetString("server_url"), check.Equals, "http://127.0.0.1:8080")
c.Assert(viper.GetString("listen_addr"), check.Equals, "0.0.0.0:8080")
c.Assert(viper.GetString("metrics_listen_addr"), check.Equals, "127.0.0.1:9915")
c.Assert(viper.GetString("metrics_enabled"), check.Equals, "true")
c.Assert(viper.GetString("metrics_listen_addr"), check.Equals, "127.0.0.1:9090")
c.Assert(viper.GetString("db_type"), check.Equals, "sqlite3")
c.Assert(viper.GetString("db_path"), check.Equals, "/var/lib/headscale/db.sqlite")
c.Assert(viper.GetString("tls_letsencrypt_hostname"), check.Equals, "")
Expand Down
5 changes: 1 addition & 4 deletions config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ server_url: http://127.0.0.1:8080
#
listen_addr: 0.0.0.0:8080

# Enable Prometheus metrics endpoint
metrics_enabled: true

# Address to listen to /metrics, you may want
# to keep this endpoint private to your internal
# network
#
metrics_listen_addr: 127.0.0.1:9915
metrics_listen_addr: 127.0.0.1:9090

# Address to listen for gRPC.
# gRPC is used for controlling a headscale server
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/kustomize/base/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ metadata:
data:
server_url: $(PUBLIC_PROTO)://$(PUBLIC_HOSTNAME)
listen_addr: "0.0.0.0:8080"
metrics_enabled: "true"
metrics_listen_addr: "127.0.0.1:9915"
metrics_listen_addr: "127.0.0.1:9090"
ephemeral_node_inactivity_timeout: "30m"
5 changes: 0 additions & 5 deletions docs/examples/kustomize/postgres/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ spec:
configMapKeyRef:
name: headscale-config
key: metrics_listen_addr
- name: METRICS_ENABLED
valueFrom:
configMapKeyRef:
name: headscale-config
key: metrics_enabled
- name: DERP_MAP_PATH
value: /vol/config/derp.yaml
- name: EPHEMERAL_NODE_INACTIVITY_TIMEOUT
Expand Down
5 changes: 0 additions & 5 deletions docs/examples/kustomize/sqlite/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ spec:
configMapKeyRef:
name: headscale-config
key: metrics_listen_addr
- name: METRICS_ENABLED
valueFrom:
configMapKeyRef:
name: headscale-config
key: metrics_enabled
- name: DERP_MAP_PATH
value: /vol/config/derp.yaml
- name: EPHEMERAL_NODE_INACTIVITY_TIMEOUT
Expand Down
3 changes: 1 addition & 2 deletions integration_test/etc/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ dns_config:
db_path: /tmp/integration_test_db.sqlite3
private_key_path: private.key
listen_addr: 0.0.0.0:8080
metrics_enabled: true
metrics_listen_addr: 127.0.0.1:9915
metrics_listen_addr: 127.0.0.1:9090
server_url: http://headscale:8080

derp:
Expand Down

0 comments on commit 9a61725

Please sign in to comment.