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

add Grafana URL to appserving DTO #146

Merged
merged 4 commits into from
Sep 1, 2023
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
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