Skip to content

Commit abd3b1c

Browse files
committed
app count
1 parent a26a28c commit abd3b1c

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

client/telemetry/TelemetryEventClient.go

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"github.com/devtron-labs/common-lib/utils/k8s"
4242
"github.com/devtron-labs/devtron/internal/sql/repository"
4343
appRepository "github.com/devtron-labs/devtron/internal/sql/repository/app"
44-
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
4544
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
4645
"github.com/devtron-labs/devtron/pkg/auth/sso"
4746
user2 "github.com/devtron-labs/devtron/pkg/auth/user"
@@ -275,7 +274,7 @@ func (impl *TelemetryEventClientImpl) SummaryDetailsForTelemetry() (cluster []be
275274
// New methods for collecting additional telemetry metrics
276275

277276
func (impl *TelemetryEventClientImpl) getHelmAppCount() int {
278-
count, err := impl.installedAppReadService.GetDeploymentSuccessfulStatusCountForTelemetry()
277+
count, err := impl.installedAppReadService.GetActiveInstalledAppCount()
279278
if err != nil {
280279
impl.logger.Errorw("error getting helm app count", "err", err)
281280
return -1
@@ -284,49 +283,21 @@ func (impl *TelemetryEventClientImpl) getHelmAppCount() int {
284283
}
285284

286285
func (impl *TelemetryEventClientImpl) getDevtronAppCount() int {
287-
// Use a simple approach - count all active apps that are not jobs
288-
if impl.appRepository == nil {
289-
impl.logger.Warnw("appRepository not available for devtron app count")
290-
return -1
291-
}
292-
293-
// Get all active apps and filter out jobs
294-
apps, err := impl.appRepository.FindAll()
286+
devtronAppCount, err := impl.appRepository.FindDevtronAppCount()
295287
if err != nil {
296288
impl.logger.Errorw("error getting all apps for devtron app count", "err", err)
297289
return -1
298290
}
299-
300-
devtronAppCount := 0
301-
for _, app := range apps {
302-
if app.AppType != helper.Job && app.Active {
303-
devtronAppCount++
304-
}
305-
}
306-
307291
return devtronAppCount
308292
}
309293

310294
func (impl *TelemetryEventClientImpl) getJobCount() int {
311-
// Use a simple approach - count all active apps that are jobs
312-
if impl.appRepository == nil {
313-
impl.logger.Warnw("appRepository not available for job count")
314-
return -1
315-
}
316-
317-
apps, err := impl.appRepository.FindAll()
295+
jobCount, err := impl.appRepository.FindJobCount()
318296
if err != nil {
319297
impl.logger.Errorw("error getting all apps for job count", "err", err)
320298
return -1
321299
}
322300

323-
jobCount := 0
324-
for _, app := range apps {
325-
if app.AppType == helper.Job && app.Active {
326-
jobCount++
327-
}
328-
}
329-
330301
return jobCount
331302
}
332303

internal/sql/repository/app/AppRepository.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ type AppRepository interface {
9292
FindAppAndProjectByIdsIn(ids []int) ([]*App, error)
9393
FetchAppIdsByDisplayNamesForJobs(names []string) (map[int]string, []int, error)
9494
GetActiveCiCdAppsCount() (int, error)
95+
FindDevtronAppCount() (int, error)
96+
FindJobCount() (int, error)
9597

9698
UpdateAppOfferingModeForAppIds(successAppIds []*int, appOfferingMode string, userId int32) error
9799
}
@@ -520,6 +522,20 @@ func (repo AppRepositoryImpl) GetActiveCiCdAppsCount() (int, error) {
520522
Count()
521523
}
522524

525+
func (repo AppRepositoryImpl) FindDevtronAppCount() (int, error) {
526+
return repo.dbConnection.Model(&App{}).
527+
Where("active=?", true).
528+
Where("app_type=?", helper.CustomApp).
529+
Count()
530+
}
531+
532+
func (repo AppRepositoryImpl) FindJobCount() (int, error) {
533+
return repo.dbConnection.Model(&App{}).
534+
Where("active=?", true).
535+
Where("app_type=?", helper.Job).
536+
Count()
537+
}
538+
523539
func (repo AppRepositoryImpl) UpdateAppOfferingModeForAppIds(successAppIds []*int, appOfferingMode string, userId int32) error {
524540
query := "update app set app_offering_mode = ?,updated_by = ?, updated_on = ? where id in (?);"
525541
var app *App

pkg/appStore/installedApp/read/InstalledAppReadEAService.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type InstalledAppReadServiceEA interface {
3636
GetAllArgoAppNamesByDeploymentAppNames(deploymentAppNames []string) ([]string, error)
3737
// IsChartStoreAppManagedByArgoCd returns if a chart store app is deployed via argo-cd or not
3838
IsChartStoreAppManagedByArgoCd(appId int) (bool, error)
39+
// GetActiveInstalledAppCount returns the count of all active installed apps
40+
GetActiveInstalledAppCount() (int, error)
3941
}
4042

4143
type InstalledAppReadServiceEAImpl struct {
@@ -114,3 +116,12 @@ func (impl *InstalledAppReadServiceEAImpl) IsChartStoreAppManagedByArgoCd(appId
114116
}
115117
return util.IsAcdApp(installedAppModel.DeploymentAppType), nil
116118
}
119+
120+
func (impl *InstalledAppReadServiceEAImpl) GetActiveInstalledAppCount() (int, error) {
121+
count, err := impl.installedAppRepository.GetActiveInstalledAppCount()
122+
if err != nil {
123+
impl.logger.Errorw("error while getting active installed app count", "error", err)
124+
return 0, err
125+
}
126+
return count, nil
127+
}

pkg/appStore/installedApp/repository/InstalledAppRepository.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ type InstalledAppRepository interface {
170170
GetInstalledAppsMinByAppId(appId int) (*InstalledApps, error)
171171
GetAllArgoAppsByDeploymentAppNames(deploymentAppNames []string) ([]string, error)
172172
GetAllAppsByClusterAndDeploymentAppType(clusterIds []int, deploymentAppType string) ([]bean.DeployedInstalledAppInfo, error)
173+
// GetActiveInstalledAppCount returns the count of all active installed apps
174+
GetActiveInstalledAppCount() (int, error)
173175
}
174176

175177
type InstalledAppRepositoryImpl struct {
@@ -1085,3 +1087,14 @@ func (impl *InstalledAppRepositoryImpl) GetAllArgoAppsByDeploymentAppNames(deplo
10851087
Select(&result)
10861088
return result, err
10871089
}
1090+
1091+
func (impl *InstalledAppRepositoryImpl) GetActiveInstalledAppCount() (int, error) {
1092+
var count int
1093+
countQuery := "SELECT COUNT(*) FROM installed_apps WHERE active = true;"
1094+
_, err := impl.dbConnection.Query(&count, countQuery)
1095+
if err != nil {
1096+
impl.Logger.Errorw("error in getting active installed app count", "err", err)
1097+
return 0, err
1098+
}
1099+
return count, nil
1100+
}

0 commit comments

Comments
 (0)