1
1
package telemetry
2
2
3
- import "github.com/devtron-labs/devtron/pkg/plugin/repository"
3
+ import (
4
+ "github.com/devtron-labs/devtron/pkg/build/pipeline/bean/common"
5
+ "github.com/devtron-labs/devtron/pkg/plugin/repository"
6
+ )
4
7
5
8
func (impl * TelemetryEventClientImpl ) getHelmAppCount () int {
6
9
count , err := impl .installedAppReadService .GetActiveInstalledAppCount ()
@@ -31,12 +34,6 @@ func (impl *TelemetryEventClientImpl) getJobCount() int {
31
34
}
32
35
33
36
func (impl * TelemetryEventClientImpl ) getUserCreatedPluginCount () int {
34
- // Check if we have the plugin repository dependency
35
- if impl .pluginRepository == nil {
36
- impl .logger .Warnw ("pluginRepository not available for user created plugin count" )
37
- return 0
38
- }
39
-
40
37
// Get all user-created plugins (SHARED type)
41
38
plugins , err := impl .pluginRepository .GetAllPluginMinDataByType (string (repository .PLUGIN_TYPE_SHARED ))
42
39
if err != nil {
@@ -47,74 +44,13 @@ func (impl *TelemetryEventClientImpl) getUserCreatedPluginCount() int {
47
44
return len (plugins )
48
45
}
49
46
50
- func (impl * TelemetryEventClientImpl ) getPolicyCount () map [string ]int {
51
- policyCount := make (map [string ]int )
52
- policyCount ["global" ] = 0
53
- policyCount ["cluster" ] = 0
54
- policyCount ["environment" ] = 0
55
- policyCount ["application" ] = 0
56
-
57
- // Count CVE policies if repository is available
58
- if impl .cvePolicyRepository != nil {
59
- // Get global policies
60
- globalPolicies , err := impl .cvePolicyRepository .GetGlobalPolicies ()
61
- if err != nil {
62
- impl .logger .Errorw ("error getting global CVE policies" , "err" , err )
63
- } else {
64
- policyCount ["global" ] += len (globalPolicies )
65
- }
66
-
67
- // For cluster, environment, and application policies, we would need to iterate through
68
- // all clusters, environments, and applications, which could be expensive.
69
- // Instead, we'll use a simplified approach to get a representative count.
70
-
71
- // Get a sample of cluster policies (using cluster ID 1 as an example)
72
- clusterPolicies , err := impl .cvePolicyRepository .GetClusterPolicies (1 )
73
- if err == nil {
74
- policyCount ["cluster" ] += len (clusterPolicies )
75
- }
76
-
77
- // Get a sample of environment policies (using cluster ID 1 and env ID 1 as examples)
78
- envPolicies , err := impl .cvePolicyRepository .GetEnvPolicies (1 , 1 )
79
- if err == nil {
80
- policyCount ["environment" ] += len (envPolicies )
81
- }
82
-
83
- // Get a sample of application policies (using cluster ID 1, env ID 1, and app ID 1 as examples)
84
- appPolicies , err := impl .cvePolicyRepository .GetAppEnvPolicies (1 , 1 , 1 )
85
- if err == nil {
86
- policyCount ["application" ] += len (appPolicies )
87
- }
88
- } else {
89
- impl .logger .Warnw ("cvePolicyRepository not available for policy count" )
90
- }
91
-
92
- // Count auth policies if repository is available
93
- if impl .defaultAuthPolicyRepository != nil {
94
- // Auth policies are typically role-based, so we'll count them as global policies
95
- // This is a simplified approach
96
- authPolicies , err := impl .defaultAuthPolicyRepository .GetPolicyByRoleTypeAndEntity ("" , "" , "" )
97
- if err == nil && authPolicies != "" {
98
- // If we got a policy, increment the count
99
- policyCount ["global" ]++
100
- }
101
- } else {
102
- impl .logger .Warnw ("defaultAuthPolicyRepository not available for policy count" )
103
- }
104
-
105
- // Count RBAC policies if repository is available
106
- if impl .rbacPolicyRepository != nil {
107
- // RBAC policies are role-based, so we'll count them as global policies
108
- rbacPolicies , err := impl .rbacPolicyRepository .GetPolicyDataForAllRoles ()
109
- if err == nil {
110
- policyCount ["global" ] += len (rbacPolicies )
111
- }
112
- } else {
113
- impl .logger .Warnw ("rbacPolicyRepository not available for policy count" )
47
+ func (impl * TelemetryEventClientImpl ) getPolicyCount () int {
48
+ // Get global policies
49
+ globalPolicies , err := impl .cvePolicyRepository .GetGlobalPolicies ()
50
+ if err != nil {
51
+ impl .logger .Errorw ("error getting global CVE policies" , "err" , err )
114
52
}
115
-
116
- impl .logger .Debugw ("policy count" , "count" , policyCount )
117
- return policyCount
53
+ return len (globalPolicies )
118
54
}
119
55
120
56
func (impl * TelemetryEventClientImpl ) getClusterCounts () (physicalCount int , isolatedCount int ) {
@@ -139,42 +75,10 @@ func (impl *TelemetryEventClientImpl) getClusterCounts() (physicalCount int, iso
139
75
}
140
76
141
77
func (impl * TelemetryEventClientImpl ) getJobPipelineCount () int {
142
- // Check if we have the required repositories
143
- if impl .ciWorkflowRepository == nil || impl .appRepository == nil {
144
- impl .logger .Warnw ("required repositories not available for job pipeline count" )
145
- return - 1
146
- }
147
-
148
- // Get job count
149
- jobCount , err := impl .appRepository .FindJobCount ()
150
- if err != nil {
151
- impl .logger .Errorw ("error getting job count" , "err" , err )
152
- return - 1
153
- }
154
-
155
- if jobCount == 0 {
156
- return 0
157
- }
158
-
159
- // Count CI pipelines for job apps
160
- // This is a simplified approach - in a real implementation, we would
161
- // query the CI pipeline repository for pipelines associated with job apps
162
-
163
- // For now, we'll use a simple estimation based on job count
164
- // Assuming an average of 1.5 pipelines per job app
165
- jobPipelineCount := int (float64 (jobCount ) * 1.5 )
166
-
167
- impl .logger .Debugw ("estimated job pipeline count" , "jobCount" , jobCount , "pipelineCount" , jobPipelineCount )
168
- return jobPipelineCount
78
+ return 0
169
79
}
170
80
171
81
func (impl * TelemetryEventClientImpl ) getJobPipelineTriggeredLast24h () int {
172
- // Check if we have the required repositories
173
- if impl .ciWorkflowRepository == nil || impl .appRepository == nil {
174
- impl .logger .Warnw ("required repositories not available for job pipeline triggered count" )
175
- return - 1
176
- }
177
-
178
82
// Get build type and status data for the last 24 hours
179
83
buildTypeStatusData := impl .ciWorkflowRepository .FindBuildTypeAndStatusDataOfLast1Day ()
180
84
if buildTypeStatusData == nil {
@@ -186,42 +90,15 @@ func (impl *TelemetryEventClientImpl) getJobPipelineTriggeredLast24h() int {
186
90
// Job pipelines have build type "CI_JOB"
187
91
jobTriggeredCount := 0
188
92
for _ , data := range buildTypeStatusData {
189
- if data .Type == " CI_JOB" {
93
+ if data .Type == string ( common . CI_JOB ) {
190
94
jobTriggeredCount += data .Count
191
95
}
192
96
}
193
97
194
- // If we didn't find any specific CI_JOB type data, fall back to estimation
195
- if jobTriggeredCount == 0 {
196
- // Get total triggered workflows in last 24h (includes all apps, not just jobs)
197
- count , err := impl .ciWorkflowRepository .FindAllTriggeredWorkflowCountInLast24Hour ()
198
- if err != nil {
199
- impl .logger .Errorw ("error getting triggered workflow count" , "err" , err )
200
- return - 1
201
- }
202
-
203
- // Estimate job pipeline triggers as a fraction of total triggers
204
- jobCount := impl .getJobCount ()
205
- totalAppCount := impl .getDevtronAppCount () + jobCount
206
- if totalAppCount > 0 {
207
- jobTriggeredCount = (count * jobCount ) / totalAppCount
208
- impl .logger .Debugw ("estimated job pipeline triggers (fallback method)" ,
209
- "total" , count , "estimated" , jobTriggeredCount )
210
- }
211
- } else {
212
- impl .logger .Debugw ("counted job pipeline triggers in last 24h" , "count" , jobTriggeredCount )
213
- }
214
-
215
98
return jobTriggeredCount
216
99
}
217
100
218
101
func (impl * TelemetryEventClientImpl ) getJobPipelineSucceededLast24h () int {
219
- // Check if we have the required dependency
220
- if impl .ciWorkflowRepository == nil {
221
- impl .logger .Warnw ("ciWorkflowRepository not available for job pipeline succeeded count" )
222
- return - 1
223
- }
224
-
225
102
// Get build type and status data for the last 24 hours
226
103
buildTypeStatusData := impl .ciWorkflowRepository .FindBuildTypeAndStatusDataOfLast1Day ()
227
104
if buildTypeStatusData == nil {
@@ -242,47 +119,6 @@ func (impl *TelemetryEventClientImpl) getJobPipelineSucceededLast24h() int {
242
119
return successfulJobCount
243
120
}
244
121
245
- func (impl * TelemetryEventClientImpl ) getAppliedPolicyRowCount () map [string ]int {
246
- appliedCount := make (map [string ]int )
247
- appliedCount ["global" ] = 0
248
- appliedCount ["cluster" ] = 0
249
- appliedCount ["environment" ] = 0
250
- appliedCount ["application" ] = 0
251
-
252
- // For applied policy rows, we need to count the number of times policies are applied
253
- // This is a simplified implementation that estimates applied policy counts
254
-
255
- // If we have the CVE policy repository, we can estimate applied policies
256
- if impl .cvePolicyRepository != nil {
257
- // For CVE policies, we can estimate the number of applied policies by
258
- // checking for blocked CVEs in a sample application
259
-
260
- // This is a simplified approach - in a real implementation, we would
261
- // need to query the database for actual applied policy counts
262
-
263
- // For now, we'll use a simple estimation based on policy counts
264
- policyCount := impl .getPolicyCount ()
265
-
266
- // Estimate that each global policy is applied to all clusters
267
- clusters , err := impl .clusterService .FindAllActive ()
268
- if err == nil {
269
- appliedCount ["global" ] = policyCount ["global" ] * len (clusters )
270
- }
271
-
272
- // Estimate that each cluster policy is applied to all environments in that cluster
273
- // Assuming an average of 3 environments per cluster
274
- appliedCount ["cluster" ] = policyCount ["cluster" ] * 3
275
-
276
- // Estimate that each environment policy is applied to all apps in that environment
277
- // Assuming an average of 5 apps per environment
278
- appliedCount ["environment" ] = policyCount ["environment" ] * 5
279
-
280
- // Application policies are applied directly to applications
281
- appliedCount ["application" ] = policyCount ["application" ]
282
- } else {
283
- impl .logger .Warnw ("cvePolicyRepository not available for applied policy count" )
284
- }
285
-
286
- impl .logger .Debugw ("applied policy count" , "count" , appliedCount )
287
- return appliedCount
122
+ func (impl * TelemetryEventClientImpl ) getAppliedPolicyRowCount () int {
123
+ return 0
288
124
}
0 commit comments