Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add telemetry for the cluster status endpoint #3610

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not pass through the err?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just didn't want to change the response here.

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