Skip to content

Commit 1f04e54

Browse files
authored
Task/update summary (#1661)
* Add Fields for Summary * Add Fields for Summary * Add Fields for Summary * Testing purpose * update payload * update payload * update payload * wire changes * update payload * update payload * update as per PR comments * refactoring code
1 parent 74638da commit 1f04e54

File tree

9 files changed

+200
-74
lines changed

9 files changed

+200
-74
lines changed

client/telemetry/TelemetryEventClient.go

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import (
55
"encoding/json"
66
"fmt"
77
"github.com/devtron-labs/devtron/api/bean"
8+
"github.com/devtron-labs/devtron/internal/sql/repository"
89
util2 "github.com/devtron-labs/devtron/internal/util"
10+
"github.com/devtron-labs/devtron/pkg/attributes"
911
"github.com/devtron-labs/devtron/pkg/cluster"
12+
"github.com/devtron-labs/devtron/pkg/sso"
1013
"github.com/devtron-labs/devtron/pkg/user"
1114
util3 "github.com/devtron-labs/devtron/pkg/util"
1215
"github.com/devtron-labs/devtron/util"
@@ -25,14 +28,16 @@ import (
2528
)
2629

2730
type TelemetryEventClientImpl struct {
28-
cron *cron.Cron
29-
logger *zap.SugaredLogger
30-
client *http.Client
31-
clusterService cluster.ClusterService
32-
K8sUtil *util2.K8sUtil
33-
aCDAuthConfig *util3.ACDAuthConfig
34-
userService user.UserService
35-
PosthogClient *PosthogClient
31+
cron *cron.Cron
32+
logger *zap.SugaredLogger
33+
client *http.Client
34+
clusterService cluster.ClusterService
35+
K8sUtil *util2.K8sUtil
36+
aCDAuthConfig *util3.ACDAuthConfig
37+
userService user.UserService
38+
attributeRepo repository.AttributesRepository
39+
ssoLoginService sso.SSOLoginService
40+
PosthogClient *PosthogClient
3641
}
3742

3843
type TelemetryEventClient interface {
@@ -44,6 +49,7 @@ type TelemetryEventClient interface {
4449

4550
func NewTelemetryEventClientImpl(logger *zap.SugaredLogger, client *http.Client, clusterService cluster.ClusterService,
4651
K8sUtil *util2.K8sUtil, aCDAuthConfig *util3.ACDAuthConfig, userService user.UserService,
52+
attributeRepo repository.AttributesRepository, ssoLoginService sso.SSOLoginService,
4753
PosthogClient *PosthogClient) (*TelemetryEventClientImpl, error) {
4854
cron := cron.New(
4955
cron.WithChain())
@@ -53,7 +59,9 @@ func NewTelemetryEventClientImpl(logger *zap.SugaredLogger, client *http.Client,
5359
logger: logger,
5460
client: client, clusterService: clusterService,
5561
K8sUtil: K8sUtil, aCDAuthConfig: aCDAuthConfig,
56-
userService: userService, PosthogClient: PosthogClient,
62+
userService: userService, attributeRepo: attributeRepo,
63+
ssoLoginService: ssoLoginService,
64+
PosthogClient: PosthogClient,
5765
}
5866

5967
watcher.HeartbeatEventForTelemetry()
@@ -76,19 +84,18 @@ func (impl *TelemetryEventClientImpl) StopCron() {
7684
}
7785

7886
type TelemetryEventEA struct {
79-
UCID string `json:"ucid"` //unique client id
80-
Timestamp time.Time `json:"timestamp"`
81-
EventMessage string `json:"eventMessage,omitempty"`
82-
EventType TelemetryEventType `json:"eventType"`
83-
Summary *SummaryEA `json:"summary,omitempty"`
84-
ServerVersion string `json:"serverVersion,omitempty"`
85-
DevtronVersion string `json:"devtronVersion,omitempty"`
86-
DevtronMode string `json:"devtronMode,omitempty"`
87-
}
88-
89-
type SummaryEA struct {
90-
UserCount int `json:"userCount,omitempty"`
91-
ClusterCount int `json:"clusterCount,omitempty"`
87+
UCID string `json:"ucid"` //unique client id
88+
Timestamp time.Time `json:"timestamp"`
89+
EventMessage string `json:"eventMessage,omitempty"`
90+
EventType TelemetryEventType `json:"eventType"`
91+
//Summary *SummaryEA `json:"summary,omitempty"`
92+
ServerVersion string `json:"serverVersion,omitempty"`
93+
UserCount int `json:"userCount,omitempty"`
94+
ClusterCount int `json:"clusterCount,omitempty"`
95+
HostURL bool `json:"hostURL,omitempty"`
96+
SSOLogin bool `json:"ssoLogin,omitempty"`
97+
DevtronVersion string `json:"devtronVersion,omitempty"`
98+
DevtronMode string `json:"devtronMode,omitempty"`
9299
}
93100

94101
const DevtronUniqueClientIdConfigMap = "devtron-ucid"
@@ -116,7 +123,7 @@ const (
116123
DashboardLoggedIn TelemetryEventType = "DashboardLoggedIn"
117124
)
118125

119-
func (impl *TelemetryEventClientImpl) SummaryDetailsForTelemetry() (cluster []cluster.ClusterBean, user []bean.UserInfo, k8sServerVersion *version.Info) {
126+
func (impl *TelemetryEventClientImpl) SummaryDetailsForTelemetry() (cluster []cluster.ClusterBean, user []bean.UserInfo, k8sServerVersion *version.Info, hostURL bool, ssoSetup bool) {
120127
discoveryClient, err := impl.K8sUtil.GetK8sDiscoveryClientInCluster()
121128
if err != nil {
122129
impl.logger.Errorw("exception caught inside telemetry summary event", "err", err)
@@ -139,7 +146,22 @@ func (impl *TelemetryEventClientImpl) SummaryDetailsForTelemetry() (cluster []cl
139146
impl.logger.Errorw("exception caught inside telemetry summary event", "err", err)
140147
return
141148
}
142-
return clusters, users, k8sServerVersion
149+
150+
hostURL = false
151+
152+
attribute, err := impl.attributeRepo.FindByKey(attributes.HostUrlKey)
153+
if err == nil && attribute.Id > 0 {
154+
hostURL = true
155+
}
156+
157+
ssoSetup = false
158+
159+
ssoConfig, err := impl.ssoLoginService.GetAll()
160+
if err == nil && len(ssoConfig) > 0 {
161+
ssoSetup = true
162+
}
163+
164+
return clusters, users, k8sServerVersion, hostURL, ssoSetup
143165
}
144166

145167
func (impl *TelemetryEventClientImpl) SummaryEventForTelemetryEA() {
@@ -154,17 +176,15 @@ func (impl *TelemetryEventClientImpl) SummaryEventForTelemetryEA() {
154176
return
155177
}
156178

157-
clusters, users, k8sServerVersion := impl.SummaryDetailsForTelemetry()
179+
clusters, users, k8sServerVersion, hostURL, ssoSetup := impl.SummaryDetailsForTelemetry()
158180

159181
payload := &TelemetryEventEA{UCID: ucid, Timestamp: time.Now(), EventType: Summary, DevtronVersion: "v1"}
160182
payload.ServerVersion = k8sServerVersion.String()
161183
payload.DevtronMode = util.GetDevtronVersion().ServerMode
162-
163-
summary := &SummaryEA{
164-
UserCount: len(users),
165-
ClusterCount: len(clusters),
166-
}
167-
payload.Summary = summary
184+
payload.HostURL = hostURL
185+
payload.SSOLogin = ssoSetup
186+
payload.UserCount = len(users)
187+
payload.ClusterCount = len(clusters)
168188

169189
reqBody, err := json.Marshal(payload)
170190
if err != nil {

client/telemetry/TelemetryEventClientExtended.go

Lines changed: 111 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package telemetry
33
import (
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

1921
type 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

2735
func 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

6788
type 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

91119
func (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 {

cmd/external-app/wire.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/devtron-labs/devtron/client/argocdServer/session"
2323
"github.com/devtron-labs/devtron/client/dashboard"
2424
"github.com/devtron-labs/devtron/client/telemetry"
25+
"github.com/devtron-labs/devtron/internal/sql/repository"
2526
app2 "github.com/devtron-labs/devtron/internal/sql/repository/app"
2627
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
2728
"github.com/devtron-labs/devtron/internal/util"
@@ -86,6 +87,8 @@ func InitializeApp() (*App, error) {
8687
wire.Bind(new(pipelineConfig.PipelineRepository), new(*pipelineConfig.PipelineRepositoryImpl)),
8788
app2.NewAppRepositoryImpl,
8889
wire.Bind(new(app2.AppRepository), new(*app2.AppRepositoryImpl)),
90+
repository.NewAttributesRepositoryImpl,
91+
wire.Bind(new(repository.AttributesRepository), new(*repository.AttributesRepositoryImpl)),
8992
pipelineConfig.NewCiPipelineRepositoryImpl,
9093
wire.Bind(new(pipelineConfig.CiPipelineRepository), new(*pipelineConfig.CiPipelineRepositoryImpl)),
9194
// // needed for enforcer util ends

cmd/external-app/wire_gen.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)