mirror of
https://github.com/gravitl/netmaker.git
synced 2025-12-24 13:28:22 +08:00
fix: allow upsert flow logs settings to work only if clickhouse connects;
This commit is contained in:
@@ -11,9 +11,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
ch "github.com/gravitl/netmaker/clickhouse"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
ch "github.com/gravitl/netmaker/clickhouse"
|
||||
"golang.org/x/exp/slog"
|
||||
|
||||
"github.com/gravitl/netmaker/database"
|
||||
@@ -248,8 +247,29 @@ func updateSettings(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if currSettings.EnableFlowLogs != req.EnableFlowLogs {
|
||||
if req.EnableFlowLogs {
|
||||
err := ch.Initialize()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to enable flow logs: %v", err)
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, logic.Internal))
|
||||
return
|
||||
}
|
||||
logic.StartFlowCleanupLoop()
|
||||
} else {
|
||||
logic.StopFlowCleanupLoop()
|
||||
ch.Close()
|
||||
}
|
||||
|
||||
_ = mq.PublishExporterFeatureFlags()
|
||||
}
|
||||
|
||||
err := logic.UpsertServerSettings(req)
|
||||
if err != nil {
|
||||
if req.EnableFlowLogs {
|
||||
logic.StopFlowCleanupLoop()
|
||||
ch.Close()
|
||||
}
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("failed to update server settings "+err.Error()), "internal"))
|
||||
return
|
||||
}
|
||||
@@ -288,18 +308,6 @@ func reInit(curr, new models.ServerSettings, force bool) {
|
||||
logic.GetMetricsMonitor().Start()
|
||||
}
|
||||
|
||||
if curr.EnableFlowLogs != new.EnableFlowLogs {
|
||||
if new.EnableFlowLogs {
|
||||
_ = ch.Initialize()
|
||||
logic.StartFlowCleanupLoop()
|
||||
} else {
|
||||
logic.StopFlowCleanupLoop()
|
||||
ch.Close()
|
||||
}
|
||||
|
||||
_ = mq.PublishExporterFeatureFlags()
|
||||
}
|
||||
|
||||
// On force AutoUpdate change, change AutoUpdate for all hosts.
|
||||
// On force FlowLogs enable, enable FlowLogs for all hosts.
|
||||
// On FlowLogs disable, forced or not, disable FlowLogs for all hosts.
|
||||
|
||||
Reference in New Issue
Block a user