diff --git a/client/telemetry/TelemetryEventClientExtended.go b/client/telemetry/TelemetryEventClientExtended.go index d80134097a..24bf093577 100644 --- a/client/telemetry/TelemetryEventClientExtended.go +++ b/client/telemetry/TelemetryEventClientExtended.go @@ -131,8 +131,12 @@ type TelemetryEventDto struct { UserCount int `json:"userCount,omitempty"` EnvironmentCount int `json:"environmentCount,omitempty"` ClusterCount int `json:"clusterCount,omitempty"` - CiCountPerDay int `json:"ciCountPerDay,omitempty"` - CdCountPerDay int `json:"cdCountPerDay,omitempty"` + CiCreatedPerDay int `json:"ciCreatedPerDay"` + CdCreatedPerDay int `json:"cdCreatedPerDay"` + CiDeletedPerDay int `json:"ciDeletedPerDay"` + CdDeletedPerDay int `json:"cdDeletedPerDay"` + CiTriggeredPerDay int `json:"ciTriggeredPerDay"` + CdTriggeredPerDay int `json:"cdTriggeredPerDay"` HelmChartCount int `json:"helmChartCount,omitempty"` SecurityScanCountPerDay int `json:"securityScanCountPerDay,omitempty"` GitAccountsCount int `json:"gitAccountsCount,omitempty"` @@ -187,7 +191,7 @@ func (impl *TelemetryEventClientImplExtended) SendSummaryEvent(eventType string) impl.logger.Infow("sending summary event", "eventType", eventType) ucid, err := impl.getUCID() if err != nil { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) + impl.logger.Errorw("exception caught inside telemetry summary event while retrieving ucid", "err", err) return err } @@ -200,58 +204,77 @@ func (impl *TelemetryEventClientImplExtended) SendSummaryEvent(eventType string) payload := &TelemetryEventDto{UCID: ucid, Timestamp: time.Now(), EventType: TelemetryEventType(eventType), DevtronVersion: "v1"} payload.ServerVersion = k8sServerVersion.String() - environments, err := impl.environmentService.GetAllActive() + environmentCount, err := impl.environmentService.GetAllActiveEnvironmentCount() if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) - return err + impl.logger.Errorw("exception caught inside telemetry summary event while retrieving environmentCount, setting its value to -1", "err", err) + environmentCount = -1 } prodApps, err := impl.appListingRepository.FindAppCount(true) if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) - return err + impl.logger.Errorw("exception caught inside telemetry summary event, while retrieving prodApps, setting its value to -1", "err", err) + prodApps = -1 } nonProdApps, err := impl.appListingRepository.FindAppCount(false) if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) - return err + impl.logger.Errorw("exception caught inside telemetry summary event,while retrieving nonProdApps, setting its value to -1", "err", err) + nonProdApps = -1 } - ciPipeline, err := impl.ciPipelineRepository.FindAllPipelineInLast24Hour() + ciPipelineCount, err := impl.ciPipelineRepository.FindAllPipelineCreatedCountInLast24Hour() if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) - return err + impl.logger.Errorw("exception caught inside telemetry summary event, while retrieving ciPipelineCount, setting its value to -1", "err", err) + ciPipelineCount = -1 } - - cdPipeline, err := impl.pipelineRepository.FindAllPipelineInLast24Hour() + ciPipelineDeletedCount, err := impl.ciPipelineRepository.FindAllDeletedPipelineCountInLast24Hour() if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) - return err + impl.logger.Errorw("exception caught inside telemetry summary event, while retrieving ciPipelineDeletedCount, setting its value to -1", "err", err) + ciPipelineDeletedCount = -1 + } + ciPipelineTriggeredCount, err := impl.ciWorkflowRepository.FindAllTriggeredWorkflowCountInLast24Hour() + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("exception caught inside telemetry summary event, while retrieving ciPipelineTriggeredCount, setting its value to -1", "err", err) + ciPipelineTriggeredCount = -1 } - gitAccounts, err := impl.gitProviderRepository.FindAll() + cdPipelineCount, err := impl.pipelineRepository.FindAllPipelineCreatedCountInLast24Hour() if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) - return err + impl.logger.Errorw("exception caught inside telemetry summary event, while retrieving cdPipelineCount, setting its value to -1", "err", err) + cdPipelineCount = -1 + } + cdPipelineDeletedCount, err := impl.pipelineRepository.FindAllDeletedPipelineCountInLast24Hour() + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("exception caught inside telemetry summary event, while retrieving cdPipelineDeletedCount, setting its value to -1", "err", err) + cdPipelineDeletedCount = -1 + } + cdPipelineTriggeredCount, err := impl.cdWorkflowRepository.FindAllTriggeredWorkflowCountInLast24Hour() + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("exception caught inside telemetry summary event, while retrieving cdPipelineTriggeredCount, setting its value to -1", "err", err) + cdPipelineTriggeredCount = -1 + } + gitAccounts, err := impl.gitProviderRepository.FindAllGitProviderCount() + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("exception caught inside telemetry summary event, while retrieving gitAccounts, setting its value to -1", "err", err) + gitAccounts = -1 } gitOpsCount, err := impl.gitOpsConfigReadService.GetConfiguredGitOpsCount() if err != nil { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) - return err + impl.logger.Errorw("exception caught inside telemetry summary event,while retrieving gitOpsCount, setting its value to -1", "err", err) + gitOpsCount = -1 } - containerRegistry, err := impl.dockerArtifactStoreRepository.FindAll() + containerRegistryCount, err := impl.dockerArtifactStoreRepository.FindAllDockerArtifactCount() if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) - return err + impl.logger.Errorw("exception caught inside telemetry summary event,while retrieving containerRegistryCount, setting its value to -1", "err", err) + containerRegistryCount = -1 } //appSetup := false apps, err := impl.appRepository.FindAll() if err != nil { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) + impl.logger.Errorw("exception caught inside telemetry summary event,while retrieving apps", "err", err) return err } @@ -264,24 +287,24 @@ func (impl *TelemetryEventClientImplExtended) SendSummaryEvent(eventType string) if len(appIds) < AppsCount { payload.AppsWithGitRepoConfigured, err = impl.materialRepository.FindNumberOfAppsWithGitRepo(appIds) if err != nil { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) + impl.logger.Errorw("exception caught inside telemetry summary event,while retrieving AppsWithGitRepoConfigured", "err", err) } payload.AppsWithDockerConfigured, err = impl.ciTemplateRepository.FindNumberOfAppsWithDockerConfigured(appIds) if err != nil { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) + impl.logger.Errorw("exception caught inside telemetry summary event,while retrieving AppsWithDockerConfigured", "err", err) } payload.AppsWithDeploymentTemplateConfigured, err = impl.chartRepository.FindNumberOfAppsWithDeploymentTemplate(appIds) if err != nil { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) + impl.logger.Errorw("exception caught inside telemetry summary event,while retrieving AppsWithDeploymentTemplateConfigured", "err", err) } payload.AppsWithCiPipelineConfigured, err = impl.ciPipelineRepository.FindNumberOfAppsWithCiPipeline(appIds) if err != nil { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) + impl.logger.Errorw("exception caught inside telemetry summary event,while retrieving AppsWithCiPipelineConfigured", "err", err) } payload.AppsWithCdPipelineConfigured, err = impl.pipelineRepository.FindNumberOfAppsWithCdPipeline(appIds) if err != nil { - impl.logger.Errorw("exception caught inside telemetry summary event", "err", err) + impl.logger.Errorw("exception caught inside telemetry summary event,while retrieving AppsWithCdPipelineConfigured", "err", err) } } @@ -302,15 +325,18 @@ func (impl *TelemetryEventClientImplExtended) SendSummaryEvent(eventType string) devtronVersion := util.GetDevtronVersion() payload.ProdAppCount = prodApps payload.NonProdAppCount = nonProdApps - payload.RegistryCount = len(containerRegistry) + payload.RegistryCount = containerRegistryCount payload.SSOLogin = ssoSetup payload.UserCount = len(users) - payload.EnvironmentCount = len(environments) + payload.EnvironmentCount = environmentCount payload.ClusterCount = len(clusters) - payload.CiCountPerDay = len(ciPipeline) - - payload.CdCountPerDay = len(cdPipeline) - payload.GitAccountsCount = len(gitAccounts) + payload.CiCreatedPerDay = ciPipelineCount + payload.CiDeletedPerDay = ciPipelineDeletedCount + payload.CiTriggeredPerDay = ciPipelineTriggeredCount + payload.CdCreatedPerDay = cdPipelineCount + payload.CdDeletedPerDay = cdPipelineDeletedCount + payload.CdTriggeredPerDay = cdPipelineTriggeredCount + payload.GitAccountsCount = gitAccounts payload.GitOpsCount = gitOpsCount payload.HostURL = hostURL payload.DevtronGitVersion = devtronVersion.GitCommit diff --git a/cmd/external-app/wire_gen.go b/cmd/external-app/wire_gen.go index 4019867777..d82b8c6fa1 100644 --- a/cmd/external-app/wire_gen.go +++ b/cmd/external-app/wire_gen.go @@ -1,6 +1,6 @@ // Code generated by Wire. DO NOT EDIT. -//go:generate go run github.com/google/wire/cmd/wire +//go:generate go run -mod=mod github.com/google/wire/cmd/wire //go:build !wireinject // +build !wireinject diff --git a/internal/sql/repository/GitOpsConfigRepository.go b/internal/sql/repository/GitOpsConfigRepository.go index 8f59497342..4cb3a23046 100644 --- a/internal/sql/repository/GitOpsConfigRepository.go +++ b/internal/sql/repository/GitOpsConfigRepository.go @@ -28,6 +28,7 @@ type GitOpsConfigRepository interface { UpdateGitOpsConfig(model *GitOpsConfig, tx *pg.Tx) error GetGitOpsConfigById(id int) (*GitOpsConfig, error) GetAllGitOpsConfig() ([]*GitOpsConfig, error) + GetAllGitOpsConfigCount() (int, error) GetGitOpsConfigByProvider(provider string) (*GitOpsConfig, error) GetGitOpsConfigActive() (*GitOpsConfig, error) GetConnection() *pg.DB @@ -91,6 +92,10 @@ func (impl *GitOpsConfigRepositoryImpl) GetAllGitOpsConfig() ([]*GitOpsConfig, e err := impl.dbConnection.Model(&userModel).Order("updated_on desc").Select() return userModel, err } +func (impl *GitOpsConfigRepositoryImpl) GetAllGitOpsConfigCount() (int, error) { + cnt, err := impl.dbConnection.Model(&GitOpsConfig{}).Count() + return cnt, err +} func (impl *GitOpsConfigRepositoryImpl) GetGitOpsConfigByProvider(provider string) (*GitOpsConfig, error) { var model GitOpsConfig err := impl.dbConnection.Model(&model).Where("provider = ?", provider).Select() diff --git a/internal/sql/repository/GitProviderRepository.go b/internal/sql/repository/GitProviderRepository.go index f2b73d96b3..b75a5806a2 100644 --- a/internal/sql/repository/GitProviderRepository.go +++ b/internal/sql/repository/GitProviderRepository.go @@ -52,6 +52,7 @@ type GitProviderRepository interface { ProviderExists(url string) (bool, error) FindAllActiveForAutocomplete() ([]GitProvider, error) FindAll() ([]GitProvider, error) + FindAllGitProviderCount() (int, error) FindOne(providerId string) (GitProvider, error) FindByUrl(providerUrl string) (GitProvider, error) Update(gitProvider *GitProvider) error @@ -95,6 +96,11 @@ func (impl GitProviderRepositoryImpl) FindAll() ([]GitProvider, error) { Where("deleted = ?", false).Select() return providers, err } +func (impl GitProviderRepositoryImpl) FindAllGitProviderCount() (int, error) { + gitProviderCount, err := impl.dbConnection.Model(&GitProvider{}). + Where("deleted = ?", false).Count() + return gitProviderCount, err +} func (impl GitProviderRepositoryImpl) FindOne(providerId string) (GitProvider, error) { var provider GitProvider diff --git a/internal/sql/repository/dockerRegistry/DockerArtifactStoreRepository.go b/internal/sql/repository/dockerRegistry/DockerArtifactStoreRepository.go index ebb20f79f3..d2810cb083 100644 --- a/internal/sql/repository/dockerRegistry/DockerArtifactStoreRepository.go +++ b/internal/sql/repository/dockerRegistry/DockerArtifactStoreRepository.go @@ -92,6 +92,7 @@ type DockerArtifactStoreRepository interface { FindActiveDefaultStore() (*DockerArtifactStore, error) FindAllActiveForAutocomplete() ([]DockerArtifactStore, error) FindAll() ([]DockerArtifactStore, error) + FindAllDockerArtifactCount() (int, error) FindAllChartProviders() ([]DockerArtifactStore, error) FindOne(storeId string) (*DockerArtifactStore, error) FindOneWithDeploymentCount(storeId string) (*DockerArtifactStoreExt, error) @@ -169,7 +170,12 @@ func (impl DockerArtifactStoreRepositoryImpl) FindAll() ([]DockerArtifactStore, Select() return providers, err } - +func (impl DockerArtifactStoreRepositoryImpl) FindAllDockerArtifactCount() (int, error) { + dockerArtifactCount, err := impl.dbConnection.Model(&DockerArtifactStore{}). + Where("docker_artifact_store.active = ?", true). + Count() + return dockerArtifactCount, err +} func (impl DockerArtifactStoreRepositoryImpl) FindAllChartProviders() ([]DockerArtifactStore, error) { var providers []DockerArtifactStore err := impl.dbConnection.Model(&providers). diff --git a/internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go b/internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go index b24c79934a..9e5cf2abcd 100644 --- a/internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go +++ b/internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go @@ -57,7 +57,7 @@ type CdWorkflowRepository interface { FindLatestWfrByAppIdAndEnvironmentId(appId int, environmentId int) (*CdWorkflowRunner, error) IsLatestCDWfr(pipelineId, wfrId int) (bool, error) FindLatestCdWorkflowRunnerByEnvironmentIdAndRunnerType(appId int, environmentId int, runnerType bean.WorkflowType) (CdWorkflowRunner, error) - + FindAllTriggeredWorkflowCountInLast24Hour() (cdWorkflowCount int, err error) GetConnection() *pg.DB FindLastPreOrPostTriggeredByPipelineId(pipelineId int) (CdWorkflowRunner, error) @@ -357,7 +357,19 @@ func (impl *CdWorkflowRepositoryImpl) FindLatestCdWorkflowByPipelineIdV2(pipelin // TODO - Group By Environment And Pipeline will get latest pipeline from top return cdWorkflow, err } - +func (impl *CdWorkflowRepositoryImpl) FindAllTriggeredWorkflowCountInLast24Hour() (cdWorkflowCount int, err error) { + cnt, err := impl.dbConnection. + Model(&CdWorkflow{}). + ColumnExpr("DISTINCT pipeline_id"). + Join("JOIN cd_workflow_runner ON cd_workflow.id = cd_workflow_runner.cd_workflow_id"). + Where("cd_workflow_runner.workflow_type = ? AND cd_workflow_runner.started_on > ?", bean.CD_WORKFLOW_TYPE_DEPLOY, time.Now().AddDate(0, 0, -1)). + Group("cd_workflow.pipeline_id"). + Count() + if err != nil { + impl.logger.Errorw("error occurred while fetching cd workflow", "err", err) + } + return cnt, err +} func (impl *CdWorkflowRepositoryImpl) FindCdWorkflowMetaByEnvironmentId(appId int, environmentId int, offset int, limit int) ([]CdWorkflowRunner, error) { var wfrList []CdWorkflowRunner err := impl.dbConnection. diff --git a/internal/sql/repository/pipelineConfig/CiPipelineRepository.go b/internal/sql/repository/pipelineConfig/CiPipelineRepository.go index 495b4b7d64..f16a4e6cf1 100644 --- a/internal/sql/repository/pipelineConfig/CiPipelineRepository.go +++ b/internal/sql/repository/pipelineConfig/CiPipelineRepository.go @@ -128,7 +128,8 @@ type CiPipelineRepository interface { FetchParentCiPipelinesForDG() ([]*bean.CiPipelinesMap, error) FetchCiPipelinesForDG(parentId int, childCiPipelineIds []int) (*CiPipeline, int, error) FinDByParentCiPipelineAndAppId(parentCiPipeline int, appIds []int) ([]*CiPipeline, error) - FindAllPipelineInLast24Hour() (pipelines []*CiPipeline, err error) + FindAllPipelineCreatedCountInLast24Hour() (pipelineCount int, err error) + FindAllDeletedPipelineCountInLast24Hour() (pipelineCount int, err error) FindNumberOfAppsWithCiPipeline(appIds []int) (count int, err error) FindAppAndProjectByCiPipelineIds(ciPipelineIds []int) ([]*CiPipeline, error) FindCiPipelineConfigsByIds(ids []int) ([]*CiPipeline, error) @@ -502,12 +503,17 @@ func (impl *CiPipelineRepositoryImpl) FinDByParentCiPipelineAndAppId(parentCiPip return ciPipelines, err } -func (impl *CiPipelineRepositoryImpl) FindAllPipelineInLast24Hour() (pipelines []*CiPipeline, err error) { - err = impl.dbConnection.Model(&pipelines). - Column("ci_pipeline.*"). +func (impl *CiPipelineRepositoryImpl) FindAllPipelineCreatedCountInLast24Hour() (pipelineCount int, err error) { + pipelineCount, err = impl.dbConnection.Model(&CiPipeline{}). Where("created_on > ?", time.Now().AddDate(0, 0, -1)). - Select() - return pipelines, err + Count() + return pipelineCount, err +} +func (impl *CiPipelineRepositoryImpl) FindAllDeletedPipelineCountInLast24Hour() (pipelineCount int, err error) { + pipelineCount, err = impl.dbConnection.Model(&CiPipeline{}). + Where("created_on > ? and deleted=?", time.Now().AddDate(0, 0, -1), true). + Count() + return pipelineCount, err } func (impl *CiPipelineRepositoryImpl) FindNumberOfAppsWithCiPipeline(appIds []int) (count int, err error) { diff --git a/internal/sql/repository/pipelineConfig/CiWorkflowRepository.go b/internal/sql/repository/pipelineConfig/CiWorkflowRepository.go index 338032227a..7044f77ee6 100644 --- a/internal/sql/repository/pipelineConfig/CiWorkflowRepository.go +++ b/internal/sql/repository/pipelineConfig/CiWorkflowRepository.go @@ -43,6 +43,7 @@ type CiWorkflowRepository interface { FindLastTriggeredWorkflowByCiIds(pipelineId []int) (ciWorkflow []*CiWorkflow, err error) FindLastTriggeredWorkflowByArtifactId(ciArtifactId int) (ciWorkflow *CiWorkflow, err error) FindAllLastTriggeredWorkflowByArtifactId(ciArtifactId []int) (ciWorkflow []*CiWorkflow, err error) + FindAllTriggeredWorkflowCountInLast24Hour() (ciWorkflowCount int, err error) FindLastTriggeredWorkflowGitTriggersByArtifactId(ciArtifactId int) (ciWorkflow *CiWorkflow, err error) FindLastTriggeredWorkflowGitTriggersByArtifactIds(ciArtifactIds []int) ([]*WorkflowWithArtifact, error) ExistsByStatus(status string) (bool, error) @@ -286,7 +287,16 @@ func (impl *CiWorkflowRepositoryImpl) FindLastTriggeredWorkflowByArtifactId(ciAr Select() return workflow, err } - +func (impl *CiWorkflowRepositoryImpl) FindAllTriggeredWorkflowCountInLast24Hour() (ciWorkflowCount int, err error) { + cnt, err := impl.dbConnection.Model(&CiWorkflow{}). + ColumnExpr("DISTINCT ci_pipeline_id"). + Where("started_on > ? ", time.Now().AddDate(0, 0, -1)). + Count() + if err != nil { + impl.logger.Errorw("error occurred while fetching ci workflow", "err", err) + } + return cnt, err +} func (impl *CiWorkflowRepositoryImpl) FindAllLastTriggeredWorkflowByArtifactId(ciArtifactIds []int) (ciWorkflows []*CiWorkflow, err error) { err = impl.dbConnection.Model(&ciWorkflows). Column("ci_workflow.git_triggers", "ci_workflow.ci_pipeline_id", "CiPipeline", "cia.id"). diff --git a/internal/sql/repository/pipelineConfig/PipelineRepository.go b/internal/sql/repository/pipelineConfig/PipelineRepository.go index 0d8fbbb7e8..d2176e4ec4 100644 --- a/internal/sql/repository/pipelineConfig/PipelineRepository.go +++ b/internal/sql/repository/pipelineConfig/PipelineRepository.go @@ -93,7 +93,8 @@ type PipelineRepository interface { FindByIdsInAndEnvironment(ids []int, environmentId int) ([]*Pipeline, error) FindActiveByAppIdAndEnvironmentIdV2() (pipelines []*Pipeline, err error) GetConnection() *pg.DB - FindAllPipelineInLast24Hour() (pipelines []*Pipeline, err error) + FindAllPipelineCreatedCountInLast24Hour() (pipelineCount int, err error) + FindAllDeletedPipelineCountInLast24Hour() (pipelineCount int, err error) FindActiveByEnvId(envId int) (pipelines []*Pipeline, err error) FindActivePipelineByEnvId(envId int) (pipelines []*Pipeline, err error) FindActiveByEnvIds(envId []int) (pipelines []*Pipeline, err error) @@ -447,12 +448,17 @@ func (impl PipelineRepositoryImpl) FindByPipelineTriggerGitHash(gitHash string) return pipelines, err } -func (impl PipelineRepositoryImpl) FindAllPipelineInLast24Hour() (pipelines []*Pipeline, err error) { - err = impl.dbConnection.Model(&pipelines). - Column("pipeline.*"). +func (impl PipelineRepositoryImpl) FindAllPipelineCreatedCountInLast24Hour() (pipelineCount int, err error) { + pipelineCount, err = impl.dbConnection.Model(&Pipeline{}). Where("created_on > ?", time.Now().AddDate(0, 0, -1)). - Select() - return pipelines, err + Count() + return pipelineCount, err +} +func (impl PipelineRepositoryImpl) FindAllDeletedPipelineCountInLast24Hour() (pipelineCount int, err error) { + pipelineCount, err = impl.dbConnection.Model(&Pipeline{}). + Where("created_on > ? and deleted=?", time.Now().AddDate(0, 0, -1), true). + Count() + return pipelineCount, err } func (impl PipelineRepositoryImpl) FindActiveByEnvId(envId int) (pipelines []*Pipeline, err error) { err = impl.dbConnection.Model(&pipelines).Column("pipeline.*", "App", "Environment"). diff --git a/pkg/cluster/EnvironmentService.go b/pkg/cluster/EnvironmentService.go index 43740137bd..02f4a16b1e 100644 --- a/pkg/cluster/EnvironmentService.go +++ b/pkg/cluster/EnvironmentService.go @@ -46,6 +46,7 @@ type EnvironmentService interface { Update(mappings *bean2.EnvironmentBean, userId int32) (*bean2.EnvironmentBean, error) GetAll() ([]bean2.EnvironmentBean, error) GetAllActive() ([]bean2.EnvironmentBean, error) + GetAllActiveEnvironmentCount() (int, error) Delete(deleteReq *bean2.EnvironmentBean, userId int32) error FindClusterByEnvId(id int) (*ClusterBean, error) // FindById provides an exposed struct of bean.EnvironmentBean; @@ -231,7 +232,10 @@ func (impl EnvironmentServiceImpl) GetAllActive() ([]bean2.EnvironmentBean, erro } return beans, nil } - +func (impl EnvironmentServiceImpl) GetAllActiveEnvironmentCount() (int, error) { + cnt, err := impl.environmentRepository.FindAllActiveEnvironmentCount() + return cnt, err +} func (impl EnvironmentServiceImpl) FindById(id int) (*bean2.EnvironmentBean, error) { model, err := impl.environmentRepository.FindById(id) if err != nil { diff --git a/pkg/cluster/repository/EnvironmentRepository.go b/pkg/cluster/repository/EnvironmentRepository.go index 19b9c9c3d5..7ccd1845d7 100644 --- a/pkg/cluster/repository/EnvironmentRepository.go +++ b/pkg/cluster/repository/EnvironmentRepository.go @@ -54,6 +54,7 @@ type EnvironmentRepository interface { Create(mappings *Environment) error FindAll() ([]Environment, error) FindAllActive() ([]*Environment, error) + FindAllActiveEnvironmentCount() (int, error) MarkEnvironmentDeleted(mappings *Environment, tx *pg.Tx) error GetConnection() (dbConnection *pg.DB) FindAllActiveEnvOnlyDetails() ([]*Environment, error) @@ -256,6 +257,13 @@ func (repositoryImpl EnvironmentRepositoryImpl) FindAllActive() ([]*Environment, Select() return mappings, err } +func (repositoryImpl EnvironmentRepositoryImpl) FindAllActiveEnvironmentCount() (int, error) { + cnt, err := repositoryImpl. + dbConnection.Model(&Environment{}). + Where("environment.active = ?", true). + Count() + return cnt, err +} func (repositoryImpl EnvironmentRepositoryImpl) FindAllActiveEnvOnlyDetails() ([]*Environment, error) { var mappings []*Environment err := repositoryImpl. diff --git a/pkg/deployment/gitOps/config/GitOpsConfigReadService.go b/pkg/deployment/gitOps/config/GitOpsConfigReadService.go index 519f5e5cf0..4f98046e05 100644 --- a/pkg/deployment/gitOps/config/GitOpsConfigReadService.go +++ b/pkg/deployment/gitOps/config/GitOpsConfigReadService.go @@ -139,12 +139,6 @@ func (impl *GitOpsConfigReadServiceImpl) GetGitOpsConfigActive() (*bean2.GitOpsC } func (impl *GitOpsConfigReadServiceImpl) GetConfiguredGitOpsCount() (int, error) { - count := 0 - models, err := impl.gitOpsRepository.GetAllGitOpsConfig() - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error, GetGitOpsConfigActive", "err", err) - return count, err - } - count = len(models) - return count, nil + count, err := impl.gitOpsRepository.GetAllGitOpsConfigCount() + return count, err } diff --git a/wire_gen.go b/wire_gen.go index 5a60b944d1..6d697c7670 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -1,6 +1,6 @@ // Code generated by Wire. DO NOT EDIT. -//go:generate go run github.com/google/wire/cmd/wire +//go:generate go run -mod=mod github.com/google/wire/cmd/wire //go:build !wireinject // +build !wireinject