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:
Vijay Joshi
2023-11-16 12:03:34 +05:30
committed by GitHub
parent 0c85c3b68d
commit 928a768b82
15 changed files with 636 additions and 0 deletions

View 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))
}

View File

@@ -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)