Skip to content

Commit 0db6568

Browse files
committed
refact
1 parent 64ef5d0 commit 0db6568

File tree

4 files changed

+164
-207
lines changed

4 files changed

+164
-207
lines changed

client/telemetry/TelemetryEventClient.go

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ import (
2929
installedAppReader "github.com/devtron-labs/devtron/pkg/appStore/installedApp/read"
3030
bean2 "github.com/devtron-labs/devtron/pkg/attributes/bean"
3131
"github.com/devtron-labs/devtron/pkg/auth/user/bean"
32-
authPolicyRepository "github.com/devtron-labs/devtron/pkg/auth/user/repository"
3332
bean3 "github.com/devtron-labs/devtron/pkg/cluster/bean"
3433
module2 "github.com/devtron-labs/devtron/pkg/module/bean"
35-
pluginRepository "github.com/devtron-labs/devtron/pkg/plugin/repository"
36-
cvePolicyRepository "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/repository"
37-
3834
ucidService "github.com/devtron-labs/devtron/pkg/ucid"
3935
cron3 "github.com/devtron-labs/devtron/util/cron"
4036
"go.opentelemetry.io/otel"
@@ -43,8 +39,6 @@ import (
4339

4440
"github.com/devtron-labs/common-lib/utils/k8s"
4541
"github.com/devtron-labs/devtron/internal/sql/repository"
46-
appRepository "github.com/devtron-labs/devtron/internal/sql/repository/app"
47-
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
4842
"github.com/devtron-labs/devtron/pkg/auth/sso"
4943
user2 "github.com/devtron-labs/devtron/pkg/auth/user"
5044
"github.com/devtron-labs/devtron/pkg/cluster"
@@ -81,15 +75,6 @@ type TelemetryEventClientImpl struct {
8175
cloudProviderIdentifierService cloudProviderIdentifier.ProviderIdentifierService
8276
telemetryConfig TelemetryConfig
8377
globalEnvVariables *util.GlobalEnvVariables
84-
// Additional repositories for telemetry metrics (passed from TelemetryEventClientExtended)
85-
appRepository appRepository.AppRepository
86-
ciWorkflowRepository pipelineConfig.CiWorkflowRepository
87-
cdWorkflowRepository pipelineConfig.CdWorkflowRepository
88-
// Repositories for plugin and policy metrics
89-
pluginRepository pluginRepository.GlobalPluginRepository
90-
cvePolicyRepository cvePolicyRepository.CvePolicyRepository
91-
defaultAuthPolicyRepository authPolicyRepository.DefaultAuthPolicyRepository
92-
rbacPolicyRepository authPolicyRepository.RbacPolicyDataRepository
9378
}
9479

9580
type TelemetryEventClient interface {
@@ -135,7 +120,6 @@ func NewTelemetryEventClientImpl(logger *zap.SugaredLogger, client *http.Client,
135120
telemetryConfig: TelemetryConfig{},
136121
globalEnvVariables: envVariables.GlobalEnvVariables,
137122
userAttributesRepository: userAttributesRepository,
138-
// Note: appRepository, ciWorkflowRepository, cdWorkflowRepository will be set by TelemetryEventClientExtended
139123
}
140124

141125
watcher.HeartbeatEventForTelemetry()
@@ -328,20 +312,22 @@ func (impl *TelemetryEventClientImpl) SendSummaryEvent(eventType string) error {
328312
payload.HelmChartSuccessfulDeploymentCount = helmChartSuccessfulDeploymentCount
329313
payload.ExternalHelmAppClusterCount = ExternalHelmAppClusterCount
330314

331-
// Collect new telemetry metrics
315+
// Collect EA-mode compatible telemetry metrics
332316
payload.HelmAppCount = impl.getHelmAppCount()
333-
payload.DevtronAppCount = impl.getDevtronAppCount()
334-
payload.JobCount = impl.getJobCount()
335-
payload.JobPipelineCount = impl.getJobPipelineCount()
336-
payload.JobPipelineTriggeredLast24h = impl.getJobPipelineTriggeredLast24h()
337-
payload.JobPipelineSucceededLast24h = impl.getJobPipelineSucceededLast24h()
338-
payload.UserCreatedPluginCount = impl.getUserCreatedPluginCount()
339-
payload.PolicyCount = impl.getPolicyCount()
340-
payload.AppliedPolicyRowCount = impl.getAppliedPolicyRowCount()
341317
payload.PhysicalClusterCount, payload.IsolatedClusterCount = impl.getClusterCounts()
342318
payload.ActiveUsersLast30Days = impl.getActiveUsersLast30Days()
343-
payload.GitOpsPipelineCount = impl.getGitOpsPipelineCount()
344-
payload.NoGitOpsPipelineCount = impl.helmPipelineCount()
319+
320+
// Set FULL-mode only metrics to 0 for EA mode
321+
payload.DevtronAppCount = 0
322+
payload.JobCount = 0
323+
payload.JobPipelineCount = 0
324+
payload.JobPipelineTriggeredLast24h = 0
325+
payload.JobPipelineSucceededLast24h = 0
326+
payload.UserCreatedPluginCount = 0
327+
payload.PolicyCount = 0
328+
payload.AppliedPolicyRowCount = 0
329+
payload.GitOpsPipelineCount = 0
330+
payload.NoGitOpsPipelineCount = 0
345331

346332
payload.ClusterProvider, err = impl.GetCloudProvider()
347333
if err != nil {

client/telemetry/TelemetryEventClientExtended.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ type TelemetryEventClientImplExtended struct {
7171
chartRepository chartRepoRepository.ChartRepository
7272
ciBuildConfigService pipeline.CiBuildConfigService
7373
gitOpsConfigReadService config.GitOpsConfigReadService
74+
// Additional repositories for FULL-mode telemetry metrics
75+
pluginRepository pluginRepository.GlobalPluginRepository
76+
cvePolicyRepository cvePolicyRepository.CvePolicyRepository
77+
defaultAuthPolicyRepository authPolicyRepository.DefaultAuthPolicyRepository
78+
rbacPolicyRepository authPolicyRepository.RbacPolicyDataRepository
7479
*TelemetryEventClientImpl
7580
}
7681

@@ -113,6 +118,11 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
113118
chartRepository: chartRepository,
114119
ciBuildConfigService: ciBuildConfigService,
115120
gitOpsConfigReadService: gitOpsConfigReadService,
121+
// Initialize FULL-mode specific repositories
122+
pluginRepository: pluginRepository,
123+
cvePolicyRepository: cvePolicyRepository,
124+
defaultAuthPolicyRepository: defaultAuthPolicyRepository,
125+
rbacPolicyRepository: rbacPolicyRepository,
116126
TelemetryEventClientImpl: &TelemetryEventClientImpl{
117127
cron: cron,
118128
logger: logger,
@@ -134,15 +144,6 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
134144
cloudProviderIdentifierService: cloudProviderIdentifierService,
135145
telemetryConfig: TelemetryConfig{},
136146
globalEnvVariables: envVariables.GlobalEnvVariables,
137-
// Pass existing repositories from TelemetryEventClientExtended to embedded TelemetryEventClientImpl
138-
appRepository: appRepository,
139-
ciWorkflowRepository: ciWorkflowRepository,
140-
cdWorkflowRepository: cdWorkflowRepository,
141-
// Pass plugin and policy repositories for additional telemetry metrics
142-
pluginRepository: pluginRepository,
143-
cvePolicyRepository: cvePolicyRepository,
144-
defaultAuthPolicyRepository: defaultAuthPolicyRepository,
145-
rbacPolicyRepository: rbacPolicyRepository,
146147
},
147148
}
148149

client/telemetry/telemetryQueries.go

Lines changed: 4 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package telemetry
22

3-
import (
4-
"github.com/devtron-labs/devtron/pkg/build/pipeline/bean/common"
5-
"github.com/devtron-labs/devtron/pkg/plugin/repository"
6-
)
3+
// EA-mode compatible telemetry queries - no imports needed for current methods
74

85
func (impl *TelemetryEventClientImpl) getHelmAppCount() int {
96
if impl.installedAppReadService == nil {
@@ -18,62 +15,7 @@ func (impl *TelemetryEventClientImpl) getHelmAppCount() int {
1815
return count
1916
}
2017

21-
func (impl *TelemetryEventClientImpl) getDevtronAppCount() int {
22-
if impl.appRepository == nil {
23-
impl.logger.Warnw("appRepository not available for devtron app count")
24-
return -1
25-
}
26-
devtronAppCount, err := impl.appRepository.FindDevtronAppCount()
27-
if err != nil {
28-
impl.logger.Errorw("error getting all apps for devtron app count", "err", err)
29-
return -1
30-
}
31-
return devtronAppCount
32-
}
33-
34-
func (impl *TelemetryEventClientImpl) getJobCount() int {
35-
if impl.appRepository == nil {
36-
impl.logger.Warnw("appRepository not available for job count")
37-
return -1
38-
}
39-
jobCount, err := impl.appRepository.FindJobCount()
40-
if err != nil {
41-
impl.logger.Errorw("error getting all apps for job count", "err", err)
42-
return -1
43-
}
44-
45-
return jobCount
46-
}
47-
48-
func (impl *TelemetryEventClientImpl) getUserCreatedPluginCount() int {
49-
if impl.pluginRepository == nil {
50-
impl.logger.Warnw("pluginRepository not available for user created plugin count")
51-
return -1
52-
}
53-
54-
// Get all user-created plugins (SHARED type)
55-
plugins, err := impl.pluginRepository.GetAllPluginMinDataByType(string(repository.PLUGIN_TYPE_SHARED))
56-
if err != nil {
57-
impl.logger.Errorw("error getting user created plugin count", "err", err)
58-
return 0
59-
}
60-
61-
return len(plugins)
62-
}
63-
64-
func (impl *TelemetryEventClientImpl) getPolicyCount() int {
65-
if impl.cvePolicyRepository == nil {
66-
impl.logger.Warnw("cvePolicyRepository not available for policy count")
67-
return -1
68-
}
69-
70-
// Get global policies
71-
globalPolicies, err := impl.cvePolicyRepository.GetGlobalPolicies()
72-
if err != nil {
73-
impl.logger.Errorw("error getting global CVE policies", "err", err)
74-
}
75-
return len(globalPolicies)
76-
}
18+
// EA-mode compatible telemetry methods
7719

7820
func (impl *TelemetryEventClientImpl) getClusterCounts() (physicalCount int, isolatedCount int) {
7921
clusters, err := impl.clusterService.FindAllActive()
@@ -96,66 +38,8 @@ func (impl *TelemetryEventClientImpl) getClusterCounts() (physicalCount int, iso
9638
return physicalCount, isolatedCount
9739
}
9840

99-
func (impl *TelemetryEventClientImpl) getJobPipelineCount() int {
100-
return 0
101-
}
102-
103-
func (impl *TelemetryEventClientImpl) getJobPipelineTriggeredLast24h() int {
104-
// Check if we have the required dependency
105-
if impl.ciWorkflowRepository == nil {
106-
impl.logger.Warnw("ciWorkflowRepository not available for job pipeline triggered count")
107-
return -1
108-
}
109-
110-
// Get build type and status data for the last 24 hours
111-
buildTypeStatusData := impl.ciWorkflowRepository.FindBuildTypeAndStatusDataOfLast1Day()
112-
if buildTypeStatusData == nil {
113-
impl.logger.Warnw("no build type status data available for last 24 hours")
114-
return 0
115-
}
116-
117-
// Count job pipeline triggers
118-
// Job pipelines have build type "CI_JOB"
119-
jobTriggeredCount := 0
120-
for _, data := range buildTypeStatusData {
121-
if data.Type == string(common.CI_JOB) {
122-
jobTriggeredCount += data.Count
123-
}
124-
}
125-
126-
return jobTriggeredCount
127-
}
128-
129-
func (impl *TelemetryEventClientImpl) getJobPipelineSucceededLast24h() int {
130-
// Check if we have the required dependency
131-
if impl.ciWorkflowRepository == nil {
132-
impl.logger.Warnw("ciWorkflowRepository not available for job pipeline succeeded count")
133-
return -1
134-
}
135-
136-
// Get build type and status data for the last 24 hours
137-
buildTypeStatusData := impl.ciWorkflowRepository.FindBuildTypeAndStatusDataOfLast1Day()
138-
if buildTypeStatusData == nil {
139-
impl.logger.Warnw("no build type status data available for last 24 hours")
140-
return 0
141-
}
142-
143-
// Count successful job pipeline runs
144-
// Job pipelines have build type "CI_JOB"
145-
successfulJobCount := 0
146-
for _, data := range buildTypeStatusData {
147-
if data.Type == "CI_JOB" && data.Status == "Succeeded" {
148-
successfulJobCount += data.Count
149-
}
150-
}
151-
152-
impl.logger.Debugw("counted successful job pipeline runs in last 24h", "count", successfulJobCount)
153-
return successfulJobCount
154-
}
155-
156-
func (impl *TelemetryEventClientImpl) getAppliedPolicyRowCount() int {
157-
return 0
158-
}
41+
// Note: FULL-mode specific methods like getDevtronAppCount, getJobCount, etc.
42+
// are now implemented in TelemetryEventClientImplExtended in telemetryQueriesExtended.go
15943

16044
func (impl *TelemetryEventClientImpl) getActiveUsersLast30Days() int {
16145
if impl.userAuditService == nil {
@@ -172,54 +56,3 @@ func (impl *TelemetryEventClientImpl) getActiveUsersLast30Days() int {
17256
impl.logger.Debugw("counted active users in last 30 days", "count", count)
17357
return count
17458
}
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) helmPipelineCount() 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-
}

0 commit comments

Comments
 (0)