TP-48197 : Implementation of RCA Service, repo, handler, validator and webhook for posting RCA to incident channel along with unit tests (#282)
* TP-48197 : Implementation of RCA Service, repo, handler, validator and webhook for posting RCA to incident channel * Added unit tests * Added migration script" * PR Review Changes * Update migratrion
This commit is contained in:
52
cmd/app/handler/rca_handler.go
Normal file
52
cmd/app/handler/rca_handler.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"houston/logger"
|
||||
"houston/service/rca"
|
||||
request "houston/service/request"
|
||||
common "houston/service/response/common"
|
||||
utils "houston/service/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
rcaLogTag = "[rca_handler]"
|
||||
)
|
||||
|
||||
type RcaHandler struct {
|
||||
gin *gin.Engine
|
||||
service *rca.RcaService
|
||||
}
|
||||
|
||||
func NewRcaHandler(gin *gin.Engine, rcaService *rca.RcaService) *RcaHandler {
|
||||
return &RcaHandler{
|
||||
gin: gin,
|
||||
service: rcaService,
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *RcaHandler) HandlePostRca(c *gin.Context) {
|
||||
var postRcaRequest request.PostRcaRequest
|
||||
if err := c.ShouldBindJSON(&postRcaRequest); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := utils.ValidatePostRcaRequest(postRcaRequest); err != nil {
|
||||
logger.Error(fmt.Sprintf("%s Received invalid request to post Rca", rcaLogTag), zap.Error(err))
|
||||
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
|
||||
return
|
||||
}
|
||||
|
||||
err := handler.service.PostRcaToIncidentChannel(postRcaRequest)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, common.ErrorResponse(err, http.StatusBadRequest, nil))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, common.SuccessResponse("Message posted successfully!", http.StatusOK))
|
||||
}
|
||||
@@ -12,8 +12,11 @@ import (
|
||||
"houston/logger"
|
||||
"houston/model/ingester"
|
||||
"houston/pkg/slackbot"
|
||||
rcaRepository "houston/repository/rca/impl"
|
||||
"houston/service"
|
||||
"houston/service/incident"
|
||||
"houston/service/rca"
|
||||
"houston/service/slack"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -39,6 +42,7 @@ func (s *Server) Handler(houstonGroup *gin.RouterGroup) {
|
||||
s.incidentClientHandler(houstonGroup)
|
||||
s.incidentClientHandlerV2(houstonGroup)
|
||||
s.filtersHandlerV2(houstonGroup)
|
||||
s.rcaHandler(houstonGroup)
|
||||
s.gin.Use(s.createMiddleware())
|
||||
s.teamHandler(houstonGroup)
|
||||
s.severityHandler(houstonGroup)
|
||||
@@ -150,6 +154,16 @@ func (s *Server) logHandler(houstonGroup *gin.RouterGroup) {
|
||||
houstonGroup.GET("/logs/:log_type/:id", logHandler.GetLogs)
|
||||
}
|
||||
|
||||
func (s *Server) rcaHandler(houstonGroup *gin.RouterGroup) {
|
||||
slackService := slack.NewSlackService()
|
||||
incidentServiceV2 := incident.NewIncidentServiceV2(s.db)
|
||||
rcaRepository := rcaRepository.NewRcaRepository(s.db)
|
||||
rcaService := rca.NewRcaService(incidentServiceV2, slackService, rcaRepository)
|
||||
rcaHandler := handler.NewRcaHandler(s.gin, rcaService)
|
||||
|
||||
houstonGroup.POST("/rca", rcaHandler.HandlePostRca)
|
||||
}
|
||||
|
||||
func (s *Server) usersHandler(houstonGroup *gin.RouterGroup) {
|
||||
houstonClient := NewHoustonClient()
|
||||
slackClient := slackbot.NewSlackClient(houstonClient.socketModeClient)
|
||||
|
||||
Reference in New Issue
Block a user