Skip to content

Commit

Permalink
Merge pull request #146 from openinfradev/tks-issues-858
Browse files Browse the repository at this point in the history
add Grafana URL to appserving DTO
  • Loading branch information
ktkfree authored Sep 1, 2023
2 parents 6aa387a + cb3f732 commit 8d25148
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
41 changes: 35 additions & 6 deletions internal/usecase/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ type IAppServeAppUsecase interface {
}

type AppServeAppUsecase struct {
repo repository.IAppServeAppRepository
argo argowf.ArgoClient
repo repository.IAppServeAppRepository
organizationRepo repository.IOrganizationRepository
appGroupRepo repository.IAppGroupRepository
argo argowf.ArgoClient
}

func NewAppServeAppUsecase(r repository.Repository, argoClient argowf.ArgoClient) IAppServeAppUsecase {
return &AppServeAppUsecase{
repo: r.AppServeApp,
argo: argoClient,
repo: r.AppServeApp,
organizationRepo: r.Organization,
appGroupRepo: r.AppGroup,
argo: argoClient,
}
}

Expand Down Expand Up @@ -183,12 +187,37 @@ func (u *AppServeAppUsecase) GetAppServeApps(organizationId string, showAll bool
}

func (u *AppServeAppUsecase) GetAppServeAppById(appId string) (*domain.AppServeApp, error) {
app, err := u.repo.GetAppServeAppById(appId)
asa, err := u.repo.GetAppServeAppById(appId)
if err != nil {
return nil, err
}

return app, nil
/************************
* Construct grafana URL *
************************/
organization, err := u.organizationRepo.Get(asa.OrganizationId)
if err != nil {
return asa, httpErrors.NewInternalServerError(errors.Wrap(err, fmt.Sprintf("Failed to get organization for app %s", asa.Name)), "S_FAILED_FETCH_ORGANIZATION", "")
}

appGroupsInPrimaryCluster, err := u.appGroupRepo.Fetch(domain.ClusterId(organization.PrimaryClusterId), nil)
if err != nil {
return asa, err
}

for _, appGroup := range appGroupsInPrimaryCluster {
if appGroup.AppGroupType == domain.AppGroupType_LMA {
applications, err := u.appGroupRepo.GetApplications(appGroup.ID, domain.ApplicationType_GRAFANA)
if err != nil {
return asa, err
}
if len(applications) > 0 {
asa.GrafanaUrl = applications[0].Endpoint + "/d/tks_appserving_dashboard/tks-appserving-dashboard?refresh=30s&var-cluster=" + asa.TargetClusterId + "&var-kubernetes_namespace_name=" + asa.Namespace + "&var-kubernetes_pod_name=All&var-kubernetes_container_name=main&var-TopK=10"
}
}
}

return asa, nil
}

func (u *AppServeAppUsecase) GetAppServeAppLatestTask(appId string) (*domain.AppServeAppTask, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/usecase/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (u *StackUsecase) Get(ctx context.Context, stackId domain.StackId) (out dom

organization, err := u.organizationRepo.Get(cluster.OrganizationId)
if err != nil {
return out, httpErrors.NewInternalServerError(errors.Wrap(err, fmt.Sprintf("Failed to get organization for clusterId %s", cluster.OrganizationId)), "S_FAILED_FETCH_ORGANIZATION", "")
return out, httpErrors.NewInternalServerError(errors.Wrap(err, fmt.Sprintf("Failed to get organization for clusterId %s", domain.ClusterId(stackId))), "S_FAILED_FETCH_ORGANIZATION", "")
}

appGroups, err := u.appGroupRepo.Fetch(domain.ClusterId(stackId), nil)
Expand Down
1 change: 1 addition & 0 deletions pkg/domain/app-serve-app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type AppServeApp struct {
TargetClusterId string `json:"targetClusterId,omitempty"` // target cluster to which the app is deployed
TargetClusterName string `gorm:"-:all" json:"targetClusterName,omitempty"` // target cluster name
Status string `gorm:"index" json:"status,omitempty"` // status is status of deployed app
GrafanaUrl string `json:"grafanaUrl,omitempty"` // grafana dashboard URL for deployed app
CreatedAt time.Time `gorm:"autoCreateTime:false" json:"createdAt" `
UpdatedAt *time.Time `gorm:"autoUpdateTime:false" json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt"`
Expand Down

0 comments on commit 8d25148

Please sign in to comment.