|
|
@@ -1,6 +1,7 @@
|
|
|
package porter_app
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
"net/http"
|
|
|
|
|
|
"github.com/porter-dev/porter/api/server/authz"
|
|
|
@@ -11,6 +12,8 @@ import (
|
|
|
"github.com/porter-dev/porter/api/server/shared/requestutils"
|
|
|
"github.com/porter-dev/porter/api/types"
|
|
|
"github.com/porter-dev/porter/internal/models"
|
|
|
+ "github.com/porter-dev/porter/internal/telemetry"
|
|
|
+ "gorm.io/gorm"
|
|
|
)
|
|
|
|
|
|
type GetPorterAppHandler struct {
|
|
|
@@ -28,16 +31,30 @@ func NewGetPorterAppHandler(
|
|
|
}
|
|
|
|
|
|
func (c *GetPorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
- ctx := r.Context()
|
|
|
+ ctx, span := telemetry.NewSpan(r.Context(), "serve-get-porter-app")
|
|
|
+
|
|
|
cluster, _ := ctx.Value(types.ClusterScope).(*models.Cluster)
|
|
|
+
|
|
|
stackName, reqErr := requestutils.GetURLParamString(r, types.URLParamStackName)
|
|
|
if reqErr != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(reqErr, http.StatusBadRequest))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ telemetry.WithAttributes(span,
|
|
|
+ telemetry.AttributeKV{Key: "cluster_id", Value: cluster.ID},
|
|
|
+ telemetry.AttributeKV{Key: "project_id", Value: cluster.ProjectID},
|
|
|
+ telemetry.AttributeKV{Key: "stack_name", Value: stackName},
|
|
|
+ )
|
|
|
+
|
|
|
app, err := c.Repo().PorterApp().ReadPorterAppByName(cluster.ID, stackName)
|
|
|
if err != nil {
|
|
|
+ if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ err = telemetry.Error(ctx, span, err, "porter app not found")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusNotFound))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
return
|
|
|
}
|