This commit is contained in:
+24
-24
@@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/HellreigN/backend/docs"
|
||||
"gitea.d3m0k1d.ru/d3m0k1d/HellreigN/backend/internal/config"
|
||||
@@ -59,25 +60,25 @@ func main() {
|
||||
}
|
||||
|
||||
// Initialize ClickHouse and log repository
|
||||
var logRepo *repository.LogRepository
|
||||
logRepo := repository.NewLogRepository()
|
||||
if cfg.Database.Clickhouse_host != "" {
|
||||
chConn, err := storage.OpenClickHouse(storage.ClickHouseConfig{
|
||||
Host: cfg.Database.Clickhouse_host,
|
||||
User: cfg.Database.Clickhouse_user,
|
||||
Password: cfg.Database.Clickhouse_password,
|
||||
Database: cfg.Database.Clickhouse_database,
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Warning: ClickHouse connection failed: %v", err)
|
||||
} else {
|
||||
logRepo = repository.NewLogRepository(chConn)
|
||||
go func() {
|
||||
db, err := storage.OpenClickHouseWithRetry(storage.ClickHouseConfig{
|
||||
Host: cfg.Database.Clickhouse_host,
|
||||
User: cfg.Database.Clickhouse_user,
|
||||
Password: cfg.Database.Clickhouse_password,
|
||||
Database: cfg.Database.Clickhouse_database,
|
||||
}, 10, 5*time.Second)
|
||||
if err != nil {
|
||||
log.Printf("Warning: ClickHouse connection failed: %v", err)
|
||||
return
|
||||
}
|
||||
log.Println("ClickHouse connected successfully")
|
||||
logRepo.SetDB(db)
|
||||
if err := logRepo.Init(context.Background()); err != nil {
|
||||
log.Printf("Warning: Failed to initialize logs table: %v", err)
|
||||
} else {
|
||||
log.Println("ClickHouse connected successfully")
|
||||
}
|
||||
defer chConn.Close()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Initialize Collector gRPC service
|
||||
@@ -183,15 +184,14 @@ func main() {
|
||||
mockLogHandlers := handlers.NewLogHandlers(nil)
|
||||
logsGroup.GET("/mock", mockLogHandlers.GetMockLogs)
|
||||
|
||||
if logRepo != nil {
|
||||
logHandlers := handlers.NewLogHandlers(logRepo)
|
||||
logsGroup.POST("", logHandlers.Insert)
|
||||
logsGroup.POST("/batch", logHandlers.InsertBatch)
|
||||
logsGroup.GET("", logHandlers.Search)
|
||||
logsGroup.GET("/services", logHandlers.GetServices)
|
||||
logsGroup.GET("/agents", logHandlers.GetAgents)
|
||||
logsGroup.GET("/levels", logHandlers.GetLevels)
|
||||
}
|
||||
// ClickHouse log handlers (always registered, work when ClickHouse connects)
|
||||
logHandlers := handlers.NewLogHandlers(logRepo)
|
||||
logsGroup.POST("", logHandlers.Insert)
|
||||
logsGroup.POST("/batch", logHandlers.InsertBatch)
|
||||
logsGroup.GET("", logHandlers.Search)
|
||||
logsGroup.GET("/services", logHandlers.GetServices)
|
||||
logsGroup.GET("/agents", logHandlers.GetAgents)
|
||||
logsGroup.GET("/levels", logHandlers.GetLevels)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user