Skip to content

Commit

Permalink
delete cluster telemetry + hide modal on failure (#4327)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feroze Mohideen authored Feb 26, 2024
1 parent 7049f69 commit f7ec352
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions api/server/handlers/cluster/delete.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cluster

import (
"fmt"
"net/http"

"connectrpc.com/connect"
Expand All @@ -14,6 +13,7 @@ import (
"github.com/porter-dev/porter/api/types"
"github.com/porter-dev/porter/internal/models"
"github.com/porter-dev/porter/internal/repository"
"github.com/porter-dev/porter/internal/telemetry"
)

type ClusterDeleteHandler struct {
Expand All @@ -32,20 +32,22 @@ func NewClusterDeleteHandler(
}

func (c *ClusterDeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx, span := telemetry.NewSpan(r.Context(), "serve-delete-cluster")
defer span.End()

cluster, _ := ctx.Value(types.ClusterScope).(*models.Cluster)

if cluster.ProvisionedBy == "CAPI" {
if c.Config().EnableCAPIProvisioner {
revisions, err := c.Config().Repo.APIContractRevisioner().List(ctx, cluster.ProjectID, repository.WithClusterID(cluster.ID))
if err != nil {
e := fmt.Errorf("error listing revisions for cluster %d: %w", cluster.ID, err)
c.HandleAPIError(w, r, apierrors.NewErrInternal(e))
err = telemetry.Error(ctx, span, err, "error listing revisions for cluster")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
return
}
if cluster.Status == types.UpdatingUnavailable || cluster.Status == types.Updating {
e := fmt.Errorf("unable to delete cluster %d that is updating", cluster.ID)
c.HandleAPIError(w, r, apierrors.NewErrInternal(e))
err = telemetry.Error(ctx, span, nil, "unable to delete cluster that is updating")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
return
}
var revisionID string
Expand All @@ -64,16 +66,17 @@ func (c *ClusterDeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
})
_, err = c.Config().ClusterControlPlaneClient.DeleteCluster(ctx, cl)
if err != nil {
e := fmt.Errorf("error deleting cluster %d: %w", cluster.ID, err)
c.HandleAPIError(w, r, apierrors.NewErrInternal(e))
err = telemetry.Error(ctx, span, err, "error deleting cluster")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
return
}
}
}

err := c.Repo().Cluster().DeleteCluster(cluster)
if err != nil {
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
err = telemetry.Error(ctx, span, err, "error deleting cluster")
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const Settings: React.FC = () => {
try {
setIsSubmitting(true);
await deleteCluster();
setCurrentOverlay(null);
history.push("/infrastructure");
} catch (err) {
showIntercomWithMessage({
Expand All @@ -65,6 +64,7 @@ const Settings: React.FC = () => {
setErrorMessage(message);
} finally {
setIsSubmitting(false);
setCurrentOverlay(null);
}
};

Expand Down

0 comments on commit f7ec352

Please sign in to comment.