Skip to content

Commit 6e196cb

Browse files
committed
Merge branch 'main' into create-cm-on-cluster-action-oss
# Conflicts: # env_gen.json # go.mod # go.sum # pkg/delete/DeleteService.go # vendor/modules.txt
2 parents 9a085b5 + 69a5263 commit 6e196cb

File tree

168 files changed

+12594
-743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+12594
-743
lines changed

App.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type App struct {
5656
server *http.Server
5757
db *pg.DB
5858
posthogClient *posthogTelemetry.PosthogClient
59+
userService user.UserService
5960
// eventProcessor.CentralEventProcessor is used to register event processors
6061
centralEventProcessor *eventProcessor.CentralEventProcessor // do not remove this.
6162
// used for local dev only
@@ -79,6 +80,7 @@ func NewApp(router *router.MuxRouter,
7980
pubSubClient *pubsub.PubSubClientServiceImpl,
8081
workflowEventProcessorImpl *in.WorkflowEventProcessorImpl,
8182
enforcerV2 *casbinv2.SyncedEnforcer,
83+
userService user.UserService,
8284
) *App {
8385
//check argo connection
8486
//todo - check argo-cd version on acd integration installation
@@ -97,6 +99,7 @@ func NewApp(router *router.MuxRouter,
9799
centralEventProcessor: centralEventProcessor,
98100
pubSubClient: pubSubClient,
99101
workflowEventProcessorImpl: workflowEventProcessorImpl,
102+
userService: userService,
100103
}
101104
return app
102105
}
@@ -112,7 +115,7 @@ func (app *App) Start() {
112115
app.MuxRouter.Init()
113116
//authEnforcer := casbin2.Create()
114117

115-
server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: authMiddleware.Authorizer(app.sessionManager2, user.WhitelistChecker, nil)(app.MuxRouter.Router)}
118+
server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: authMiddleware.Authorizer(app.sessionManager2, user.WhitelistChecker, app.userService.CheckUserStatusAndUpdateLoginAudit)(app.MuxRouter.Router)}
116119
app.MuxRouter.Router.Use(app.loggingMiddleware.LoggingMiddleware)
117120
app.MuxRouter.Router.Use(middleware.PrometheusMiddleware)
118121
app.MuxRouter.Router.Use(middlewares.Recovery)

Wire.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ func InitializeApp() (*App, error) {
303303
pipeline.NewCiMaterialConfigServiceImpl,
304304
wire.Bind(new(pipeline.CiMaterialConfigService), new(*pipeline.CiMaterialConfigServiceImpl)),
305305

306+
app.NewDeploymentEventHandlerImpl,
307+
wire.Bind(new(app.DeploymentEventHandler), new(*app.DeploymentEventHandlerImpl)),
308+
306309
pipeline.NewAppArtifactManagerImpl,
307310
wire.Bind(new(pipeline.AppArtifactManager), new(*pipeline.AppArtifactManagerImpl)),
308311
pipeline.NewDevtronAppCMCSServiceImpl,

api/bean/AppView/AppView.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type GenericNoteResponseBean struct {
6464
Description string `json:"description"`
6565
UpdatedBy string `json:"updatedBy"`
6666
UpdatedOn time.Time `json:"updatedOn"`
67+
CreatedBy string `json:"createdBy"`
6768
}
6869

6970
type JobContainer struct {
@@ -100,6 +101,7 @@ type JobListingContainer struct {
100101
LastTriggeredEnvironmentName string `sql:"last_triggered_environment_name" json:"lastTriggeredEnvironmentName"`
101102
LastTriggeredEnvironmentId int `sql:"last_triggered_environment_id" json:"lastEnvironmentId"`
102103
ProjectId int `sql:"team_id" json:"projectId"`
104+
CreatedBy int32 `sql:"created_by" json:"createdBy"`
103105
}
104106

105107
type CiPipelineLastSucceededTime struct {

api/k8s/application/k8sApplicationRestHandler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ func (handler *K8sApplicationRestHandlerImpl) CreateEphemeralContainer(w http.Re
10251025
return
10261026
}
10271027
request.UserId = userId
1028+
request.ExternalArgoAppIdentifier = resourceRequestBean.ExternalArgoAppIdentifier
1029+
10281030
err = handler.k8sApplicationService.CreatePodEphemeralContainers(&request)
10291031
if err != nil {
10301032
handler.logger.Errorw("error occurred in creating ephemeral container", "err", err, "requestPayload", request)
@@ -1073,6 +1075,7 @@ func (handler *K8sApplicationRestHandlerImpl) DeleteEphemeralContainer(w http.Re
10731075
return
10741076
}
10751077
request.UserId = userId
1078+
request.ExternalArgoAppIdentifier = resourceRequestBean.ExternalArgoAppIdentifier
10761079
_, err = handler.k8sApplicationService.TerminatePodEphemeralContainer(request)
10771080
if err != nil {
10781081
handler.logger.Errorw("error occurred in terminating ephemeral container", "err", err, "requestPayload", request)
@@ -1156,6 +1159,7 @@ func (handler *K8sApplicationRestHandlerImpl) verifyRbacForAppRequests(token str
11561159
handler.logger.Errorw("error in decoding appId", "err", err, "appId", request.AppId)
11571160
return false, err
11581161
}
1162+
request.ExternalArgoAppIdentifier = argoAppIdentifier
11591163
request.ClusterId = argoAppIdentifier.ClusterId
11601164
request.ExternalArgoApplicationName = argoAppIdentifier.AppName
11611165
valid, err := handler.argoApplicationReadService.ValidateArgoResourceRequest(r.Context(), argoAppIdentifier, request.K8sRequest)

api/restHandler/app/pipeline/AutoCompleteRestHandler.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package pipeline
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"github.com/devtron-labs/devtron/pkg/auth/user"
2324
"github.com/devtron-labs/devtron/pkg/build/git/gitProvider/read"
@@ -93,6 +94,24 @@ func (handler DevtronAppAutoCompleteRestHandlerImpl) GetAppListForAutocomplete(w
9394
v := r.URL.Query()
9495
teamId := v.Get("teamId")
9596
appName := v.Get("appName")
97+
offset := 0
98+
size := 0 // default value is 0, it means if not provided in query param it will fetch all
99+
sizeStr := v.Get("size")
100+
if sizeStr != "" {
101+
size, err = strconv.Atoi(sizeStr)
102+
if err != nil || size < 0 {
103+
common.WriteJsonResp(w, errors.New("invalid size"), nil, http.StatusBadRequest)
104+
return
105+
}
106+
}
107+
offsetStr := v.Get("offset")
108+
if offsetStr != "" {
109+
offset, err = strconv.Atoi(offsetStr)
110+
if err != nil || offset < 0 {
111+
common.WriteJsonResp(w, errors.New("invalid offset"), nil, http.StatusBadRequest)
112+
return
113+
}
114+
}
96115
appTypeParam := v.Get("appType")
97116
var appType int
98117
if appTypeParam != "" {
@@ -131,6 +150,7 @@ func (handler DevtronAppAutoCompleteRestHandlerImpl) GetAppListForAutocomplete(w
131150
}
132151
}
133152
if isActionUserSuperAdmin {
153+
apps = handler.getPaginatedResultsForApps(offset, size, apps)
134154
common.WriteJsonResp(w, err, apps, http.StatusOK)
135155
return
136156
}
@@ -161,6 +181,7 @@ func (handler DevtronAppAutoCompleteRestHandlerImpl) GetAppListForAutocomplete(w
161181
}
162182
span.End()
163183
// RBAC
184+
accessedApps = handler.getPaginatedResultsForApps(offset, size, accessedApps)
164185
common.WriteJsonResp(w, err, accessedApps, http.StatusOK)
165186
}
166187

@@ -290,3 +311,14 @@ func (handler DevtronAppAutoCompleteRestHandlerImpl) TeamListAutocomplete(w http
290311

291312
common.WriteJsonResp(w, err, result, http.StatusOK)
292313
}
314+
315+
func (handler DevtronAppAutoCompleteRestHandlerImpl) getPaginatedResultsForApps(offset int, size int, apps []*pipeline.AppBean) []*pipeline.AppBean {
316+
if size > 0 {
317+
if offset+size <= len(apps) {
318+
apps = apps[offset : offset+size]
319+
} else {
320+
apps = apps[offset:]
321+
}
322+
}
323+
return apps
324+
}

client/telemetry/TelemetryEventClient.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ func (impl *TelemetryEventClientImpl) SummaryDetailsForTelemetry() (cluster []be
263263
return clusters, users, k8sServerVersion, hostURL, ssoSetup, HelmAppAccessCount, ChartStoreVisitCount, SkippedOnboarding, HelmAppUpdateCounter, helmChartSuccessfulDeploymentCount, ExternalHelmAppClusterCount
264264
}
265265

266+
// New methods for collecting additional telemetry metrics
267+
266268
func (impl *TelemetryEventClientImpl) SummaryEventForTelemetryEA() {
267269
err := impl.SendSummaryEvent(string(Summary))
268270
if err != nil {
@@ -310,6 +312,11 @@ func (impl *TelemetryEventClientImpl) SendSummaryEvent(eventType string) error {
310312
payload.HelmChartSuccessfulDeploymentCount = helmChartSuccessfulDeploymentCount
311313
payload.ExternalHelmAppClusterCount = ExternalHelmAppClusterCount
312314

315+
// Collect EA-mode compatible telemetry metrics
316+
payload.HelmAppCount = impl.getHelmAppCount()
317+
payload.PhysicalClusterCount, payload.IsolatedClusterCount = impl.getClusterCounts()
318+
payload.ActiveUsersLast30Days = impl.getActiveUsersLast30Days()
319+
313320
payload.ClusterProvider, err = impl.GetCloudProvider()
314321
if err != nil {
315322
impl.logger.Errorw("error while getting cluster provider", "error", err)

client/telemetry/TelemetryEventClientExtended.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
installedAppReader "github.com/devtron-labs/devtron/pkg/appStore/installedApp/read"
2727
"github.com/devtron-labs/devtron/pkg/auth/sso"
2828
user2 "github.com/devtron-labs/devtron/pkg/auth/user"
29+
authPolicyRepository "github.com/devtron-labs/devtron/pkg/auth/user/repository"
2930
"github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/read"
3031
repository3 "github.com/devtron-labs/devtron/pkg/build/git/gitProvider/repository"
3132
"github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
@@ -34,6 +35,8 @@ import (
3435
"github.com/devtron-labs/devtron/pkg/cluster/environment"
3536
"github.com/devtron-labs/devtron/pkg/deployment/gitOps/config"
3637
moduleRepo "github.com/devtron-labs/devtron/pkg/module/repo"
38+
pluginRepository "github.com/devtron-labs/devtron/pkg/plugin/repository"
39+
cvePolicyRepository "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/repository"
3740
serverDataStore "github.com/devtron-labs/devtron/pkg/server/store"
3841
ucidService "github.com/devtron-labs/devtron/pkg/ucid"
3942
util3 "github.com/devtron-labs/devtron/pkg/util"
@@ -68,6 +71,11 @@ type TelemetryEventClientImplExtended struct {
6871
chartRepository chartRepoRepository.ChartRepository
6972
ciBuildConfigService pipeline.CiBuildConfigService
7073
gitOpsConfigReadService config.GitOpsConfigReadService
74+
// Additional repositories for FULL-mode telemetry metrics
75+
pluginRepository pluginRepository.GlobalPluginRepository
76+
cvePolicyRepository cvePolicyRepository.CvePolicyRepository
77+
defaultAuthPolicyRepository authPolicyRepository.DefaultAuthPolicyRepository
78+
rbacPolicyRepository authPolicyRepository.RbacPolicyDataRepository
7179
*TelemetryEventClientImpl
7280
}
7381

@@ -85,7 +93,12 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
8593
ciBuildConfigService pipeline.CiBuildConfigService, moduleRepository moduleRepo.ModuleRepository, serverDataStore *serverDataStore.ServerDataStore,
8694
helmAppClient client.HelmAppClient, installedAppReadService installedAppReader.InstalledAppReadService, userAttributesRepository repository.UserAttributesRepository,
8795
cloudProviderIdentifierService cloudProviderIdentifier.ProviderIdentifierService, cronLogger *cron3.CronLoggerImpl,
88-
gitOpsConfigReadService config.GitOpsConfigReadService, envVariables *util.EnvironmentVariables) (*TelemetryEventClientImplExtended, error) {
96+
gitOpsConfigReadService config.GitOpsConfigReadService, envVariables *util.EnvironmentVariables,
97+
// Optional repositories for additional telemetry metrics
98+
pluginRepository pluginRepository.GlobalPluginRepository,
99+
cvePolicyRepository cvePolicyRepository.CvePolicyRepository,
100+
defaultAuthPolicyRepository authPolicyRepository.DefaultAuthPolicyRepository,
101+
rbacPolicyRepository authPolicyRepository.RbacPolicyDataRepository) (*TelemetryEventClientImplExtended, error) {
89102

90103
cron := cron.New(
91104
cron.WithChain(cron.Recover(cronLogger)))
@@ -105,6 +118,11 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
105118
chartRepository: chartRepository,
106119
ciBuildConfigService: ciBuildConfigService,
107120
gitOpsConfigReadService: gitOpsConfigReadService,
121+
// Initialize FULL-mode specific repositories
122+
pluginRepository: pluginRepository,
123+
cvePolicyRepository: cvePolicyRepository,
124+
defaultAuthPolicyRepository: defaultAuthPolicyRepository,
125+
rbacPolicyRepository: rbacPolicyRepository,
108126
TelemetryEventClientImpl: &TelemetryEventClientImpl{
109127
cron: cron,
110128
logger: logger,
@@ -319,6 +337,21 @@ func (impl *TelemetryEventClientImplExtended) SendSummaryEvent(eventType string)
319337
payload.HelmChartSuccessfulDeploymentCount = HelmChartSuccessfulDeploymentCount
320338
payload.ExternalHelmAppClusterCount = ExternalHelmAppClusterCount
321339

340+
// Collect new telemetry metrics
341+
payload.HelmAppCount = impl.getHelmAppCount()
342+
payload.DevtronAppCount = impl.getDevtronAppCount()
343+
payload.JobCount = impl.getJobCount()
344+
payload.JobPipelineCount = impl.getJobPipelineCount()
345+
payload.JobPipelineTriggeredLast24h = impl.getJobPipelineTriggeredLast24h()
346+
payload.JobPipelineSucceededLast24h = impl.getJobPipelineSucceededLast24h()
347+
payload.UserCreatedPluginCount = impl.getUserCreatedPluginCount()
348+
payload.PolicyCount = impl.getPolicyCount()
349+
payload.AppliedPolicyRowCount = impl.getAppliedPolicyRowCount()
350+
payload.PhysicalClusterCount, payload.IsolatedClusterCount = impl.getClusterCounts()
351+
payload.ActiveUsersLast30Days = impl.getActiveUsersLast30Days()
352+
payload.GitOpsPipelineCount = impl.getGitOpsPipelineCount()
353+
payload.HelmPipelineCount = impl.helmPipelineCount()
354+
322355
payload.ClusterProvider, err = impl.GetCloudProvider()
323356
if err != nil {
324357
impl.logger.Errorw("error while getting cluster provider", "error", err)
@@ -374,7 +407,11 @@ func (impl *TelemetryEventClientImplExtended) getCiBuildTypeData() (int, int, in
374407
func (impl *TelemetryEventClientImplExtended) getCiBuildTypeVsStatusVsCount() (successCount map[bean.CiBuildType]int, failureCount map[bean.CiBuildType]int) {
375408
successCount = make(map[bean.CiBuildType]int)
376409
failureCount = make(map[bean.CiBuildType]int)
377-
buildTypeAndStatusVsCount := impl.ciWorkflowRepository.FindBuildTypeAndStatusDataOfLast1Day()
410+
buildTypeAndStatusVsCount, err := impl.ciWorkflowRepository.FindBuildTypeAndStatusDataOfLast1Day()
411+
if err != nil {
412+
impl.logger.Errorw("error getting build type vs status vs count data", "err", err)
413+
return successCount, failureCount
414+
}
378415
for _, buildTypeCount := range buildTypeAndStatusVsCount {
379416
if buildTypeCount == nil {
380417
continue

client/telemetry/bean.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ type TelemetryEventEA struct {
7575
HelmChartSuccessfulDeploymentCount int `json:"helmChartSuccessfulDeploymentCount,omitempty"`
7676
ExternalHelmAppClusterCount map[int32]int `json:"ExternalHelmAppClusterCount,omitempty"`
7777
ClusterProvider string `json:"clusterProvider,omitempty"`
78+
// New telemetry fields
79+
HelmAppCount int `json:"helmAppCount,omitempty"`
80+
PhysicalClusterCount int `json:"physicalClusterCount,omitempty"`
81+
IsolatedClusterCount int `json:"isolatedClusterCount,omitempty"`
82+
ActiveUsersLast30Days int `json:"activeUsersLast30Days,omitempty"`
7883
}
7984

8085
const AppsCount int = 50
@@ -136,4 +141,19 @@ type TelemetryEventDto struct {
136141
HelmChartSuccessfulDeploymentCount int `json:"helmChartSuccessfulDeploymentCount,omitempty"`
137142
ExternalHelmAppClusterCount map[int32]int `json:"ExternalHelmAppClusterCount"`
138143
ClusterProvider string `json:"clusterProvider,omitempty"`
144+
// New telemetry fields
145+
HelmAppCount int `json:"helmAppCount,omitempty"`
146+
DevtronAppCount int `json:"devtronAppCount,omitempty"`
147+
JobCount int `json:"jobCount,omitempty"`
148+
JobPipelineCount int `json:"jobPipelineCount,omitempty"`
149+
JobPipelineTriggeredLast24h int `json:"jobPipelineTriggeredLast24h,omitempty"`
150+
JobPipelineSucceededLast24h int `json:"jobPipelineSucceededLast24h,omitempty"`
151+
UserCreatedPluginCount int `json:"userCreatedPluginCount,omitempty"`
152+
PolicyCount int `json:"policyCount,omitempty"`
153+
AppliedPolicyRowCount int `json:"appliedPolicyRowCount,omitempty"`
154+
PhysicalClusterCount int `json:"physicalClusterCount,omitempty"`
155+
IsolatedClusterCount int `json:"isolatedClusterCount,omitempty"`
156+
ActiveUsersLast30Days int `json:"activeUsersLast30Days,omitempty"`
157+
GitOpsPipelineCount int `json:"gitOpsPipelineCount,omitempty"`
158+
HelmPipelineCount int `json:"helmPipelineCount,omitempty"`
139159
}

client/telemetry/telemetryQueries.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package telemetry
2+
3+
// EA-mode compatible telemetry queries - no imports needed for current methods
4+
5+
func (impl *TelemetryEventClientImpl) getHelmAppCount() int {
6+
if impl.installedAppReadService == nil {
7+
impl.logger.Warnw("installedAppReadService not available for helm app count")
8+
return -1
9+
}
10+
count, err := impl.installedAppReadService.GetActiveInstalledAppCount()
11+
if err != nil {
12+
impl.logger.Errorw("error getting helm app count", "err", err)
13+
return -1
14+
}
15+
return count
16+
}
17+
18+
// EA-mode compatible telemetry methods
19+
20+
func (impl *TelemetryEventClientImpl) getClusterCounts() (physicalCount int, isolatedCount int) {
21+
clusters, err := impl.clusterService.FindAllActive()
22+
if err != nil {
23+
impl.logger.Errorw("error getting cluster counts", "err", err)
24+
return -1, -1
25+
}
26+
27+
physicalCount = 0
28+
isolatedCount = 0
29+
30+
for _, cluster := range clusters {
31+
if cluster.IsVirtualCluster {
32+
isolatedCount++
33+
} else {
34+
physicalCount++
35+
}
36+
}
37+
38+
return physicalCount, isolatedCount
39+
}
40+
41+
// Note: FULL-mode specific methods like getDevtronAppCount, getJobCount, etc.
42+
// are now implemented in TelemetryEventClientImplExtended in telemetryQueriesExtended.go
43+
44+
func (impl *TelemetryEventClientImpl) getActiveUsersLast30Days() int {
45+
if impl.userAuditService == nil {
46+
impl.logger.Warnw("userAuditService not available for active users count")
47+
return -1
48+
}
49+
50+
count, err := impl.userAuditService.GetActiveUsersCountInLast30Days()
51+
if err != nil {
52+
impl.logger.Errorw("error getting active users count in last 30 days", "err", err)
53+
return -1
54+
}
55+
56+
impl.logger.Debugw("counted active users in last 30 days", "count", count)
57+
return count
58+
}

0 commit comments

Comments
 (0)