fix: allow upsert flow logs settings to work only if clickhouse connects;

This commit is contained in:
VishalDalwadi
2025-12-17 11:48:04 +05:30
parent 3e3d8c60a0
commit b022fa279d

View File

@@ -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.