Skip to content

Commit 22ee1c9

Browse files
committed
fix
1 parent d389839 commit 22ee1c9

File tree

2 files changed

+36
-200
lines changed

2 files changed

+36
-200
lines changed

client/telemetry/bean.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ type TelemetryEventEA struct {
7676
ExternalHelmAppClusterCount map[int32]int `json:"ExternalHelmAppClusterCount,omitempty"`
7777
ClusterProvider string `json:"clusterProvider,omitempty"`
7878
// New telemetry fields
79-
HelmAppCount int `json:"helmAppCount,omitempty"`
80-
DevtronAppCount int `json:"devtronAppCount,omitempty"`
81-
JobCount int `json:"jobCount,omitempty"`
82-
JobPipelineCount int `json:"jobPipelineCount,omitempty"`
83-
JobPipelineTriggeredLast24h int `json:"jobPipelineTriggeredLast24h,omitempty"`
84-
JobPipelineSucceededLast24h int `json:"jobPipelineSucceededLast24h,omitempty"`
85-
UserCreatedPluginCount int `json:"userCreatedPluginCount,omitempty"`
86-
PolicyCount map[string]int `json:"policyCount,omitempty"`
87-
AppliedPolicyRowCount map[string]int `json:"appliedPolicyRowCount,omitempty"`
88-
PhysicalClusterCount int `json:"physicalClusterCount,omitempty"`
89-
IsolatedClusterCount int `json:"isolatedClusterCount,omitempty"`
79+
HelmAppCount int `json:"helmAppCount,omitempty"`
80+
DevtronAppCount int `json:"devtronAppCount,omitempty"`
81+
JobCount int `json:"jobCount,omitempty"`
82+
JobPipelineCount int `json:"jobPipelineCount,omitempty"`
83+
JobPipelineTriggeredLast24h int `json:"jobPipelineTriggeredLast24h,omitempty"`
84+
JobPipelineSucceededLast24h int `json:"jobPipelineSucceededLast24h,omitempty"`
85+
UserCreatedPluginCount int `json:"userCreatedPluginCount,omitempty"`
86+
PolicyCount int `json:"policyCount,omitempty"`
87+
AppliedPolicyRowCount int `json:"appliedPolicyRowCount,omitempty"`
88+
PhysicalClusterCount int `json:"physicalClusterCount,omitempty"`
89+
IsolatedClusterCount int `json:"isolatedClusterCount,omitempty"`
9090
}
9191

9292
const AppsCount int = 50
@@ -149,15 +149,15 @@ type TelemetryEventDto struct {
149149
ExternalHelmAppClusterCount map[int32]int `json:"ExternalHelmAppClusterCount"`
150150
ClusterProvider string `json:"clusterProvider,omitempty"`
151151
// New telemetry fields
152-
HelmAppCount int `json:"helmAppCount,omitempty"`
153-
DevtronAppCount int `json:"devtronAppCount,omitempty"`
154-
JobCount int `json:"jobCount,omitempty"`
155-
JobPipelineCount int `json:"jobPipelineCount,omitempty"`
156-
JobPipelineTriggeredLast24h int `json:"jobPipelineTriggeredLast24h,omitempty"`
157-
JobPipelineSucceededLast24h int `json:"jobPipelineSucceededLast24h,omitempty"`
158-
UserCreatedPluginCount int `json:"userCreatedPluginCount,omitempty"`
159-
PolicyCount map[string]int `json:"policyCount,omitempty"`
160-
AppliedPolicyRowCount map[string]int `json:"appliedPolicyRowCount,omitempty"`
161-
PhysicalClusterCount int `json:"physicalClusterCount,omitempty"`
162-
IsolatedClusterCount int `json:"isolatedClusterCount,omitempty"`
152+
HelmAppCount int `json:"helmAppCount,omitempty"`
153+
DevtronAppCount int `json:"devtronAppCount,omitempty"`
154+
JobCount int `json:"jobCount,omitempty"`
155+
JobPipelineCount int `json:"jobPipelineCount,omitempty"`
156+
JobPipelineTriggeredLast24h int `json:"jobPipelineTriggeredLast24h,omitempty"`
157+
JobPipelineSucceededLast24h int `json:"jobPipelineSucceededLast24h,omitempty"`
158+
UserCreatedPluginCount int `json:"userCreatedPluginCount,omitempty"`
159+
PolicyCount int `json:"policyCount,omitempty"`
160+
AppliedPolicyRowCount int `json:"appliedPolicyRowCount,omitempty"`
161+
PhysicalClusterCount int `json:"physicalClusterCount,omitempty"`
162+
IsolatedClusterCount int `json:"isolatedClusterCount,omitempty"`
163163
}

client/telemetry/telemetryQueries.go

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

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+
)
47

58
func (impl *TelemetryEventClientImpl) getHelmAppCount() int {
69
count, err := impl.installedAppReadService.GetActiveInstalledAppCount()
@@ -31,12 +34,6 @@ func (impl *TelemetryEventClientImpl) getJobCount() int {
3134
}
3235

3336
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-
4037
// Get all user-created plugins (SHARED type)
4138
plugins, err := impl.pluginRepository.GetAllPluginMinDataByType(string(repository.PLUGIN_TYPE_SHARED))
4239
if err != nil {
@@ -47,74 +44,13 @@ func (impl *TelemetryEventClientImpl) getUserCreatedPluginCount() int {
4744
return len(plugins)
4845
}
4946

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)
11452
}
115-
116-
impl.logger.Debugw("policy count", "count", policyCount)
117-
return policyCount
53+
return len(globalPolicies)
11854
}
11955

12056
func (impl *TelemetryEventClientImpl) getClusterCounts() (physicalCount int, isolatedCount int) {
@@ -139,42 +75,10 @@ func (impl *TelemetryEventClientImpl) getClusterCounts() (physicalCount int, iso
13975
}
14076

14177
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
16979
}
17080

17181
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-
17882
// Get build type and status data for the last 24 hours
17983
buildTypeStatusData := impl.ciWorkflowRepository.FindBuildTypeAndStatusDataOfLast1Day()
18084
if buildTypeStatusData == nil {
@@ -186,42 +90,15 @@ func (impl *TelemetryEventClientImpl) getJobPipelineTriggeredLast24h() int {
18690
// Job pipelines have build type "CI_JOB"
18791
jobTriggeredCount := 0
18892
for _, data := range buildTypeStatusData {
189-
if data.Type == "CI_JOB" {
93+
if data.Type == string(common.CI_JOB) {
19094
jobTriggeredCount += data.Count
19195
}
19296
}
19397

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-
21598
return jobTriggeredCount
21699
}
217100

218101
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-
225102
// Get build type and status data for the last 24 hours
226103
buildTypeStatusData := impl.ciWorkflowRepository.FindBuildTypeAndStatusDataOfLast1Day()
227104
if buildTypeStatusData == nil {
@@ -242,47 +119,6 @@ func (impl *TelemetryEventClientImpl) getJobPipelineSucceededLast24h() int {
242119
return successfulJobCount
243120
}
244121

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
288124
}

0 commit comments

Comments
 (0)