@@ -24,12 +24,8 @@ import (
2424 "fmt"
2525 cloudProviderIdentifier "github.com/devtron-labs/common-lib/cloud-provider-identifier"
2626 posthogTelemetry "github.com/devtron-labs/common-lib/telemetry"
27- "github.com/devtron-labs/common-lib/utils/k8s/commonBean"
2827 "github.com/devtron-labs/devtron/api/helm-app/gRPC"
2928 installedAppReader "github.com/devtron-labs/devtron/pkg/appStore/installedApp/read"
30- bean2 "github.com/devtron-labs/devtron/pkg/attributes/bean"
31- "github.com/devtron-labs/devtron/pkg/auth/user/bean"
32- bean3 "github.com/devtron-labs/devtron/pkg/cluster/bean"
3329 module2 "github.com/devtron-labs/devtron/pkg/module/bean"
3430 ucidService "github.com/devtron-labs/devtron/pkg/ucid"
3531 cron3 "github.com/devtron-labs/devtron/util/cron"
@@ -49,9 +45,7 @@ import (
4945 "github.com/go-pg/pg"
5046 "github.com/posthog/posthog-go"
5147 "github.com/robfig/cron/v3"
52- "github.com/tidwall/gjson"
5348 "go.uber.org/zap"
54- "k8s.io/apimachinery/pkg/version"
5549)
5650
5751type TelemetryEventClientImpl struct {
@@ -154,115 +148,6 @@ func (impl *TelemetryEventClientImpl) StopCron() {
154148 impl .cron .Stop ()
155149}
156150
157- func (impl * TelemetryEventClientImpl ) SummaryDetailsForTelemetry () (cluster []bean3.ClusterBean , user []bean.UserInfo ,
158- k8sServerVersion * version.Info , hostURL bool , ssoSetup bool , HelmAppAccessCount string , ChartStoreVisitCount string ,
159- SkippedOnboarding bool , HelmAppUpdateCounter string , helmChartSuccessfulDeploymentCount int , ExternalHelmAppClusterCount map [int32 ]int ) {
160-
161- discoveryClient , err := impl .K8sUtil .GetK8sDiscoveryClientInCluster ()
162- if err != nil {
163- impl .logger .Errorw ("exception caught inside telemetry summary event" , "err" , err )
164- return
165- }
166- k8sServerVersion , err = discoveryClient .ServerVersion ()
167- if err != nil {
168- impl .logger .Errorw ("exception caught inside telemetry summary event" , "err" , err )
169- return
170- }
171-
172- users , err := impl .userService .GetAll ()
173- if err != nil && err != pg .ErrNoRows {
174- impl .logger .Errorw ("exception caught inside telemetry summery event" , "err" , err )
175- return
176- }
177-
178- clusters , err := impl .clusterService .FindAllActive ()
179-
180- if err != nil && err != pg .ErrNoRows {
181- impl .logger .Errorw ("exception caught inside telemetry summary event" , "err" , err )
182- return
183- }
184-
185- hostURL = false
186-
187- attribute , err := impl .attributeRepo .FindByKey (bean2 .HostUrlKey )
188- if err == nil && attribute .Id > 0 {
189- hostURL = true
190- }
191-
192- attribute , err = impl .attributeRepo .FindByKey ("HelmAppAccessCounter" )
193-
194- if err == nil {
195- HelmAppAccessCount = attribute .Value
196- }
197-
198- attribute , err = impl .attributeRepo .FindByKey ("ChartStoreVisitCount" )
199-
200- if err == nil {
201- ChartStoreVisitCount = attribute .Value
202- }
203-
204- attribute , err = impl .attributeRepo .FindByKey ("HelmAppUpdateCounter" )
205-
206- if err == nil {
207- HelmAppUpdateCounter = attribute .Value
208- }
209-
210- helmChartSuccessfulDeploymentCount , err = impl .installedAppReadService .GetDeploymentSuccessfulStatusCountForTelemetry ()
211-
212- //externalHelmCount := make(map[int32]int)
213- ExternalHelmAppClusterCount = make (map [int32 ]int )
214-
215- for _ , clusterDetail := range clusters {
216- req := & gRPC.AppListRequest {}
217- config := & gRPC.ClusterConfig {
218- ApiServerUrl : clusterDetail .ServerUrl ,
219- Token : clusterDetail .Config [commonBean .BearerToken ],
220- ClusterId : int32 (clusterDetail .Id ),
221- ClusterName : clusterDetail .ClusterName ,
222- InsecureSkipTLSVerify : clusterDetail .InsecureSkipTLSVerify ,
223- }
224-
225- if clusterDetail .InsecureSkipTLSVerify == false {
226- config .KeyData = clusterDetail .Config [commonBean .TlsKey ]
227- config .CertData = clusterDetail .Config [commonBean .CertData ]
228- config .CaData = clusterDetail .Config [commonBean .CertificateAuthorityData ]
229- }
230- req .Clusters = append (req .Clusters , config )
231- applicationStream , err := impl .helmAppClient .ListApplication (context .Background (), req )
232- if err == nil {
233- clusterList , err1 := applicationStream .Recv ()
234- if err1 != nil {
235- impl .logger .Errorw ("error in list helm applications streams recv" , "err" , err )
236- }
237- if err1 != nil && clusterList != nil && ! clusterList .Errored {
238- ExternalHelmAppClusterCount [clusterList .ClusterId ] = len (clusterList .DeployedAppDetail )
239- }
240- } else {
241- impl .logger .Errorw ("error while fetching list application from kubelink" , "err" , err )
242- }
243- }
244-
245- //getting userData from emailId
246- userData , err := impl .userAttributesRepository .GetUserDataByEmailId (AdminEmailIdConst )
247-
248- SkippedOnboardingValue := gjson .Get (userData , SkippedOnboardingConst ).Str
249-
250- if SkippedOnboardingValue == "true" {
251- SkippedOnboarding = true
252- } else {
253- SkippedOnboarding = false
254- }
255-
256- ssoSetup = false
257-
258- ssoConfig , err := impl .ssoLoginService .GetAll ()
259- if err == nil && len (ssoConfig ) > 0 {
260- ssoSetup = true
261- }
262-
263- return clusters , users , k8sServerVersion , hostURL , ssoSetup , HelmAppAccessCount , ChartStoreVisitCount , SkippedOnboarding , HelmAppUpdateCounter , helmChartSuccessfulDeploymentCount , ExternalHelmAppClusterCount
264- }
265-
266151// New methods for collecting additional telemetry metrics
267152
268153func (impl * TelemetryEventClientImpl ) SummaryEventForTelemetryEA () {
@@ -291,7 +176,7 @@ func (impl *TelemetryEventClientImpl) SendSummaryEvent(eventType string) error {
291176 return err
292177 }
293178
294- clusters , users , k8sServerVersion , hostURL , ssoSetup , HelmAppAccessCount , ChartStoreVisitCount , SkippedOnboarding , HelmAppUpdateCounter , helmChartSuccessfulDeploymentCount , ExternalHelmAppClusterCount := impl .SummaryDetailsForTelemetry ()
179+ clusters , users , k8sServerVersion , hostURL , ssoSetup , HelmAppAccessCount , ChartStoreVisitCount , SkippedOnboarding , HelmAppUpdateCounter , helmChartSuccessfulDeploymentCount , ExternalHelmAppClusterCount := impl .GetSummaryDetailsForTelemetry ()
295180
296181 payload := & TelemetryEventEA {UCID : ucid , Timestamp : time .Now (), EventType : TelemetryEventType (eventType ), DevtronVersion : "v1" }
297182 payload .ServerVersion = k8sServerVersion .String ()
0 commit comments