|
|
@@ -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)
|
|
|
}
|