From cf3fc85196e13e52db055dbc594d437dcc9765ac Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Tue, 12 Jul 2022 12:27:28 +0200 Subject: [PATCH 1/4] Make tailnet updates check configurable --- config-example.yaml | 6 ++++++ config.go | 16 ++++++++++++++++ poll.go | 5 ++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/config-example.yaml b/config-example.yaml index 9740f3ad..c32f9416 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -103,6 +103,12 @@ disable_check_updates: false # Time before an inactive ephemeral node is deleted? ephemeral_node_inactivity_timeout: 30m +# Period to check for changes in the tailnet. A value too low will severily affect +# CPU consumption of Headscale. A value too high (over 60s) will cause problems +# to the nodes, as they won't get updates or keep alive messages on time. +# In case of doubts, do not touch the default 10s. +changes_check_interval: 10s + # SQLite config db_type: sqlite3 db_path: /var/lib/headscale/db.sqlite diff --git a/config.go b/config.go index 9e71a750..0ef09110 100644 --- a/config.go +++ b/config.go @@ -26,6 +26,7 @@ type Config struct { GRPCAddr string GRPCAllowInsecure bool EphemeralNodeInactivityTimeout time.Duration + ChangesCheckInterval time.Duration IPPrefixes []netaddr.IPPrefix PrivateKeyPath string BaseDomain string @@ -162,6 +163,8 @@ func LoadConfig(path string, isFile bool) error { viper.SetDefault("ephemeral_node_inactivity_timeout", "120s") + viper.SetDefault("changes_check_interval", "10s") + if err := viper.ReadInConfig(); err != nil { log.Warn().Err(err).Msg("Failed to read configuration from disk") @@ -217,6 +220,15 @@ func LoadConfig(path string, isFile bool) error { ) } + maxChangesCheckInterval, _ := time.ParseDuration("60s") + if viper.GetDuration("changes_check_interval") > maxChangesCheckInterval { + errorText += fmt.Sprintf( + "Fatal config error: changes_check_interval (%s) is set too high, must be less than %s", + viper.GetString("changes_check_interval"), + maxChangesCheckInterval, + ) + } + if errorText != "" { //nolint return errors.New(strings.TrimSuffix(errorText, "\n")) @@ -478,6 +490,10 @@ func GetHeadscaleConfig() (*Config, error) { "ephemeral_node_inactivity_timeout", ), + ChangesCheckInterval: viper.GetDuration( + "changes_check_interval", + ), + DBtype: viper.GetString("db_type"), DBpath: AbsolutePathFromConfigPath(viper.GetString("db_path")), DBhost: viper.GetString("db_host"), diff --git a/poll.go b/poll.go index 9218495d..95fb542c 100644 --- a/poll.go +++ b/poll.go @@ -16,8 +16,7 @@ import ( ) const ( - keepAliveInterval = 60 * time.Second - updateCheckInterval = 10 * time.Second + keepAliveInterval = 60 * time.Second ) type contextKey string @@ -640,7 +639,7 @@ func (h *Headscale) scheduledPollWorker( machine *Machine, ) { keepAliveTicker := time.NewTicker(keepAliveInterval) - updateCheckerTicker := time.NewTicker(updateCheckInterval) + updateCheckerTicker := time.NewTicker(h.cfg.ChangesCheckInterval) defer closeChanWithLog( updateChan, From 8e0939f403147f7cb5c3f294e0df6ea6f76d1688 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Tue, 12 Jul 2022 12:33:42 +0200 Subject: [PATCH 2/4] Updated changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e916056..23064ac1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,11 +30,10 @@ - Add -c option to specify config file from command line [#285](https://github.com/juanfont/headscale/issues/285) [#612](https://github.com/juanfont/headscale/pull/601) - Add configuration option to allow Tailscale clients to use a random WireGuard port. [kb/1181/firewalls](https://tailscale.com/kb/1181/firewalls) [#624](https://github.com/juanfont/headscale/pull/624) - Improve obtuse UX regarding missing configuration (`ephemeral_node_inactivity_timeout` not set) [#639](https://github.com/juanfont/headscale/pull/639) -- Fix nodes being shown as 'offline' in `tailscale status` [648](https://github.com/juanfont/headscale/pull/648) - Fix nodes being shown as 'offline' in `tailscale status` [#648](https://github.com/juanfont/headscale/pull/648) - Improve shutdown behaviour [#651](https://github.com/juanfont/headscale/pull/651) - Drop Gin as web framework in Headscale [648](https://github.com/juanfont/headscale/pull/648) - +- Make tailnet updates check interval configurable [#675](https://github.com/juanfont/headscale/pull/675) ## 0.15.0 (2022-03-20) From 5b5298b0255098a0653da985f3b412fc133cbb40 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Tue, 12 Jul 2022 12:52:03 +0200 Subject: [PATCH 3/4] Renamed config param for node update check internal --- CHANGELOG.md | 2 +- config-example.yaml | 6 +++--- config.go | 18 +++++++++--------- poll.go | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23064ac1..1c63ae49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ - Fix nodes being shown as 'offline' in `tailscale status` [#648](https://github.com/juanfont/headscale/pull/648) - Improve shutdown behaviour [#651](https://github.com/juanfont/headscale/pull/651) - Drop Gin as web framework in Headscale [648](https://github.com/juanfont/headscale/pull/648) -- Make tailnet updates check interval configurable [#675](https://github.com/juanfont/headscale/pull/675) +- Make tailnet node updates check interval configurable [#675](https://github.com/juanfont/headscale/pull/675) ## 0.15.0 (2022-03-20) diff --git a/config-example.yaml b/config-example.yaml index c32f9416..d3d155e2 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -103,11 +103,11 @@ disable_check_updates: false # Time before an inactive ephemeral node is deleted? ephemeral_node_inactivity_timeout: 30m -# Period to check for changes in the tailnet. A value too low will severily affect +# Period to check for node updates in the tailnet. A value too low will severily affect # CPU consumption of Headscale. A value too high (over 60s) will cause problems -# to the nodes, as they won't get updates or keep alive messages on time. +# to the nodes, as they won't get updates or keep alive messages in time. # In case of doubts, do not touch the default 10s. -changes_check_interval: 10s +node_update_check_interval: 10s # SQLite config db_type: sqlite3 diff --git a/config.go b/config.go index 0ef09110..6789f6f0 100644 --- a/config.go +++ b/config.go @@ -26,7 +26,7 @@ type Config struct { GRPCAddr string GRPCAllowInsecure bool EphemeralNodeInactivityTimeout time.Duration - ChangesCheckInterval time.Duration + NodeUpdateCheckInterval time.Duration IPPrefixes []netaddr.IPPrefix PrivateKeyPath string BaseDomain string @@ -163,7 +163,7 @@ func LoadConfig(path string, isFile bool) error { viper.SetDefault("ephemeral_node_inactivity_timeout", "120s") - viper.SetDefault("changes_check_interval", "10s") + viper.SetDefault("node_update_check_interval", "10s") if err := viper.ReadInConfig(); err != nil { log.Warn().Err(err).Msg("Failed to read configuration from disk") @@ -220,12 +220,12 @@ func LoadConfig(path string, isFile bool) error { ) } - maxChangesCheckInterval, _ := time.ParseDuration("60s") - if viper.GetDuration("changes_check_interval") > maxChangesCheckInterval { + maxNodeUpdateCheckInterval, _ := time.ParseDuration("60s") + if viper.GetDuration("node_update_check_interval") > maxNodeUpdateCheckInterval { errorText += fmt.Sprintf( - "Fatal config error: changes_check_interval (%s) is set too high, must be less than %s", - viper.GetString("changes_check_interval"), - maxChangesCheckInterval, + "Fatal config error: node_update_check_interval (%s) is set too high, must be less than %s", + viper.GetString("node_update_check_interval"), + maxNodeUpdateCheckInterval, ) } @@ -490,8 +490,8 @@ func GetHeadscaleConfig() (*Config, error) { "ephemeral_node_inactivity_timeout", ), - ChangesCheckInterval: viper.GetDuration( - "changes_check_interval", + NodeUpdateCheckInterval: viper.GetDuration( + "node_update_check_interval", ), DBtype: viper.GetString("db_type"), diff --git a/poll.go b/poll.go index 95fb542c..6628a179 100644 --- a/poll.go +++ b/poll.go @@ -639,7 +639,7 @@ func (h *Headscale) scheduledPollWorker( machine *Machine, ) { keepAliveTicker := time.NewTicker(keepAliveInterval) - updateCheckerTicker := time.NewTicker(h.cfg.ChangesCheckInterval) + updateCheckerTicker := time.NewTicker(h.cfg.NodeUpdateCheckInterval) defer closeChanWithLog( updateChan, From 4ccff8bf2891d36225983ad42d0b36f28b9b368a Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Tue, 12 Jul 2022 13:13:04 +0200 Subject: [PATCH 4/4] Added the new parameter to the integration test params --- integration_test/etc/alt-config.dump.gold.yaml | 1 + integration_test/etc/alt-config.yaml | 1 + integration_test/etc/config.dump.gold.yaml | 1 + integration_test/etc/config.yaml | 1 + integration_test/etc_embedded_derp/config.yaml | 1 + 5 files changed, 5 insertions(+) diff --git a/integration_test/etc/alt-config.dump.gold.yaml b/integration_test/etc/alt-config.dump.gold.yaml index a3d7adb0..e8934230 100644 --- a/integration_test/etc/alt-config.dump.gold.yaml +++ b/integration_test/etc/alt-config.dump.gold.yaml @@ -20,6 +20,7 @@ dns_config: nameservers: - 1.1.1.1 ephemeral_node_inactivity_timeout: 30m +node_update_check_interval: 10s grpc_allow_insecure: false grpc_listen_addr: :50443 ip_prefixes: diff --git a/integration_test/etc/alt-config.yaml b/integration_test/etc/alt-config.yaml index 8de9a828..fa1bfcb3 100644 --- a/integration_test/etc/alt-config.yaml +++ b/integration_test/etc/alt-config.yaml @@ -2,6 +2,7 @@ log_level: trace acl_policy_path: "" db_type: sqlite3 ephemeral_node_inactivity_timeout: 30m +node_update_check_interval: 10s ip_prefixes: - fd7a:115c:a1e0::/48 - 100.64.0.0/10 diff --git a/integration_test/etc/config.dump.gold.yaml b/integration_test/etc/config.dump.gold.yaml index 4d03d74e..17bb0ca0 100644 --- a/integration_test/etc/config.dump.gold.yaml +++ b/integration_test/etc/config.dump.gold.yaml @@ -20,6 +20,7 @@ dns_config: nameservers: - 1.1.1.1 ephemeral_node_inactivity_timeout: 30m +node_update_check_interval: 10s grpc_allow_insecure: false grpc_listen_addr: :50443 ip_prefixes: diff --git a/integration_test/etc/config.yaml b/integration_test/etc/config.yaml index f055b4ca..e6b34afa 100644 --- a/integration_test/etc/config.yaml +++ b/integration_test/etc/config.yaml @@ -2,6 +2,7 @@ log_level: trace acl_policy_path: "" db_type: sqlite3 ephemeral_node_inactivity_timeout: 30m +node_update_check_interval: 10s ip_prefixes: - fd7a:115c:a1e0::/48 - 100.64.0.0/10 diff --git a/integration_test/etc_embedded_derp/config.yaml b/integration_test/etc_embedded_derp/config.yaml index a8b57af5..e6ad3b00 100644 --- a/integration_test/etc_embedded_derp/config.yaml +++ b/integration_test/etc_embedded_derp/config.yaml @@ -2,6 +2,7 @@ log_level: trace acl_policy_path: "" db_type: sqlite3 ephemeral_node_inactivity_timeout: 30m +node_update_check_interval: 10s ip_prefixes: - fd7a:115c:a1e0::/48 - 100.64.0.0/10