@@ -27,7 +27,6 @@ import (
27
27
"github.com/devtron-labs/devtron/internal/middleware"
28
28
repository2 "github.com/devtron-labs/devtron/pkg/cluster/repository"
29
29
"go.opentelemetry.io/otel"
30
- "strconv"
31
30
"strings"
32
31
"time"
33
32
@@ -38,7 +37,6 @@ import (
38
37
)
39
38
40
39
type AppListingRepository interface {
41
- FetchAppsByEnvironment (appListingFilter helper.AppListingFilter ) ([]* bean.AppEnvironmentContainer , error )
42
40
FetchJobs (appIds []int , statuses []string , environmentIds []int , sortOrder string ) ([]* bean.JobListingContainer , error )
43
41
FetchOverviewCiPipelines (jobId int ) ([]* bean.JobListingContainer , error )
44
42
FetchJobsLastSucceededOn (ciPipelineIDs []int ) ([]* bean.CiPipelineLastSucceededTime , error )
@@ -47,7 +45,7 @@ type AppListingRepository interface {
47
45
FetchAppTriggerView (appId int ) ([]bean.TriggerView , error )
48
46
FetchAppStageStatus (appId int , appType int ) ([]bean.AppStageStatus , error )
49
47
50
- //Not in used
48
+ // Not in used
51
49
PrometheusApiByEnvId (id int ) (* string , error )
52
50
53
51
FetchOtherEnvironment (appId int ) ([]* bean.Environment , error )
@@ -193,81 +191,6 @@ func getRequiredAppIdsInSequence(appIds []int) []int {
193
191
return resIDs
194
192
}
195
193
196
- func (impl AppListingRepositoryImpl ) FetchAppsByEnvironment (appListingFilter helper.AppListingFilter ) ([]* bean.AppEnvironmentContainer , error ) {
197
- impl .Logger .Debug ("reached at FetchAppsByEnvironment:" )
198
- var appEnvArr []* bean.AppEnvironmentContainer
199
-
200
- query := impl .appListingRepositoryQueryBuilder .BuildAppListingQueryLastDeploymentTime ()
201
- impl .Logger .Debugw ("basic app detail query: " , query )
202
- var lastDeployedTimeDTO []* bean.AppEnvironmentContainer
203
- lastDeployedTimeMap := map [int ]* bean.AppEnvironmentContainer {}
204
- start := time .Now ()
205
- _ , err := impl .dbConnection .Query (& lastDeployedTimeDTO , query )
206
- middleware .AppListingDuration .WithLabelValues ("buildAppListingQueryLastDeploymentTime" , "devtron" ).Observe (time .Since (start ).Seconds ())
207
- if err != nil {
208
- impl .Logger .Error (err )
209
- return appEnvArr , err
210
- }
211
- for _ , item := range lastDeployedTimeDTO {
212
- if _ , ok := lastDeployedTimeMap [item .PipelineId ]; ok {
213
- continue
214
- }
215
- lastDeployedTimeMap [item .PipelineId ] = & bean.AppEnvironmentContainer {
216
- LastDeployedTime : item .LastDeployedTime ,
217
- DataSource : item .DataSource ,
218
- MaterialInfoJson : item .MaterialInfoJson ,
219
- CiArtifactId : item .CiArtifactId ,
220
- }
221
- }
222
-
223
- var appEnvContainer []* bean.AppEnvironmentContainer
224
- appsEnvquery := impl .appListingRepositoryQueryBuilder .BuildAppListingQuery (appListingFilter )
225
- impl .Logger .Debugw ("basic app detail query: " , appsEnvquery )
226
- start = time .Now ()
227
- _ , appsErr := impl .dbConnection .Query (& appEnvContainer , appsEnvquery )
228
- middleware .AppListingDuration .WithLabelValues ("buildAppListingQuery" , "devtron" ).Observe (time .Since (start ).Seconds ())
229
- if appsErr != nil {
230
- impl .Logger .Error (appsErr )
231
- return appEnvContainer , appsErr
232
- }
233
- latestDeploymentStatusMap := map [string ]* bean.AppEnvironmentContainer {}
234
- for _ , item := range appEnvContainer {
235
- if item .EnvironmentId > 0 && item .PipelineId > 0 && item .Active == false {
236
- // skip adding apps which have linked with cd pipeline and that environment has marked as deleted.
237
- continue
238
- }
239
- // include only apps which are not linked with any cd pipeline + those linked with cd pipeline and env has active.
240
- key := strconv .Itoa (item .AppId ) + "_" + strconv .Itoa (item .EnvironmentId )
241
- if _ , ok := latestDeploymentStatusMap [key ]; ok {
242
- continue
243
- }
244
-
245
- if lastDeployedTime , ok := lastDeployedTimeMap [item .PipelineId ]; ok {
246
- item .LastDeployedTime = lastDeployedTime .LastDeployedTime
247
- item .DataSource = lastDeployedTime .DataSource
248
- item .MaterialInfoJson = lastDeployedTime .MaterialInfoJson
249
- item .CiArtifactId = lastDeployedTime .CiArtifactId
250
- }
251
-
252
- if len (item .DataSource ) > 0 {
253
- mInfo , err := parseMaterialInfo (item .MaterialInfoJson , item .DataSource )
254
- if err == nil && len (mInfo ) > 0 {
255
- item .MaterialInfo = mInfo
256
- } else {
257
- item .MaterialInfo = []byte ("[]" )
258
- }
259
- item .MaterialInfoJson = ""
260
- } else {
261
- item .MaterialInfo = []byte ("[]" )
262
- item .MaterialInfoJson = ""
263
- }
264
- appEnvArr = append (appEnvArr , item )
265
- latestDeploymentStatusMap [key ] = item
266
- }
267
-
268
- return appEnvArr , nil
269
- }
270
-
271
194
func (impl AppListingRepositoryImpl ) FetchAppsByEnvironmentV2 (appListingFilter helper.AppListingFilter ) ([]* bean.AppEnvironmentContainer , int , error ) {
272
195
impl .Logger .Debugw ("reached at FetchAppsByEnvironment " , "appListingFilter" , appListingFilter )
273
196
var appEnvArr []* bean.AppEnvironmentContainer
@@ -306,7 +229,7 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
306
229
307
230
} else {
308
231
309
- //to get all the appIds in appEnvs allowed for user and filtered by the appListing filter and sorted by name
232
+ // to get all the appIds in appEnvs allowed for user and filtered by the appListing filter and sorted by name
310
233
appIdCountDtos := make ([]* bean.AppEnvironmentContainer , 0 )
311
234
appIdCountQuery := impl .appListingRepositoryQueryBuilder .GetAppIdsQueryWithPaginationForAppNameSearch (appListingFilter )
312
235
impl .Logger .Debug ("GetAppIdsQueryWithPaginationForAppNameSearch query " , appIdCountQuery )
@@ -327,7 +250,7 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
327
250
uniqueAppIds [i ] = obj .AppId
328
251
}
329
252
appListingFilter .AppIds = uniqueAppIds
330
- //set appids required for this page in the filter and get the appEnv containers of these apps
253
+ // set appids required for this page in the filter and get the appEnv containers of these apps
331
254
appListingFilter .AppIds = uniqueAppIds
332
255
appsEnvquery := impl .appListingRepositoryQueryBuilder .GetQueryForAppEnvContainerss (appListingFilter )
333
256
impl .Logger .Debug ("GetQueryForAppEnvContainerss query: " , appsEnvquery )
@@ -341,8 +264,8 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
341
264
342
265
}
343
266
344
- //filter out unique pipelineIds from the above result and get the deployment times for them
345
- //some items don't have pipelineId if no pipeline is configured for the app in the appEnv container
267
+ // filter out unique pipelineIds from the above result and get the deployment times for them
268
+ // some items don't have pipelineId if no pipeline is configured for the app in the appEnv container
346
269
pipelineIdsSet := make (map [int ]bool )
347
270
pipelineIds := make ([]int , 0 )
348
271
for _ , item := range appEnvContainer {
@@ -353,7 +276,7 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
353
276
}
354
277
}
355
278
356
- //if any pipeline found get the latest deployment time
279
+ // if any pipeline found get the latest deployment time
357
280
if len (pipelineIds ) > 0 {
358
281
query := impl .appListingRepositoryQueryBuilder .BuildAppListingQueryLastDeploymentTimeV2 (pipelineIds )
359
282
impl .Logger .Debugw ("basic app detail query: " , query )
@@ -366,7 +289,7 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
366
289
}
367
290
}
368
291
369
- //get the last deployment time for all the items
292
+ // get the last deployment time for all the items
370
293
for _ , item := range lastDeployedTimeDTO {
371
294
if _ , ok := lastDeployedTimeMap [item .PipelineId ]; ok {
372
295
continue
@@ -375,7 +298,7 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
375
298
376
299
}
377
300
378
- //set the time for corresponding appEnv container
301
+ // set the time for corresponding appEnv container
379
302
for _ , item := range appEnvContainer {
380
303
if lastDeployedTime , ok := lastDeployedTimeMap [item .PipelineId ]; ok {
381
304
item .LastDeployedTime = lastDeployedTime
@@ -483,7 +406,7 @@ func (impl AppListingRepositoryImpl) FetchAppDetail(ctx context.Context, appId i
483
406
var appDetailContainer bean.AppDetailContainer
484
407
newCtx , span := otel .Tracer ("orchestrator" ).Start (ctx , "DeploymentDetailsByAppIdAndEnvId" )
485
408
defer span .End ()
486
- //Fetch deployment detail of cd pipeline latest triggered within env of any App.
409
+ // Fetch deployment detail of cd pipeline latest triggered within env of any App.
487
410
deploymentDetail , err := impl .deploymentDetailsByAppIdAndEnvId (newCtx , appId , envId )
488
411
if err != nil {
489
412
impl .Logger .Warn ("unable to fetch deployment detail for app" )
@@ -511,7 +434,7 @@ func (impl AppListingRepositoryImpl) PrometheusApiByEnvId(id int) (*string, erro
511
434
query := "SELECT env.prometheus_endpoint from environment env" +
512
435
" WHERE env.id = ? AND env.active = TRUE"
513
436
impl .Logger .Debugw ("query" , query )
514
- //environments := []string{"QA"}
437
+ // environments := []string{"QA"}
515
438
_ , err := impl .dbConnection .Query (& prometheusEndpoint , query , id )
516
439
if err != nil {
517
440
impl .Logger .Error ("Exception caught:" , err )
0 commit comments