Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect user app pod log #495

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6312,6 +6312,57 @@ const docTemplate = `{
}
}
},
"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/log": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Get log and pod status of appServeApp",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"AppServeApps"
],
"summary": "Get log and pod status of appServeApp",
"parameters": [
{
"type": "string",
"description": "Organization ID",
"name": "organizationId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Project ID",
"name": "projectId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "App ID",
"name": "appId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAppServeAppLogResponse"
}
}
}
}
},
"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/rollback": {
"post": {
"security": [
Expand Down Expand Up @@ -12579,6 +12630,17 @@ const docTemplate = `{
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.GetAppServeAppLogResponse": {
"type": "object",
"properties": {
"podLog": {
"type": "string"
},
"podStatus": {
"type": "string"
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.GetAppServeAppTaskResponse": {
"type": "object",
"properties": {
Expand Down
62 changes: 62 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6306,6 +6306,57 @@
}
}
},
"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/log": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Get log and pod status of appServeApp",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"AppServeApps"
],
"summary": "Get log and pod status of appServeApp",
"parameters": [
{
"type": "string",
"description": "Organization ID",
"name": "organizationId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Project ID",
"name": "projectId",
"in": "path",
"required": true
},
{
"type": "string",
"description": "App ID",
"name": "appId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAppServeAppLogResponse"
}
}
}
}
},
"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/rollback": {
"post": {
"security": [
Expand Down Expand Up @@ -12573,6 +12624,17 @@
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.GetAppServeAppLogResponse": {
"type": "object",
"properties": {
"podLog": {
"type": "string"
},
"podStatus": {
"type": "string"
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.GetAppServeAppTaskResponse": {
"type": "object",
"properties": {
Expand Down
40 changes: 40 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,13 @@ definitions:
pagination:
$ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.PaginationResponse'
type: object
github_com_openinfradev_tks-api_pkg_domain.GetAppServeAppLogResponse:
properties:
podLog:
type: string
podStatus:
type: string
type: object
github_com_openinfradev_tks-api_pkg_domain.GetAppServeAppTaskResponse:
properties:
appServeApp:
Expand Down Expand Up @@ -8187,6 +8194,39 @@ paths:
summary: Get latest task from appServeApp
tags:
- AppServeApps
/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/log:
get:
consumes:
- application/json
description: Get log and pod status of appServeApp
parameters:
- description: Organization ID
in: path
name: organizationId
required: true
type: string
- description: Project ID
in: path
name: projectId
required: true
type: string
- description: App ID
in: path
name: appId
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAppServeAppLogResponse'
security:
- JWT: []
summary: Get log and pod status of appServeApp
tags:
- AppServeApps
/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/rollback:
post:
consumes:
Expand Down
1 change: 1 addition & 0 deletions internal/delivery/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const (
GetNumOfAppsOnStack // 프로젝트 관리/앱 서빙/조회
GetAppServeApp // 프로젝트 관리/앱 서빙/조회
GetAppServeAppLatestTask // 프로젝트 관리/앱 서빙/조회
GetAppServeAppLog // 프로젝트 관리/앱 서빙/조회
IsAppServeAppExist // 프로젝트 관리/앱 서빙/조회 // 프로젝트 관리/앱 서빙/배포 // 프로젝트 관리/앱 서빙/빌드
IsAppServeAppNameExist // 프로젝트 관리/앱 서빙/조회 // 프로젝트 관리/앱 서빙/배포 // 프로젝트 관리/앱 서빙/빌드
DeleteAppServeApp // 프로젝트 관리/앱 서빙/삭제
Expand Down
66 changes: 66 additions & 0 deletions internal/delivery/http/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,72 @@ func (h *AppServeAppHandler) GetNumOfAppsOnStack(w http.ResponseWriter, r *http.
ResponseJSON(w, r, http.StatusOK, numApps)
}

// GetAppServeAppLog godoc
//
// @Tags AppServeApps
// @Summary Get log and pod status of appServeApp
// @Description Get log and pod status of appServeApp
// @Accept json
// @Produce json
// @Param organizationId path string true "Organization ID"
// @Param projectId path string true "Project ID"
// @Param appId path string true "App ID"
// @Success 200 {object} domain.GetAppServeAppLogResponse
// @Router /organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/log [get]
// @Security JWT
func (h *AppServeAppHandler) GetAppServeAppLog(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

organizationId, ok := vars["organizationId"]
fmt.Printf("organizationId = [%v]\n", organizationId)
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid organizationId"), "", ""))
return
}

projectId, ok := vars["projectId"]
log.Debugf(r.Context(), "projectId = [%v]\n", projectId)
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("Invalid projectId: [%s]", projectId), "C_INVALID_PROJECT_ID", ""))
return
}

appId, ok := vars["appId"]
fmt.Printf("appId = [%s]\n", appId)
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid appId"), "", ""))
return
}

// Check if projectId exists
prj, err := h.prjUsecase.GetProject(r.Context(), organizationId, projectId)
if err != nil {
ErrorJSON(w, r, httpErrors.NewInternalServerError(fmt.Errorf("Error while checking project record: %s", err), "", ""))
return
} else if prj == nil {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("projectId not found: %s", projectId), "C_INVALID_PROJECT_ID", ""))
}

podLog, podStatus, err := h.usecase.GetAppServeAppLog(r.Context(), appId)
if err != nil {
ErrorJSON(w, r, httpErrors.NewInternalServerError(err, "", ""))
return
}

var out domain.GetAppServeAppLogResponse
// if err := serializer.Map(r.Context(), podLog, &out.PodLog); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ktkfree 님~ 이 부분은 구조체가 아닌 string 값을 복사할 때 아래 에러가 발생하여, map 함수 대신 그냥 단순히 대입하도록 하였는데, 혹시 문제가 될까요? 정상 동작하는건 확인하였습니다.
reflect: call of reflect.Value.NumField on string Value

// log.Info(r.Context(), err)
// }
out.PodLog = podLog

// if err := serializer.Map(r.Context(), podStatus, &out.PodStatus); err != nil {
// log.Info(r.Context(), err)
// }
out.PodStatus = podStatus

ResponseJSON(w, r, http.StatusOK, out)
}

// GetAppServeAppTasksByAppId godoc
//
// @Tags AppServeApps
Expand Down
22 changes: 19 additions & 3 deletions internal/repository/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type IAppServeAppRepository interface {
GetAppServeAppTasksByAppId(ctx context.Context, appId string, pg *pagination.Pagination) ([]model.AppServeAppTask, error)
GetAppServeAppTaskById(ctx context.Context, taskId string) (*model.AppServeAppTask, error)
GetAppServeAppLatestTask(ctx context.Context, appId string) (*model.AppServeAppTask, error)
GetClusterIdByAppId(ctx context.Context, appId string) (string, error)

GetNumOfAppsOnStack(ctx context.Context, organizationId string, clusterId string) (int64, error)

Expand Down Expand Up @@ -55,9 +56,9 @@ func (r *AppServeAppRepository) CreateAppServeApp(ctx context.Context, app *mode
// Update creates new appServeApp task for existing appServeApp.
func (r *AppServeAppRepository) CreateTask(ctx context.Context, task *model.AppServeAppTask, appId string) (string, error) {
task.ID = uuid.New().String()
if len(appId) > 0 {
task.AppServeAppId = appId
}
if len(appId) > 0 {
task.AppServeAppId = appId
}
res := r.db.WithContext(ctx).Create(task)
if res.Error != nil {
return "", res.Error
Expand Down Expand Up @@ -174,6 +175,21 @@ func (r *AppServeAppRepository) GetAppServeAppLatestTask(ctx context.Context, ap
return &task, nil
}

func (r *AppServeAppRepository) GetClusterIdByAppId(ctx context.Context, appId string) (string, error) {
var app model.AppServeApp

res := r.db.WithContext(ctx).Where("id = ?", appId).First(&app)
if res.Error != nil {
log.Debug(ctx, res.Error)
return "", res.Error
}
if res.RowsAffected == 0 {
return "", fmt.Errorf("No app with ID %s", appId)
}

return app.TargetClusterId, nil
}

func (r *AppServeAppRepository) GetNumOfAppsOnStack(ctx context.Context, organizationId string, clusterId string) (int64, error) {
var apps []model.AppServeApp

Expand Down
1 change: 1 addition & 0 deletions internal/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/tasks", customMiddleware.Handle(internalApi.GetAppServeAppTasksByAppId, http.HandlerFunc(appServeAppHandler.GetAppServeAppTasksByAppId))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/tasks/{taskId}", customMiddleware.Handle(internalApi.GetAppServeAppTaskDetail, http.HandlerFunc(appServeAppHandler.GetAppServeAppTaskDetail))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/latest-task", customMiddleware.Handle(internalApi.GetAppServeAppLatestTask, http.HandlerFunc(appServeAppHandler.GetAppServeAppLatestTask))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/log", customMiddleware.Handle(internalApi.GetAppServeAppLog, http.HandlerFunc(appServeAppHandler.GetAppServeAppLog))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}/exist", customMiddleware.Handle(internalApi.IsAppServeAppExist, http.HandlerFunc(appServeAppHandler.IsAppServeAppExist))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/name/{name}/existence", customMiddleware.Handle(internalApi.IsAppServeAppNameExist, http.HandlerFunc(appServeAppHandler.IsAppServeAppNameExist))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/app-serve-apps/{appId}", customMiddleware.Handle(internalApi.DeleteAppServeApp, http.HandlerFunc(appServeAppHandler.DeleteAppServeApp))).Methods(http.MethodDelete)
Expand Down
Loading
Loading