@@ -3,9 +3,11 @@ package telemetry
33import (
44 "encoding/json"
55 "github.com/devtron-labs/devtron/internal/sql/repository"
6+ "github.com/devtron-labs/devtron/internal/sql/repository/app"
67 "github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
78 util2 "github.com/devtron-labs/devtron/internal/util"
89 "github.com/devtron-labs/devtron/pkg/cluster"
10+ "github.com/devtron-labs/devtron/pkg/sso"
911 "github.com/devtron-labs/devtron/pkg/user"
1012 util3 "github.com/devtron-labs/devtron/pkg/util"
1113 "github.com/devtron-labs/devtron/util"
@@ -17,35 +19,54 @@ import (
1719)
1820
1921type TelemetryEventClientImplExtended struct {
20- environmentService cluster.EnvironmentService
21- appListingRepository repository.AppListingRepository
22- ciPipelineRepository pipelineConfig.CiPipelineRepository
23- pipelineRepository pipelineConfig.PipelineRepository
22+ environmentService cluster.EnvironmentService
23+ appListingRepository repository.AppListingRepository
24+ ciPipelineRepository pipelineConfig.CiPipelineRepository
25+ pipelineRepository pipelineConfig.PipelineRepository
26+ gitHostRepository repository.GitHostRepository
27+ gitProviderRepository repository.GitProviderRepository
28+ dockerArtifactStoreRepository repository.DockerArtifactStoreRepository
29+ appRepository app.AppRepository
30+ ciWorkflowRepository pipelineConfig.CiWorkflowRepository
31+ cdWorkflowRepository pipelineConfig.CdWorkflowRepository
2432 * TelemetryEventClientImpl
2533}
2634
2735func NewTelemetryEventClientImplExtended (logger * zap.SugaredLogger , client * http.Client , clusterService cluster.ClusterService ,
2836 K8sUtil * util2.K8sUtil , aCDAuthConfig * util3.ACDAuthConfig ,
2937 environmentService cluster.EnvironmentService , userService user.UserService ,
3038 appListingRepository repository.AppListingRepository , PosthogClient * PosthogClient ,
31- ciPipelineRepository pipelineConfig.CiPipelineRepository , pipelineRepository pipelineConfig.PipelineRepository ) (* TelemetryEventClientImplExtended , error ) {
39+ ciPipelineRepository pipelineConfig.CiPipelineRepository , pipelineRepository pipelineConfig.PipelineRepository ,
40+ gitHostRepository repository.GitHostRepository , gitProviderRepository repository.GitProviderRepository ,
41+ attributeRepo repository.AttributesRepository , ssoLoginService sso.SSOLoginService , appRepository app.AppRepository ,
42+ ciWorkflowRepository pipelineConfig.CiWorkflowRepository , cdWorkflowRepository pipelineConfig.CdWorkflowRepository ,
43+ dockerArtifactStoreRepository repository.DockerArtifactStoreRepository ) (* TelemetryEventClientImplExtended , error ) {
3244
3345 cron := cron .New (
3446 cron .WithChain ())
3547 cron .Start ()
3648 watcher := & TelemetryEventClientImplExtended {
37- environmentService : environmentService ,
38- appListingRepository : appListingRepository ,
39- ciPipelineRepository : ciPipelineRepository , pipelineRepository : pipelineRepository ,
49+ environmentService : environmentService ,
50+ appListingRepository : appListingRepository ,
51+ ciPipelineRepository : ciPipelineRepository ,
52+ pipelineRepository : pipelineRepository ,
53+ gitHostRepository : gitHostRepository ,
54+ gitProviderRepository : gitProviderRepository ,
55+ dockerArtifactStoreRepository : dockerArtifactStoreRepository ,
56+ appRepository : appRepository ,
57+ cdWorkflowRepository : cdWorkflowRepository ,
58+ ciWorkflowRepository : ciWorkflowRepository ,
4059 TelemetryEventClientImpl : & TelemetryEventClientImpl {
41- cron : cron ,
42- logger : logger ,
43- client : client ,
44- clusterService : clusterService ,
45- K8sUtil : K8sUtil ,
46- aCDAuthConfig : aCDAuthConfig ,
47- userService : userService ,
48- PosthogClient : PosthogClient ,
60+ cron : cron ,
61+ logger : logger ,
62+ client : client ,
63+ clusterService : clusterService ,
64+ K8sUtil : K8sUtil ,
65+ aCDAuthConfig : aCDAuthConfig ,
66+ userService : userService ,
67+ attributeRepo : attributeRepo ,
68+ ssoLoginService : ssoLoginService ,
69+ PosthogClient : PosthogClient ,
4970 },
5071 }
5172
@@ -65,17 +86,11 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
6586}
6687
6788type TelemetryEventDto struct {
68- UCID string `json:"ucid"` //unique client id
69- Timestamp time.Time `json:"timestamp"`
70- EventMessage string `json:"eventMessage,omitempty"`
71- EventType TelemetryEventType `json:"eventType"`
72- Summary * SummaryDto `json:"summary,omitempty"`
73- ServerVersion string `json:"serverVersion,omitempty"`
74- DevtronVersion string `json:"devtronVersion,omitempty"`
75- DevtronMode string `json:"devtronMode,omitempty"`
76- }
77-
78- type SummaryDto struct {
89+ UCID string `json:"ucid"` //unique client id
90+ Timestamp time.Time `json:"timestamp"`
91+ EventMessage string `json:"eventMessage,omitempty"`
92+ EventType TelemetryEventType `json:"eventType"`
93+ //Summary *SummaryDto `json:"summary,omitempty"`
7994 ProdAppCount int `json:"prodAppCount,omitempty"`
8095 NonProdAppCount int `json:"nonProdAppCount,omitempty"`
8196 UserCount int `json:"userCount,omitempty"`
@@ -85,7 +100,20 @@ type SummaryDto struct {
85100 CdCountPerDay int `json:"cdCountPerDay,omitempty"`
86101 HelmChartCount int `json:"helmChartCount,omitempty"`
87102 SecurityScanCountPerDay int `json:"securityScanCountPerDay,omitempty"`
103+ GitAccountsCount int `json:"gitAccountsCount,omitempty"`
104+ GitOpsCount int `json:"gitOpsCount,omitempty"`
105+ RegistryCount int `json:"registryCount,omitempty"`
106+ HostURL bool `json:"hostURL,omitempty"`
107+ SSOLogin bool `json:"ssoLogin,omitempty"`
108+ CiSetup bool `json:"ciSetup,omitempty"`
109+ CdSetup bool `json:"cdSetup,omitempty"`
110+ AppSetup bool `json:"appSetup,omitempty"`
111+ Build bool `json:"build,omitempty"`
112+ Deployment bool `json:"deployment,omitempty"`
113+ ServerVersion string `json:"serverVersion,omitempty"`
114+ DevtronGitVersion string `json:"devtronGitVersion,omitempty"`
88115 DevtronVersion string `json:"devtronVersion,omitempty"`
116+ DevtronMode string `json:"devtronMode,omitempty"`
89117}
90118
91119func (impl * TelemetryEventClientImplExtended ) SummaryEventForTelemetry () {
@@ -100,7 +128,7 @@ func (impl *TelemetryEventClientImplExtended) SummaryEventForTelemetry() {
100128 return
101129 }
102130
103- clusters , users , k8sServerVersion := impl .SummaryDetailsForTelemetry ()
131+ clusters , users , k8sServerVersion , hostURL , ssoSetup := impl .SummaryDetailsForTelemetry ()
104132 payload := & TelemetryEventDto {UCID : ucid , Timestamp : time .Now (), EventType : Summary , DevtronVersion : "v1" }
105133 payload .ServerVersion = k8sServerVersion .String ()
106134
@@ -134,19 +162,63 @@ func (impl *TelemetryEventClientImplExtended) SummaryEventForTelemetry() {
134162 return
135163 }
136164
165+ gitAccounts , err := impl .gitProviderRepository .FindAll ()
166+ if err != nil && err != pg .ErrNoRows {
167+ impl .logger .Errorw ("exception caught inside telemetry summary event" , "err" , err )
168+ return
169+ }
170+
171+ gitOps , err := impl .gitHostRepository .FindAll ()
172+ if err != nil && err != pg .ErrNoRows {
173+ impl .logger .Errorw ("exception caught inside telemetry summary event" , "err" , err )
174+ return
175+ }
176+
177+ containerRegistry , err := impl .dockerArtifactStoreRepository .FindAll ()
178+ if err != nil && err != pg .ErrNoRows {
179+ impl .logger .Errorw ("exception caught inside telemetry summary event" , "err" , err )
180+ return
181+ }
182+
183+ appSetup := false
184+ applications , err := impl .appRepository .FindAll ()
185+ if err != nil {
186+ impl .logger .Errorw ("exception caught inside telemetry summary event" , "err" , err )
187+ }
188+
189+ if len (applications ) > 0 {
190+ appSetup = true
191+ }
192+
193+ ciSetup , err := impl .ciPipelineRepository .Exists ()
194+
195+ cdSetup , err := impl .pipelineRepository .Exists ()
196+
197+ build , err := impl .ciWorkflowRepository .ExistsByStatus ("Succeeded" )
198+
199+ deployment , err := impl .cdWorkflowRepository .ExistsByStatus ("Healthy" )
200+
137201 devtronVersion := util .GetDevtronVersion ()
202+ payload .ProdAppCount = prodApps
203+ payload .NonProdAppCount = nonProdApps
204+ payload .RegistryCount = len (containerRegistry )
205+ payload .SSOLogin = ssoSetup
206+ payload .GitOpsCount = len (gitOps )
207+ payload .UserCount = len (users )
208+ payload .EnvironmentCount = len (environments )
209+ payload .ClusterCount = len (clusters )
210+ payload .CiCountPerDay = len (ciPipeline )
211+ payload .CdCountPerDay = len (cdPipeline )
212+ payload .GitAccountsCount = len (gitAccounts )
213+ payload .GitOpsCount = len (gitOps )
214+ payload .HostURL = hostURL
215+ payload .DevtronGitVersion = devtronVersion .GitCommit
216+ payload .CiSetup = ciSetup
217+ payload .CdSetup = cdSetup
218+ payload .AppSetup = appSetup
219+ payload .Build = build
220+ payload .Deployment = deployment
138221
139- summary := & SummaryDto {
140- ProdAppCount : prodApps ,
141- NonProdAppCount : nonProdApps ,
142- UserCount : len (users ),
143- EnvironmentCount : len (environments ),
144- ClusterCount : len (clusters ),
145- CiCountPerDay : len (ciPipeline ),
146- CdCountPerDay : len (cdPipeline ),
147- DevtronVersion : devtronVersion .GitCommit ,
148- }
149- payload .Summary = summary
150222 payload .DevtronMode = devtronVersion .ServerMode
151223 reqBody , err := json .Marshal (payload )
152224 if err != nil {
0 commit comments