-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AD-105: add frequency of ci-fail issues (#119)
AD-105
- Loading branch information
Showing
55 changed files
with
5,330 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package v1alpha1 | ||
|
||
type Failure struct { | ||
JiraKey string `json:"jira_key"` | ||
JiraStatus string `json:"jira_status"` | ||
ErrorMessage string `json:"error_message"` | ||
Frequency float64 `json:"frequency"` | ||
} | ||
|
||
type Failures []Failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package server | ||
|
||
import ( | ||
failureV1Alpha1 "github.com/redhat-appstudio/quality-studio/api/apis/failure/v1alpha1" | ||
) | ||
|
||
func (s *Server) UpdateFailuresByTeam() { | ||
teamArr, _ := s.cfg.Storage.GetAllTeamsFromDB() | ||
|
||
for _, team := range teamArr { | ||
failures, _ := s.cfg.Storage.GetAllFailures(team) | ||
|
||
for _, failure := range failures { | ||
jiraStatus, err := s.cfg.Storage.GetJiraStatus(failure.JiraKey) | ||
if err != nil { | ||
s.cfg.Logger.Sugar().Warnf("Failed to get jira status:", err) | ||
} | ||
|
||
err = s.cfg.Storage.CreateFailure(failureV1Alpha1.Failure{ | ||
JiraKey: failure.JiraKey, | ||
JiraStatus: jiraStatus, | ||
ErrorMessage: failure.ErrorMessage, | ||
}, team.ID) | ||
if err != nil { | ||
s.cfg.Logger.Sugar().Warnf("Failed to update failures:", err) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package failure | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
|
||
failureV1Alpha1 "github.com/redhat-appstudio/quality-studio/api/apis/failure/v1alpha1" | ||
"github.com/redhat-appstudio/quality-studio/api/types" | ||
"github.com/redhat-appstudio/quality-studio/pkg/utils/httputils" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func (f *failureRouter) createFailure(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { | ||
var fr FailureRequest | ||
if err := json.NewDecoder(r.Body).Decode(&fr); err != nil { | ||
return httputils.WriteJSON(w, http.StatusInternalServerError, &types.ErrorResponse{ | ||
Message: "Error reading team/error_message/jira_key value from body", | ||
StatusCode: http.StatusBadRequest, | ||
}) | ||
} | ||
|
||
team, err := f.Storage.GetTeamByName(fr.Team) | ||
if err != nil { | ||
f.Logger.Error("Failed to fetch team. Make sure the team exists", zap.String("team", fr.Team), zap.Error(err)) | ||
|
||
return httputils.WriteJSON(w, http.StatusInternalServerError, &types.ErrorResponse{ | ||
Message: err.Error(), | ||
StatusCode: http.StatusBadRequest, | ||
}) | ||
} | ||
|
||
jiraStatus, err := f.Storage.GetJiraStatus(fr.JiraKey) | ||
if err != nil { | ||
f.Logger.Sugar().Warnf("Failed to get jira status:", err) | ||
} | ||
|
||
err = f.Storage.CreateFailure(failureV1Alpha1.Failure{ | ||
JiraKey: fr.JiraKey, | ||
JiraStatus: jiraStatus, | ||
ErrorMessage: fr.ErrorMessage, | ||
}, team.ID) | ||
if err != nil { | ||
return httputils.WriteJSON(w, http.StatusInternalServerError, &types.ErrorResponse{ | ||
Message: "Failed to save failure data in database.", | ||
StatusCode: http.StatusBadRequest, | ||
}) | ||
} | ||
|
||
return httputils.WriteJSON(w, http.StatusOK, types.SuccessResponse{ | ||
Message: "Successfully created failure in quality-studio", | ||
StatusCode: http.StatusCreated, | ||
}) | ||
} | ||
|
||
func (f *failureRouter) getFailures(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { | ||
teamName := r.URL.Query()["team_name"] | ||
startDate := r.URL.Query()["start_date"] | ||
endDate := r.URL.Query()["end_date"] | ||
|
||
if len(teamName) == 0 { | ||
return httputils.WriteJSON(w, http.StatusBadRequest, types.ErrorResponse{ | ||
Message: "team_name value not present in query", | ||
StatusCode: 400, | ||
}) | ||
} else if len(startDate) == 0 { | ||
return httputils.WriteJSON(w, http.StatusBadRequest, types.ErrorResponse{ | ||
Message: "start_date value not present in query", | ||
StatusCode: 400, | ||
}) | ||
} else if len(endDate) == 0 { | ||
return httputils.WriteJSON(w, http.StatusBadRequest, types.ErrorResponse{ | ||
Message: "end_date value not present in query", | ||
StatusCode: 400, | ||
}) | ||
} | ||
|
||
team, err := f.Storage.GetTeamByName(teamName[0]) | ||
if err != nil { | ||
f.Logger.Error("Failed to get team") | ||
|
||
return httputils.WriteJSON(w, http.StatusInternalServerError, &types.ErrorResponse{ | ||
Message: err.Error(), | ||
StatusCode: http.StatusBadRequest, | ||
}) | ||
} | ||
|
||
failures, err := f.Storage.GetFailuresByDate(team, startDate[0], endDate[0]) | ||
if err != nil { | ||
return httputils.WriteJSON(w, http.StatusBadRequest, types.ErrorResponse{ | ||
Message: "Failed to get failures by team.", | ||
StatusCode: 400, | ||
}) | ||
} | ||
|
||
return httputils.WriteJSON(w, http.StatusOK, failures) | ||
} | ||
|
||
func (f *failureRouter) deleteFailure(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { | ||
var fr FailureRequest | ||
if err := json.NewDecoder(r.Body).Decode(&fr); err != nil { | ||
return httputils.WriteJSON(w, http.StatusInternalServerError, &types.ErrorResponse{ | ||
Message: "Error reading team/error_message/jira_key value from body", | ||
StatusCode: http.StatusBadRequest, | ||
}) | ||
} | ||
|
||
err := f.Storage.DeleteFailure(fr.JiraKey) | ||
if err != nil { | ||
return httputils.WriteJSON(w, http.StatusBadRequest, types.ErrorResponse{ | ||
Message: "Failed to delete failure", | ||
StatusCode: 400, | ||
}) | ||
} | ||
|
||
return httputils.WriteJSON(w, http.StatusOK, types.SuccessResponse{ | ||
Message: "Failure deleted", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package failure | ||
|
||
import ( | ||
"github.com/redhat-appstudio/quality-studio/api/server/router" | ||
"github.com/redhat-appstudio/quality-studio/pkg/logger" | ||
"github.com/redhat-appstudio/quality-studio/pkg/storage" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// failureRouter provides information about the server version. | ||
type failureRouter struct { | ||
Route []router.Route | ||
Storage storage.Storage | ||
Logger *zap.Logger | ||
} | ||
|
||
// NewRouter initializes a new system router | ||
func NewRouter(s storage.Storage) router.Router { | ||
logger, _ := logger.InitZap("info") | ||
r := &failureRouter{} | ||
|
||
r.Storage = s | ||
r.Logger = logger | ||
|
||
r.Route = []router.Route{ | ||
router.NewPostRoute("/failures/create", r.createFailure), | ||
router.NewGetRoute("/failures/get", r.getFailures), | ||
router.NewDeleteRoute("/failures/delete", r.deleteFailure), | ||
} | ||
|
||
return r | ||
} | ||
|
||
// Routes returns all the API routes dedicated to the server system | ||
func (s *failureRouter) Routes() []router.Route { | ||
return s.Route | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package failure | ||
|
||
type FailureRequest struct { | ||
Team string `json:"team"` | ||
ErrorMessage string `json:"error_message"` | ||
JiraKey string `json:"jira_key"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.