Skip to content

Commit f1e6829

Browse files
feat: Showing app status on app listing page (#2799)
* wip * rest-handler commit * constructors added * test commit * minor design change and resthandler dev * getting app_name and env_name in repo layer for rbac optimisation * rabc checks moved to service layer for optimisation * rbac checks in batch * getting env_identifier instead of env name * delete and update methods completed in repo layer * updating app-status for applisting and cdhandler hook points * updating app-status for app-store app deployed with gitops * added AppId field in InstalledAppAndEnvDetails struct * added update app status hook in fetch resource tree function * wip * unstable wire * sending app_status for overview page via other env api * fix * added delete with appid and envid api's * deleted active column from db * fix * query fix * query fix * fix * update hook added * fix * fix * wire * wire hyperion * query output error fix * delete api fix * delete api fix for installed apps * open api helm-app struct updated * delete query change * sql up script * port fix * delete hook code updated * unit test skeleton added for repo layer * cleaned unused code * unit tests WIP * unit tests(service layer) done for update api * unit tests(service layer) done for Delete api * fix * mocks * Integration tests WIP * integration tests for update method * integration tests for delete method * integration tests for delete_with_appid method * integration tests for delete_with_envid method * fix * restructuring * renaming script number * minor code restructuring * refactor tests * skip tests stmnts added * added filter support on app_status * script number changed * fix * query fix * wip * storing suspended status as hibernating * app-status filtering for installed apps * update app-status on appStatus_update_topic nats event * updated sql script number * wire * port fix * fix * code review changes * sql down script * removed code duplication * improved logging * code review changes * optimised query * query fix * removed commented code * changed error log to warn log * updated sql script number
1 parent 378abc6 commit f1e6829

33 files changed

+1234
-86
lines changed

Wire.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import (
6262
"github.com/devtron-labs/devtron/client/telemetry"
6363
"github.com/devtron-labs/devtron/internal/sql/repository"
6464
app2 "github.com/devtron-labs/devtron/internal/sql/repository/app"
65+
appStatusRepo "github.com/devtron-labs/devtron/internal/sql/repository/appStatus"
6566
appWorkflow2 "github.com/devtron-labs/devtron/internal/sql/repository/appWorkflow"
6667
"github.com/devtron-labs/devtron/internal/sql/repository/bulkUpdate"
6768
"github.com/devtron-labs/devtron/internal/sql/repository/chartConfig"
@@ -74,6 +75,7 @@ import (
7475
"github.com/devtron-labs/devtron/pkg/app"
7576
"github.com/devtron-labs/devtron/pkg/appClone"
7677
"github.com/devtron-labs/devtron/pkg/appClone/batch"
78+
"github.com/devtron-labs/devtron/pkg/appStatus"
7779
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
7880
appStoreDeploymentFullMode "github.com/devtron-labs/devtron/pkg/appStore/deployment/fullMode"
7981
repository4 "github.com/devtron-labs/devtron/pkg/appStore/deployment/repository"
@@ -751,6 +753,13 @@ func InitializeApp() (*App, error) {
751753
cron.NewCdApplicationStatusUpdateHandlerImpl,
752754
wire.Bind(new(cron.CdApplicationStatusUpdateHandler), new(*cron.CdApplicationStatusUpdateHandlerImpl)),
753755

756+
//app_status
757+
appStatusRepo.NewAppStatusRepositoryImpl,
758+
wire.Bind(new(appStatusRepo.AppStatusRepository), new(*appStatusRepo.AppStatusRepositoryImpl)),
759+
appStatus.NewAppStatusServiceImpl,
760+
wire.Bind(new(appStatus.AppStatusService), new(*appStatus.AppStatusServiceImpl)),
761+
//app_status ends
762+
754763
cron.GetCiWorkflowStatusUpdateConfig,
755764
cron.NewCiStatusUpdateCronImpl,
756765
wire.Bind(new(cron.CiStatusUpdateCron), new(*cron.CiStatusUpdateCronImpl)),

api/appStore/InstalledAppRestHandler.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ func (handler InstalledAppRestHandlerImpl) GetAllInstalledApp(w http.ResponseWri
143143
}
144144
}
145145
}
146+
147+
var appStatuses []string
148+
appStatusesStr := v.Get("appStatuses")
149+
if len(appStatusesStr) > 0 {
150+
appStatuses = strings.Split(appStatusesStr, ",")
151+
}
146152
appStoreName := v.Get("appStoreName")
147153
appName := v.Get("appName")
148154
offset := 0
@@ -155,7 +161,15 @@ func (handler InstalledAppRestHandlerImpl) GetAllInstalledApp(w http.ResponseWri
155161
if len(sizeStr) > 0 {
156162
size, _ = strconv.Atoi(sizeStr)
157163
}
158-
filter := &appStoreBean.AppStoreFilter{OnlyDeprecated: onlyDeprecated, ChartRepoId: chartRepoIds, AppStoreName: appStoreName, EnvIds: envIds, AppName: appName, ClusterIds: clusterIds}
164+
filter := &appStoreBean.AppStoreFilter{
165+
OnlyDeprecated: onlyDeprecated,
166+
ChartRepoId: chartRepoIds,
167+
AppStoreName: appStoreName,
168+
EnvIds: envIds,
169+
AppName: appName,
170+
ClusterIds: clusterIds,
171+
AppStatuses: appStatuses,
172+
}
159173
if size > 0 {
160174
filter.Size = size
161175
filter.Offset = offset

api/bean/AppView.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type AppEnvironmentContainer struct {
6262
DeploymentCounter int `json:"deploymentCounter,omitempty"`
6363
InstanceCounter int `json:"instanceCounter,omitempty"`
6464
Status string `json:"status"`
65+
AppStatus string `json:"appStatus"`
6566
CdStageStatus *string `json:"cdStageStatus"`
6667
PreStageStatus *string `json:"preStageStatus"`
6768
PostStageStatus *string `json:"postStageStatus"`
@@ -123,6 +124,7 @@ type AppDetailContainer struct {
123124
}
124125

125126
type Environment struct {
127+
AppStatus string `json:"appStatus"` //this is not the status of environment , this make sense with a specific app only
126128
EnvironmentId int `json:"environmentId"`
127129
EnvironmentName string `json:"environmentName"`
128130
AppMetrics *bool `json:"appMetrics"`

api/helm-app/openapiClient/model_helm_app.go

Lines changed: 46 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/restHandler/AppListingRestHandler.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
3434
"github.com/devtron-labs/devtron/internal/util"
3535
"github.com/devtron-labs/devtron/pkg/app"
36+
"github.com/devtron-labs/devtron/pkg/appStatus"
3637
service1 "github.com/devtron-labs/devtron/pkg/appStore/deployment/service"
3738
"github.com/devtron-labs/devtron/pkg/cluster"
3839
"github.com/devtron-labs/devtron/pkg/deploymentGroup"
@@ -85,6 +86,7 @@ type AppListingRestHandlerImpl struct {
8586
installedAppService service1.InstalledAppService
8687
cdApplicationStatusUpdateHandler cron.CdApplicationStatusUpdateHandler
8788
pipelineRepository pipelineConfig.PipelineRepository
89+
appStatusService appStatus.AppStatusService
8890
}
8991

9092
type AppStatus struct {
@@ -105,7 +107,8 @@ func NewAppListingRestHandlerImpl(application application.ServiceClient,
105107
helmAppClient client.HelmAppClient, clusterService cluster.ClusterService, helmAppService client.HelmAppService,
106108
argoUserService argo.ArgoUserService, k8sApplicationService k8s.K8sApplicationService, installedAppService service1.InstalledAppService,
107109
cdApplicationStatusUpdateHandler cron.CdApplicationStatusUpdateHandler,
108-
pipelineRepository pipelineConfig.PipelineRepository) *AppListingRestHandlerImpl {
110+
pipelineRepository pipelineConfig.PipelineRepository,
111+
appStatusService appStatus.AppStatusService) *AppListingRestHandlerImpl {
109112
appListingHandler := &AppListingRestHandlerImpl{
110113
application: application,
111114
appListingService: appListingService,
@@ -124,6 +127,7 @@ func NewAppListingRestHandlerImpl(application application.ServiceClient,
124127
installedAppService: installedAppService,
125128
cdApplicationStatusUpdateHandler: cdApplicationStatusUpdateHandler,
126129
pipelineRepository: pipelineRepository,
130+
appStatusService: appStatusService,
127131
}
128132
return appListingHandler
129133
}
@@ -806,6 +810,12 @@ func (handler AppListingRestHandlerImpl) fetchResourceTree(w http.ResponseWriter
806810
handler.logger.Errorw("error in syncing pipeline status", "err", err)
807811
}
808812
}
813+
//updating app_status table here
814+
err = handler.appStatusService.UpdateStatusWithAppIdEnvId(appDetail.AppId, appDetail.EnvironmentId, resp.Status)
815+
if err != nil {
816+
handler.logger.Warnw("error in updating app status", "err", err, "appId", appDetail.AppId, "envId", appDetail.EnvironmentId)
817+
}
818+
809819
} else if len(appDetail.AppName) > 0 && len(appDetail.EnvironmentName) > 0 && util.IsHelmApp(appDetail.DeploymentAppType) {
810820
config, err := handler.helmAppService.GetClusterConf(appDetail.ClusterId)
811821
if err != nil {

client/argocdServer/application/Application.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ func (c ServiceClientImpl) Create(ctxt context.Context, query *application.Appli
366366
}
367367

368368
func (c ServiceClientImpl) ResourceTree(ctxt context.Context, query *application.ResourcesQuery) (*ResourceTreeResponse, error) {
369+
//all the apps deployed via argo are fetching status from here
369370
ctx, cancel := context.WithTimeout(ctxt, TimeoutSlow)
370371
defer cancel()
371372
token, ok := ctxt.Value("token").(string)

cmd/external-app/wire.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/devtron-labs/devtron/client/telemetry"
3030
"github.com/devtron-labs/devtron/internal/sql/repository"
3131
app2 "github.com/devtron-labs/devtron/internal/sql/repository/app"
32+
"github.com/devtron-labs/devtron/internal/sql/repository/appStatus"
3233
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
3334
"github.com/devtron-labs/devtron/internal/util"
3435
"github.com/devtron-labs/devtron/pkg/app"
@@ -83,6 +84,10 @@ func InitializeApp() (*App, error) {
8384
telemetry.NewPosthogClient,
8485
delete2.NewDeleteServiceImpl,
8586

87+
//appStatus
88+
appStatus.NewAppStatusRepositoryImpl,
89+
wire.Bind(new(appStatus.AppStatusRepository), new(*appStatus.AppStatusRepositoryImpl)),
90+
//appStatus ends
8691
rbac.NewEnforcerUtilImpl,
8792
wire.Bind(new(rbac.EnforcerUtil), new(*rbac.EnforcerUtilImpl)),
8893

cmd/external-app/wire_gen.go

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/sql/repository/AppListingRepository.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,14 @@ func (impl AppListingRepositoryImpl) FetchOtherEnvironment(appId int) ([]*bean.E
446446
impl.Logger.Debug("reached at FetchOtherEnvironment:")
447447

448448
// other environment tab
449+
//TODO : create new optimised query and need to use explain analyse for both queries
449450
var otherEnvironments []*bean.Environment
450-
query := "SELECT p.environment_id,env.environment_name, p.last_deployed, env_app_m.app_metrics, env.default as prod, env_app_m.infra_metrics from" +
451-
" (SELECT pl.id,pl.app_id,pl.environment_id,pl.deleted,MAX(pco.created_on) as last_deployed from pipeline pl LEFT JOIN pipeline_config_override pco on pco.pipeline_id = pl.id WHERE pl.app_id=? and pl.deleted = FALSE GROUP BY pl.id) p" +
452-
" INNER JOIN environment env on env.id=p.environment_id" +
453-
" LEFT JOIN env_level_app_metrics env_app_m on env.id=env_app_m.env_id and p.app_id = env_app_m.app_id" +
454-
" where p.app_id=? and p.deleted = FALSE AND env.active = TRUE GROUP BY 1,2,3,4,5,6"
451+
query := "select OE.*,B.status as app_status " +
452+
"FROM " +
453+
"(SELECT p.environment_id,env.environment_name, p.last_deployed, env_app_m.app_metrics, env.default as prod, env_app_m.infra_metrics from ( SELECT pl.id,pl.app_id,pl.environment_id,pl.deleted,MAX(pco.created_on) as last_deployed from pipeline pl LEFT JOIN pipeline_config_override pco on pco.pipeline_id = pl.id WHERE pl.app_id = ? and pl.deleted = FALSE GROUP BY pl.id) p INNER JOIN environment env on env.id=p.environment_id LEFT JOIN env_level_app_metrics env_app_m on env.id=env_app_m.env_id and p.app_id = env_app_m.app_id where p.app_id=? and p.deleted = FALSE AND env.active = TRUE GROUP BY 1,2,3,4,5,6) OE " +
454+
" LEFT JOIN app_status B ON OE.environment_id = B.env_id AND B.app_id = ? ;"
455455
impl.Logger.Debugw("other env query:", query)
456-
_, err := impl.dbConnection.Query(&otherEnvironments, query, appId, appId)
456+
_, err := impl.dbConnection.Query(&otherEnvironments, query, appId, appId, appId)
457457
if err != nil {
458458
impl.Logger.Error("error in fetching other environment", "error", err)
459459
}

internal/sql/repository/app/AppRepository.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type AppRepository interface {
6363
FindIdsByNames(appNames []string) ([]int, error)
6464
FetchAllActiveInstalledAppsWithAppIdAndName() ([]*App, error)
6565
FetchAllActiveDevtronAppsWithAppIdAndName() ([]*App, error)
66+
FindEnvironmentIdForInstalledApp(appId int) (int, error)
6667
}
6768

6869
const DevtronApp = "DevtronApp"
@@ -321,3 +322,14 @@ func (repo AppRepositoryImpl) FetchAllActiveDevtronAppsWithAppIdAndName() ([]*Ap
321322
}
322323
return apps, nil
323324
}
325+
326+
func (repo AppRepositoryImpl) FindEnvironmentIdForInstalledApp(appId int) (int, error) {
327+
type envIdRes struct {
328+
envId int `json:"envId"`
329+
}
330+
res := envIdRes{}
331+
query := "select ia.environment_id " +
332+
"from installed_apps ia where ia.app_id = ?"
333+
_, err := repo.dbConnection.Query(&res, query, appId)
334+
return res.envId, err
335+
}

0 commit comments

Comments
 (0)