Skip to content

Commit 4ec22f6

Browse files
authored
Merge pull request #6199 from devtron-labs/list-application-panic
fix: list application panic handling
2 parents 88a194a + a6e42ef commit 4ec22f6

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

api/helm-app/service/HelmAppService.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/devtron-labs/devtron/api/helm-app/models"
2828
helmBean "github.com/devtron-labs/devtron/api/helm-app/service/bean"
2929
"github.com/devtron-labs/devtron/api/helm-app/service/read"
30+
"github.com/devtron-labs/devtron/api/restHandler/common"
3031
"github.com/devtron-labs/devtron/internal/constants"
3132
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
3233
bean2 "github.com/devtron-labs/devtron/pkg/cluster/bean"
@@ -158,35 +159,45 @@ func GetHelmReleaseConfig() (*HelmReleaseConfig, error) {
158159
func (impl *HelmAppServiceImpl) ListHelmApplications(ctx context.Context, clusterIds []int, w http.ResponseWriter, token string, helmAuth func(token string, object string) bool) {
159160
var helmCdPipelines []*pipelineConfig.Pipeline
160161
var installedHelmApps []*repository.InstalledApps
162+
if len(clusterIds) == 0 {
163+
common.WriteJsonResp(w, util.DefaultApiError().WithHttpStatusCode(http.StatusBadRequest).WithInternalMessage("Invalid payload. Provide cluster ids in request").WithUserMessage("Invalid payload. Provide cluster ids in request"),
164+
nil,
165+
http.StatusBadRequest)
166+
return
167+
}
161168
start := time.Now()
162169
appStream, err := impl.listApplications(ctx, clusterIds)
163170
middleware.AppListingDuration.WithLabelValues("listApplications", "helm").Observe(time.Since(start).Seconds())
164171
if err != nil {
165172
impl.logger.Errorw("error in fetching app list", "clusters", clusterIds, "err", err)
173+
common.WriteJsonResp(w, util.DefaultApiError().WithHttpStatusCode(http.StatusInternalServerError).WithInternalMessage("error in fetching app list").WithUserMessage("error in fetching app list"),
174+
nil,
175+
http.StatusInternalServerError)
176+
return
177+
}
178+
179+
// get helm apps which are created using cd_pipelines
180+
newCtx, span := otel.Tracer("pipelineRepository").Start(ctx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
181+
start = time.Now()
182+
helmCdPipelines, err = impl.pipelineRepository.GetAppAndEnvDetailsForDeploymentAppTypePipeline(util.PIPELINE_DEPLOYMENT_TYPE_HELM, clusterIds)
183+
middleware.AppListingDuration.WithLabelValues("getAppAndEnvDetailsForDeploymentAppTypePipeline", "helm").Observe(time.Since(start).Seconds())
184+
span.End()
185+
if err != nil {
186+
impl.logger.Errorw("error in fetching helm app list from DB created using cd_pipelines", "clusters", clusterIds, "err", err)
166187
}
167-
if err == nil && len(clusterIds) > 0 {
168-
// get helm apps which are created using cd_pipelines
169-
newCtx, span := otel.Tracer("pipelineRepository").Start(ctx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
188+
189+
// if not hyperion mode, then fetch from installed_apps whose deploymentAppType is helm (as in hyperion mode, these apps should be treated as external-apps)
190+
if !util2.IsBaseStack() {
191+
newCtx, span = otel.Tracer("pipelineRepository").Start(newCtx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
170192
start = time.Now()
171-
helmCdPipelines, err = impl.pipelineRepository.GetAppAndEnvDetailsForDeploymentAppTypePipeline(util.PIPELINE_DEPLOYMENT_TYPE_HELM, clusterIds)
172-
middleware.AppListingDuration.WithLabelValues("getAppAndEnvDetailsForDeploymentAppTypePipeline", "helm").Observe(time.Since(start).Seconds())
193+
installedHelmApps, err = impl.installedAppRepository.GetAppAndEnvDetailsForDeploymentAppTypeInstalledApps(util.PIPELINE_DEPLOYMENT_TYPE_HELM, clusterIds)
194+
middleware.AppListingDuration.WithLabelValues("getAppAndEnvDetailsForDeploymentAppTypeInstalledApps", "helm").Observe(time.Since(start).Seconds())
173195
span.End()
174196
if err != nil {
175-
impl.logger.Errorw("error in fetching helm app list from DB created using cd_pipelines", "clusters", clusterIds, "err", err)
176-
}
177-
178-
// if not hyperion mode, then fetch from installed_apps whose deploymentAppType is helm (as in hyperion mode, these apps should be treated as external-apps)
179-
if !util2.IsBaseStack() {
180-
newCtx, span = otel.Tracer("pipelineRepository").Start(newCtx, "GetAppAndEnvDetailsForDeploymentAppTypePipeline")
181-
start = time.Now()
182-
installedHelmApps, err = impl.installedAppRepository.GetAppAndEnvDetailsForDeploymentAppTypeInstalledApps(util.PIPELINE_DEPLOYMENT_TYPE_HELM, clusterIds)
183-
middleware.AppListingDuration.WithLabelValues("getAppAndEnvDetailsForDeploymentAppTypeInstalledApps", "helm").Observe(time.Since(start).Seconds())
184-
span.End()
185-
if err != nil {
186-
impl.logger.Errorw("error in fetching helm app list from DB created from app store", "clusters", clusterIds, "err", err)
187-
}
197+
impl.logger.Errorw("error in fetching helm app list from DB created from app store", "clusters", clusterIds, "err", err)
188198
}
189199
}
200+
190201
impl.pump.StartStreamWithTransformer(w, func() (proto.Message, error) {
191202
return appStream.Recv()
192203
}, err,

0 commit comments

Comments
 (0)