diff --git a/api/server/handlers/release/update_image_batch.go b/api/server/handlers/release/update_image_batch.go index abaa6f4f70..4ca9874dae 100644 --- a/api/server/handlers/release/update_image_batch.go +++ b/api/server/handlers/release/update_image_batch.go @@ -70,6 +70,16 @@ func (c *UpdateImageBatchHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque return } + printReleases := func(releases []*models.Release) string { + var names []string + for _, release := range releases { + names = append(names, fmt.Sprintf("%s-%s", release.Name, release.Namespace)) + } + return strings.Join(names, ",") + } + + telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "releases", Value: printReleases(releases)}) + var namespaceScopedReleases []*models.Release for _, release := range releases { if release.Namespace == helmAgent.Namespace() { @@ -77,6 +87,8 @@ func (c *UpdateImageBatchHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque } } + telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "releases-in-namespace", Value: printReleases(namespaceScopedReleases)}) + registries, err := c.Repo().Registry().ListRegistriesByProjectID(cluster.ProjectID) if err != nil { err = telemetry.Error(ctx, span, err, "error listing registries by project id") @@ -89,15 +101,22 @@ func (c *UpdateImageBatchHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque mu := &sync.Mutex{} errs := make([]string, 0) - for i := range namespaceScopedReleases { + for i, rel := range namespaceScopedReleases { wg.Add(1) - go func(index int) { + go func(release *models.Release, i int) { + defer wg.Done() + ctx, span := telemetry.NewSpan(ctx, "update-image-batch") defer span.End() - defer wg.Done() + + telemetry.WithAttributes(span, + telemetry.AttributeKV{Key: "release-name", Value: release.Name}, + telemetry.AttributeKV{Key: "release-index", Value: i}, + ) + // read release via agent - rel, err := helmAgent.GetRelease(ctx, namespaceScopedReleases[index].Name, 0, false) + rel, err := helmAgent.GetRelease(ctx, release.Name, 0, false) if err != nil { err = telemetry.Error(ctx, span, err, "error getting release") // if this is a release not found error, just return - the release has likely been deleted from the underlying @@ -107,20 +126,20 @@ func (c *UpdateImageBatchHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque } mu.Lock() - errs = append(errs, fmt.Sprintf("Error for %s, index %d: %s", namespaceScopedReleases[index].Name, index, err.Error())) + errs = append(errs, fmt.Sprintf("Error for %s, index %d: %s", release.Name, i, err.Error())) mu.Unlock() return } if rel.Chart.Name() == "job" { image := map[string]interface{}{} - image["repository"] = namespaceScopedReleases[index].ImageRepoURI + image["repository"] = release.ImageRepoURI image["tag"] = request.Tag rel.Config["image"] = image rel.Config["paused"] = true conf := &helm.UpgradeReleaseConfig{ - Name: namespaceScopedReleases[index].Name, + Name: release.Name, Cluster: cluster, Repo: c.Repo(), Registries: registries, @@ -137,11 +156,11 @@ func (c *UpdateImageBatchHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque } mu.Lock() - errs = append(errs, fmt.Sprintf("Error for %s, index %d: %s", namespaceScopedReleases[index].Name, index, err.Error())) + errs = append(errs, fmt.Sprintf("Error for %s, index %d: %s", release.Name, i, err.Error())) mu.Unlock() } } - }(i) + }(rel, i) } wg.Wait()