remove down at start if crowdsec unavailable (#93)

*  remove down at start if crowdsec unavailable

* 🚨 fix lint
This commit is contained in:
maxlerebourg
2023-03-12 20:49:00 +01:00
committed by GitHub
parent 39fcc38980
commit 1fcd4f4e2f
3 changed files with 15 additions and 10 deletions

View File

@@ -30,4 +30,6 @@ Steps to reproduce the behavior:
3. Scroll down to '....'
4. See error
<!---
If you like the plugin, please consider starring it, so you can get updates and we get some more visibility ✨
-->

View File

@@ -16,4 +16,6 @@ A clear and concise description of what you want to happen.
**Additional context**
Add any other context or screenshots about the feature request here.
<!---
If you like the plugin, please consider starring it, so you can get updates and we get some more visibility ✨
-->

View File

@@ -144,7 +144,6 @@ func New(ctx context.Context, next http.Handler, config *configuration.Config, n
config.RedisCachePassword, _ = configuration.GetVariable(config, "RedisCachePassword")
bouncer.cacheClient.New(config.RedisCacheEnabled, config.RedisCacheHost, config.RedisCachePassword)
//nolint:nestif
if (config.CrowdsecMode == configuration.StreamMode || config.CrowdsecMode == configuration.AloneMode) && ticker == nil {
if config.CrowdsecMode == configuration.AloneMode {
if err := getToken(bouncer); err != nil {
@@ -152,17 +151,10 @@ func New(ctx context.Context, next http.Handler, config *configuration.Config, n
return nil, err
}
}
if err := handleStreamCache(bouncer); err != nil {
return nil, err
}
handleStreamTicker(bouncer)
isStartup = false
ticker = startTicker(config, func() {
if err := handleStreamCache(bouncer); err != nil {
isCrowdsecStreamHealthy = false
logger.Error(err.Error())
} else {
isCrowdsecStreamHealthy = true
}
handleStreamTicker(bouncer)
})
}
logger.Debug(fmt.Sprintf("New initialized mode:%s", config.CrowdsecMode))
@@ -269,6 +261,15 @@ type Login struct {
Expire string `json:"expire"`
}
func handleStreamTicker(bouncer *Bouncer) {
if err := handleStreamCache(bouncer); err != nil {
isCrowdsecStreamHealthy = false
logger.Error(err.Error())
} else {
isCrowdsecStreamHealthy = true
}
}
func startTicker(config *configuration.Config, work func()) chan bool {
ticker := time.NewTicker(time.Duration(config.UpdateIntervalSeconds) * time.Second)
stop := make(chan bool, 1)