mirror of
https://github.com/gravitl/netmaker.git
synced 2026-04-22 16:07:11 +08:00
fix(go): skip fatal log on clickhouse conn;
This commit is contained in:
@@ -81,6 +81,10 @@ func Middleware(next http.Handler) http.Handler {
|
||||
//
|
||||
// Returns the connection and an error if one does not exist.
|
||||
func FromContext(ctx context.Context) (clickhouse.Conn, error) {
|
||||
if ch == nil {
|
||||
return nil, ErrConnNotFound
|
||||
}
|
||||
|
||||
ch, ok := ctx.Value(clickhouseCtxKey).(clickhouse.Conn)
|
||||
if !ok {
|
||||
return nil, ErrConnNotFound
|
||||
|
||||
@@ -93,6 +93,13 @@ func handleListFlows(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
conn, err := ch.FromContext(r.Context())
|
||||
if err != nil {
|
||||
logic.ReturnErrorResponse(w, r,
|
||||
logic.FormatError(fmt.Errorf("clickhouse connection not available: %v", err), logic.Internal))
|
||||
return
|
||||
}
|
||||
|
||||
q := r.URL.Query()
|
||||
|
||||
// TODO: handle query filters better
|
||||
@@ -227,12 +234,6 @@ func handleListFlows(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
args = append(args, perPage, offset)
|
||||
|
||||
conn, err := ch.FromContext(r.Context())
|
||||
if err != nil {
|
||||
logic.ReturnErrorResponse(w, r,
|
||||
logic.FormatError(fmt.Errorf("clickhouse connection not available: %v", err), logic.Internal))
|
||||
return
|
||||
}
|
||||
rows, err := conn.Query(r.Context(), query, args...)
|
||||
if err != nil {
|
||||
logic.ReturnErrorResponse(w, r,
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ func InitPro() {
|
||||
if proLogic.GetFeatureFlags().EnableFlowLogs && logic.GetServerSettings().EnableFlowLogs {
|
||||
err := ch.Initialize()
|
||||
if err != nil {
|
||||
logger.FatalLog("error connecting to clickhouse:", err.Error())
|
||||
logger.Log(0, "error connecting to clickhouse:", err.Error())
|
||||
}
|
||||
|
||||
proLogic.StartFlowCleanupLoop()
|
||||
|
||||
Reference in New Issue
Block a user