fix(go): skip fatal log on clickhouse conn;

This commit is contained in:
VishalDalwadi
2026-03-27 15:49:27 +05:30
parent 87849ff443
commit 6ad14093d2
3 changed files with 12 additions and 7 deletions
+4
View File
@@ -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
+7 -6
View File
@@ -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
View File
@@ -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()