mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-25 17:51:11 +02:00
chore: make reg cache expiry tunable
Mostly for the tests, opts: - tuning.register_cache_expiration - tuning.register_cache_cleanup
This commit is contained in:
parent
8e25f7f9dd
commit
2174f6d0b9
@ -164,6 +164,7 @@ func NewHeadscale(cfg *types.Config) (*Headscale, error) {
|
|||||||
&app,
|
&app,
|
||||||
cfg.ServerURL,
|
cfg.ServerURL,
|
||||||
&cfg.OIDC,
|
&cfg.OIDC,
|
||||||
|
&cfg.Tuning,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if cfg.OIDC.OnlyStartIfOIDCIsAvailable {
|
if cfg.OIDC.OnlyStartIfOIDCIsAvailable {
|
||||||
|
@ -69,6 +69,7 @@ func NewAuthProviderOIDC(
|
|||||||
h *Headscale,
|
h *Headscale,
|
||||||
serverURL string,
|
serverURL string,
|
||||||
cfg *types.OIDCConfig,
|
cfg *types.OIDCConfig,
|
||||||
|
tuning *types.Tuning,
|
||||||
) (*AuthProviderOIDC, error) {
|
) (*AuthProviderOIDC, error) {
|
||||||
var err error
|
var err error
|
||||||
// grab oidc config if it hasn't been already
|
// grab oidc config if it hasn't been already
|
||||||
@ -85,9 +86,19 @@ func NewAuthProviderOIDC(
|
|||||||
Scopes: cfg.Scope,
|
Scopes: cfg.Scope,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cacheExpiration := registerCacheExpiration
|
||||||
|
if tuning.RegisterCacheExpiration != 0 {
|
||||||
|
cacheExpiration = tuning.RegisterCacheExpiration
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheCleanup := registerCacheCleanup
|
||||||
|
if tuning.RegisterCacheCleanup != 0 {
|
||||||
|
cacheCleanup = tuning.RegisterCacheCleanup
|
||||||
|
}
|
||||||
|
|
||||||
registrationCache := zcache.New[string, RegistrationInfo](
|
registrationCache := zcache.New[string, RegistrationInfo](
|
||||||
registerCacheExpiration,
|
cacheExpiration,
|
||||||
registerCacheCleanup,
|
cacheCleanup,
|
||||||
)
|
)
|
||||||
|
|
||||||
return &AuthProviderOIDC{
|
return &AuthProviderOIDC{
|
||||||
|
@ -67,9 +67,19 @@ type State struct {
|
|||||||
// NewState creates and initializes a new State instance, setting up the database,
|
// NewState creates and initializes a new State instance, setting up the database,
|
||||||
// IP allocator, DERP map, policy manager, and loading existing users and nodes.
|
// IP allocator, DERP map, policy manager, and loading existing users and nodes.
|
||||||
func NewState(cfg *types.Config) (*State, error) {
|
func NewState(cfg *types.Config) (*State, error) {
|
||||||
|
cacheExpiration := registerCacheExpiration
|
||||||
|
if cfg.Tuning.RegisterCacheExpiration != 0 {
|
||||||
|
cacheExpiration = cfg.Tuning.RegisterCacheExpiration
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheCleanup := registerCacheCleanup
|
||||||
|
if cfg.Tuning.RegisterCacheCleanup != 0 {
|
||||||
|
cacheCleanup = cfg.Tuning.RegisterCacheCleanup
|
||||||
|
}
|
||||||
|
|
||||||
registrationCache := zcache.New[types.RegistrationID, types.RegisterNode](
|
registrationCache := zcache.New[types.RegistrationID, types.RegisterNode](
|
||||||
registerCacheExpiration,
|
cacheExpiration,
|
||||||
registerCacheCleanup,
|
cacheCleanup,
|
||||||
)
|
)
|
||||||
|
|
||||||
db, err := hsdb.NewHeadscaleDatabase(
|
db, err := hsdb.NewHeadscaleDatabase(
|
||||||
|
@ -235,6 +235,8 @@ type Tuning struct {
|
|||||||
BatchChangeDelay time.Duration
|
BatchChangeDelay time.Duration
|
||||||
NodeMapSessionBufferedChanSize int
|
NodeMapSessionBufferedChanSize int
|
||||||
BatcherWorkers int
|
BatcherWorkers int
|
||||||
|
RegisterCacheCleanup time.Duration
|
||||||
|
RegisterCacheExpiration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func validatePKCEMethod(method string) error {
|
func validatePKCEMethod(method string) error {
|
||||||
@ -1000,6 +1002,8 @@ func LoadServerConfig() (*Config, error) {
|
|||||||
}
|
}
|
||||||
return DefaultBatcherWorkers()
|
return DefaultBatcherWorkers()
|
||||||
}(),
|
}(),
|
||||||
|
RegisterCacheCleanup: viper.GetDuration("tuning.register_cache_cleanup"),
|
||||||
|
RegisterCacheExpiration: viper.GetDuration("tuning.register_cache_expiration"),
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user