Skip to content

Commit 062278e

Browse files
committed
gitops pipeline
1 parent cd2741a commit 062278e

File tree

5 files changed

+92
-11
lines changed

5 files changed

+92
-11
lines changed

client/telemetry/TelemetryEventClient.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ func (impl *TelemetryEventClientImpl) SendSummaryEvent(eventType string) error {
340340
payload.AppliedPolicyRowCount = impl.getAppliedPolicyRowCount()
341341
payload.PhysicalClusterCount, payload.IsolatedClusterCount = impl.getClusterCounts()
342342
payload.ActiveUsersLast30Days = impl.getActiveUsersLast30Days()
343+
payload.GitOpsPipelineCount = impl.getGitOpsPipelineCount()
344+
payload.NoGitOpsPipelineCount = impl.getNoGitOpsPipelineCount()
343345

344346
payload.ClusterProvider, err = impl.GetCloudProvider()
345347
if err != nil {

client/telemetry/TelemetryEventClientExtended.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ func (impl *TelemetryEventClientImplExtended) SendSummaryEvent(eventType string)
348348
payload.AppliedPolicyRowCount = impl.getAppliedPolicyRowCount()
349349
payload.PhysicalClusterCount, payload.IsolatedClusterCount = impl.getClusterCounts()
350350
payload.ActiveUsersLast30Days = impl.getActiveUsersLast30Days()
351+
payload.GitOpsPipelineCount = impl.getGitOpsPipelineCount()
352+
payload.NoGitOpsPipelineCount = impl.getNoGitOpsPipelineCount()
351353

352354
payload.ClusterProvider, err = impl.GetCloudProvider()
353355
if err != nil {

client/telemetry/bean.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ type TelemetryEventEA struct {
8888
PhysicalClusterCount int `json:"physicalClusterCount,omitempty"`
8989
IsolatedClusterCount int `json:"isolatedClusterCount,omitempty"`
9090
ActiveUsersLast30Days int `json:"activeUsersLast30Days,omitempty"`
91+
GitOpsPipelineCount int `json:"gitOpsPipelineCount,omitempty"`
92+
NoGitOpsPipelineCount int `json:"noGitOpsPipelineCount,omitempty"`
9193
}
9294

9395
const AppsCount int = 50
@@ -162,4 +164,6 @@ type TelemetryEventDto struct {
162164
PhysicalClusterCount int `json:"physicalClusterCount,omitempty"`
163165
IsolatedClusterCount int `json:"isolatedClusterCount,omitempty"`
164166
ActiveUsersLast30Days int `json:"activeUsersLast30Days,omitempty"`
167+
GitOpsPipelineCount int `json:"gitOpsPipelineCount,omitempty"`
168+
NoGitOpsPipelineCount int `json:"noGitOpsPipelineCount,omitempty"`
165169
}

client/telemetry/telemetryQueries.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,54 @@ func (impl *TelemetryEventClientImpl) getActiveUsersLast30Days() int {
172172
impl.logger.Debugw("counted active users in last 30 days", "count", count)
173173
return count
174174
}
175+
176+
func (impl *TelemetryEventClientImpl) getGitOpsPipelineCount() int {
177+
// Check if we have the required dependency
178+
if impl.cdWorkflowRepository == nil {
179+
impl.logger.Warnw("cdWorkflowRepository not available for GitOps pipeline count")
180+
return -1
181+
}
182+
183+
var count int
184+
query := `
185+
SELECT COUNT(DISTINCT p.id)
186+
FROM pipeline p
187+
WHERE p.deleted = false AND p.deployment_app_type = 'argo_cd'
188+
`
189+
190+
dbConnection := impl.cdWorkflowRepository.GetConnection()
191+
_, err := dbConnection.Query(&count, query)
192+
if err != nil {
193+
impl.logger.Errorw("error getting GitOps pipeline count", "err", err)
194+
return -1
195+
}
196+
197+
impl.logger.Debugw("counted GitOps pipelines", "count", count)
198+
return count
199+
}
200+
201+
func (impl *TelemetryEventClientImpl) getNoGitOpsPipelineCount() int {
202+
// Check if we have the required dependency
203+
if impl.cdWorkflowRepository == nil {
204+
impl.logger.Warnw("cdWorkflowRepository not available for No-GitOps pipeline count")
205+
return -1
206+
}
207+
208+
// Get the pipeline repository from cdWorkflowRepository connection
209+
var count int
210+
query := `
211+
SELECT COUNT(DISTINCT p.id)
212+
FROM pipeline p
213+
WHERE p.deleted = false AND p.deployment_app_type = 'helm'
214+
`
215+
216+
dbConnection := impl.cdWorkflowRepository.GetConnection()
217+
_, err := dbConnection.Query(&count, query)
218+
if err != nil {
219+
impl.logger.Errorw("error getting No-GitOps pipeline count", "err", err)
220+
return -1
221+
}
222+
223+
impl.logger.Debugw("counted No-GitOps pipelines", "count", count)
224+
return count
225+
}

internal/sql/repository/pipelineConfig/PipelineRepository.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ type PipelineRepository interface {
146146
GetAllAppsByClusterAndDeploymentAppType(clusterIds []int, deploymentAppName string) ([]*PipelineDeploymentConfigObj, error)
147147
GetAllArgoAppInfoByDeploymentAppNames(deploymentAppNames []string) ([]*PipelineDeploymentConfigObj, error)
148148
FindEnvIdsByIdsInIncludingDeleted(ids []int) ([]int, error)
149+
GetPipelineCountByDeploymentType(deploymentType string) (int, error)
149150
}
150151

151152
type CiArtifactDTO struct {
@@ -672,14 +673,14 @@ func (impl *PipelineRepositoryImpl) GetAppAndEnvDetailsForDeploymentAppTypePipel
672673

673674
func (impl *PipelineRepositoryImpl) GetArgoPipelinesHavingTriggersStuckInLastPossibleNonTerminalTimelines(pendingSinceSeconds int, timeForDegradation int) ([]*Pipeline, error) {
674675
var pipelines []*Pipeline
675-
queryString := `select p.* from pipeline p inner join cd_workflow cw on cw.pipeline_id = p.id
676-
inner join cd_workflow_runner cwr on cwr.cd_workflow_id=cw.id
676+
queryString := `select p.* from pipeline p inner join cd_workflow cw on cw.pipeline_id = p.id
677+
inner join cd_workflow_runner cwr on cwr.cd_workflow_id=cw.id
677678
left join deployment_config dc on dc.active=true and dc.app_id = p.app_id and dc.environment_id=p.environment_id
678-
where cwr.id in (select cd_workflow_runner_id from pipeline_status_timeline
679-
where id in
680-
(select DISTINCT ON (cd_workflow_runner_id) max(id) as id from pipeline_status_timeline
681-
group by cd_workflow_runner_id, id order by cd_workflow_runner_id,id desc)
682-
and status in (?) and status_time < NOW() - INTERVAL '? seconds')
679+
where cwr.id in (select cd_workflow_runner_id from pipeline_status_timeline
680+
where id in
681+
(select DISTINCT ON (cd_workflow_runner_id) max(id) as id from pipeline_status_timeline
682+
group by cd_workflow_runner_id, id order by cd_workflow_runner_id,id desc)
683+
and status in (?) and status_time < NOW() - INTERVAL '? seconds')
683684
and cwr.started_on > NOW() - INTERVAL '? minutes' and (p.deployment_app_type=? or dc.deployment_app_type=?) and p.deleted=?;`
684685
_, err := impl.dbConnection.Query(&pipelines, queryString,
685686
pg.In([]timelineStatus.TimelineStatus{timelineStatus.TIMELINE_STATUS_KUBECTL_APPLY_SYNCED,
@@ -694,11 +695,11 @@ func (impl *PipelineRepositoryImpl) GetArgoPipelinesHavingTriggersStuckInLastPos
694695

695696
func (impl *PipelineRepositoryImpl) GetArgoPipelinesHavingLatestTriggerStuckInNonTerminalStatuses(getPipelineDeployedBeforeMinutes int, getPipelineDeployedWithinHours int) ([]*Pipeline, error) {
696697
var pipelines []*Pipeline
697-
queryString := `select p.id from pipeline p inner join cd_workflow cw on cw.pipeline_id = p.id
698-
inner join cd_workflow_runner cwr on cwr.cd_workflow_id=cw.id
698+
queryString := `select p.id from pipeline p inner join cd_workflow cw on cw.pipeline_id = p.id
699+
inner join cd_workflow_runner cwr on cwr.cd_workflow_id=cw.id
699700
left join deployment_config dc on dc.active=true and dc.app_id = p.app_id and dc.environment_id=p.environment_id
700-
where cwr.id in (select id from cd_workflow_runner
701-
where started_on < NOW() - INTERVAL '? minutes' and started_on > NOW() - INTERVAL '? hours' and status not in (?)
701+
where cwr.id in (select id from cd_workflow_runner
702+
where started_on < NOW() - INTERVAL '? minutes' and started_on > NOW() - INTERVAL '? hours' and status not in (?)
702703
and workflow_type=? and cd_workflow_id in (select DISTINCT ON (pipeline_id) max(id) as id from cd_workflow
703704
group by pipeline_id, id order by pipeline_id, id desc))
704705
and (p.deployment_app_type=? or dc.deployment_app_type=?) and p.deleted=?;`
@@ -967,3 +968,24 @@ func (impl *PipelineRepositoryImpl) FindEnvIdsByIdsInIncludingDeleted(ids []int)
967968
}
968969
return envIds, err
969970
}
971+
972+
func (impl *PipelineRepositoryImpl) GetPipelineCountByDeploymentType(deploymentType string) (int, error) {
973+
var count int
974+
// Count pipelines by deployment type, considering both pipeline table and deployment_config table
975+
// The deployment_config table can override the deployment type from the pipeline table
976+
query := `
977+
SELECT COUNT(DISTINCT p.id)
978+
FROM pipeline p
979+
LEFT JOIN deployment_config dc ON dc.active = true
980+
AND dc.app_id = p.app_id
981+
AND dc.environment_id = p.environment_id
982+
WHERE p.deleted = false
983+
AND (p.deployment_app_type = ? OR dc.deployment_app_type = ?)
984+
`
985+
_, err := impl.dbConnection.Query(&count, query, deploymentType, deploymentType)
986+
if err != nil {
987+
impl.logger.Errorw("error getting pipeline count by deployment type", "deploymentType", deploymentType, "err", err)
988+
return 0, err
989+
}
990+
return count, nil
991+
}

0 commit comments

Comments
 (0)