Skip to content

Commit

Permalink
feat: add telemetry for the cluster status endpoint (#3610)
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-fully-ported authored Sep 20, 2023
1 parent 5830575 commit 078792c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions api/server/handlers/cluster/cluster_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

0 comments on commit 078792c

Please sign in to comment.