Sfoglia il codice sorgente

feat: add telemetry for the cluster status endpoint (#3610)

jose-fully-ported 2 anni fa
parent
commit
078792cff0
1 ha cambiato i file con 16 aggiunte e 6 eliminazioni
  1. 16 6
      api/server/handlers/cluster/cluster_status.go

+ 16 - 6
api/server/handlers/cluster/cluster_status.go

@@ -13,6 +13,7 @@ import (
 	"github.com/porter-dev/porter/api/server/shared/config"
 	"github.com/porter-dev/porter/api/types"
 	"github.com/porter-dev/porter/internal/models"
+	"github.com/porter-dev/porter/internal/telemetry"
 )
 
 type ClusterStatusHandler struct {
@@ -40,22 +41,25 @@ type ClusterStatusResponse struct {
 }
 
 func (c *ClusterStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	ctx := r.Context()
-	cluster, _ := ctx.Value(types.ClusterScope).(*models.Cluster)
+	ctx, span := telemetry.NewSpan(r.Context(), "serve-cluster-status")
+	defer span.End()
 
+	cluster, _ := ctx.Value(types.ClusterScope).(*models.Cluster)
 	req := connect.NewRequest(&porterv1.ClusterStatusRequest{
 		ProjectId: int64(cluster.ProjectID),
 		ClusterId: int64(cluster.ID),
 	})
 	status, err := c.Config().ClusterControlPlaneClient.ClusterStatus(ctx, req)
 	if err != nil {
-		e := fmt.Errorf("unable to retrieve status for cluster: %w", err)
-		c.HandleAPIError(w, r, apierrors.NewErrInternal(e))
+		err := fmt.Errorf("unable to retrieve status for cluster: %w", err)
+		err = telemetry.Error(ctx, span, err, err.Error())
+		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
 		return
 	}
 	if status.Msg == nil {
-		e := fmt.Errorf("unable to parse status for cluster: %w", err)
-		c.HandleAPIError(w, r, apierrors.NewErrInternal(e))
+		err := fmt.Errorf("unable to parse status for cluster: %w", err)
+		err = telemetry.Error(ctx, span, err, err.Error())
+		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
 		return
 	}
 	statusResp := status.Msg
@@ -68,6 +72,12 @@ func (c *ClusterStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 		IsControlPlaneReady:   statusResp.ControlPlaneStatus,
 	}
 
+	telemetry.WithAttributes(span,
+		telemetry.AttributeKV{Key: "cluster-phase", Value: statusResp.Phase},
+		telemetry.AttributeKV{Key: "cluster-infra-status", Value: statusResp.InfrastructureStatus},
+		telemetry.AttributeKV{Key: "cluster-control-plane-status", Value: statusResp.ControlPlaneStatus},
+	)
+
 	c.WriteResult(w, r, resp)
 	w.WriteHeader(http.StatusOK)
 }