Skip to content

Commit

Permalink
Merge pull request #675 from juanfont/configurable-update-interval
Browse files Browse the repository at this point in the history
Make tailnet updates check interval configurable
  • Loading branch information
juanfont authored Jul 12, 2022
2 parents e0b15c1 + 4ccff8b commit c50d3aa
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 5 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 node updates check interval configurable [#675](https://github.com/juanfont/headscale/pull/675)

## 0.15.0 (2022-03-20)

Expand Down
6 changes: 6 additions & 0 deletions config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 in time.
# In case of doubts, do not touch the default 10s.
node_update_check_interval: 10s

# SQLite config
db_type: sqlite3
db_path: /var/lib/headscale/db.sqlite
Expand Down
16 changes: 16 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Config struct {
GRPCAddr string
GRPCAllowInsecure bool
EphemeralNodeInactivityTimeout time.Duration
NodeUpdateCheckInterval time.Duration
IPPrefixes []netaddr.IPPrefix
PrivateKeyPath string
BaseDomain string
Expand Down Expand Up @@ -162,6 +163,8 @@ func LoadConfig(path string, isFile bool) error {

viper.SetDefault("ephemeral_node_inactivity_timeout", "120s")

viper.SetDefault("node_update_check_interval", "10s")

if err := viper.ReadInConfig(); err != nil {
log.Warn().Err(err).Msg("Failed to read configuration from disk")

Expand Down Expand Up @@ -217,6 +220,15 @@ func LoadConfig(path string, isFile bool) error {
)
}

maxNodeUpdateCheckInterval, _ := time.ParseDuration("60s")
if viper.GetDuration("node_update_check_interval") > maxNodeUpdateCheckInterval {
errorText += fmt.Sprintf(
"Fatal config error: node_update_check_interval (%s) is set too high, must be less than %s",
viper.GetString("node_update_check_interval"),
maxNodeUpdateCheckInterval,
)
}

if errorText != "" {
//nolint
return errors.New(strings.TrimSuffix(errorText, "\n"))
Expand Down Expand Up @@ -478,6 +490,10 @@ func GetHeadscaleConfig() (*Config, error) {
"ephemeral_node_inactivity_timeout",
),

NodeUpdateCheckInterval: viper.GetDuration(
"node_update_check_interval",
),

DBtype: viper.GetString("db_type"),
DBpath: AbsolutePathFromConfigPath(viper.GetString("db_path")),
DBhost: viper.GetString("db_host"),
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc/alt-config.dump.gold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc/alt-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc/config.dump.gold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions integration_test/etc_embedded_derp/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import (
)

const (
keepAliveInterval = 60 * time.Second
updateCheckInterval = 10 * time.Second
keepAliveInterval = 60 * time.Second
)

type contextKey string
Expand Down Expand Up @@ -640,7 +639,7 @@ func (h *Headscale) scheduledPollWorker(
machine *Machine,
) {
keepAliveTicker := time.NewTicker(keepAliveInterval)
updateCheckerTicker := time.NewTicker(updateCheckInterval)
updateCheckerTicker := time.NewTicker(h.cfg.NodeUpdateCheckInterval)

defer closeChanWithLog(
updateChan,
Expand Down

0 comments on commit c50d3aa

Please sign in to comment.