feat: Implement Log Query API Endpoints (Issue #13)

- Create LogsHandler with all log query endpoints
- Implement QueryLogs for LogsQL queries
- Implement StatsQuery for time-series statistics
- Implement GetFacets for field facets
- Implement TailLogs for real-time streaming (NDJSON)
- Implement ExportLogs with JSON and CSV support
- Wire up logs handler in router
- Add VictoriaLogs client initialization

Closes #13

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Code
2026-02-05 00:57:53 +03:00
parent c9b6c5bf74
commit 392f93be95
2 changed files with 319 additions and 15 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/yourusername/victorialogs-manager/internal/repository"
"github.com/yourusername/victorialogs-manager/internal/services"
"github.com/yourusername/victorialogs-manager/internal/utils"
"github.com/yourusername/victorialogs-manager/pkg/vlogs"
)
// NewRouter creates and configures the main router
@@ -35,13 +36,18 @@ func NewRouter(cfg *config.Config, db *sql.DB) *gin.Engine {
// Initialize repositories
userRepo := repository.NewUserRepository(db)
// Initialize VictoriaLogs client
vlogsClient := vlogs.NewClient(cfg.VictoriaLogs.URL, cfg.VictoriaLogs.Timeout)
// Initialize services
authService := services.NewAuthService(userRepo, jwtManager)
userService := services.NewUserService(userRepo)
logsService := services.NewLogsService(vlogsClient)
// Initialize handlers
authHandler := handlers.NewAuthHandler(authService)
userHandler := handlers.NewUserHandler(userService)
logsHandler := handlers.NewLogsHandler(logsService)
// Health check endpoint
router.GET("/health", func(c *gin.Context) {
@@ -86,21 +92,11 @@ func NewRouter(cfg *config.Config, db *sql.DB) *gin.Engine {
logs := v1.Group("/logs")
logs.Use(middleware.AuthMiddleware(jwtManager))
{
logs.POST("/query", func(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "not implemented yet"})
})
logs.POST("/tail", func(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "not implemented yet"})
})
logs.GET("/facets", func(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "not implemented yet"})
})
logs.POST("/stats", func(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "not implemented yet"})
})
logs.POST("/export", func(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{"message": "not implemented yet"})
})
logs.POST("/query", logsHandler.QueryLogs)
logs.POST("/tail", logsHandler.TailLogs)
logs.POST("/facets", logsHandler.GetFacets)
logs.POST("/stats", logsHandler.StatsQuery)
logs.POST("/export", logsHandler.ExportLogs)
}
// Alert management routes (protected)