Skip to content

Commit

Permalink
add log entry in case of receipe failure
Browse files Browse the repository at this point in the history
  • Loading branch information
nithyatsu committed Sep 15, 2023
1 parent b38b17e commit 7f9d162
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"context"
"errors"
"fmt"

ctrl "github.com/radius-project/radius/pkg/armrpc/asyncoperation/controller"
"github.com/radius-project/radius/pkg/portableresources/datamodel"
Expand All @@ -29,6 +30,7 @@ import (
"github.com/radius-project/radius/pkg/recipes/util"
rpv1 "github.com/radius-project/radius/pkg/rp/v1"
"github.com/radius-project/radius/pkg/ucp/store"
"github.com/radius-project/radius/pkg/ucp/ucplog"
)

// CreateOrUpdateResource is the async operation controller to create or update portable resources.
Expand Down Expand Up @@ -81,6 +83,8 @@ func (c *CreateOrUpdateResource[P, T]) Run(ctx context.Context, req *ctrl.Reques
recipeOutput, err := c.executeRecipeIfNeeded(ctx, data, previousOutputResources)
if err != nil {
if recipeError, ok := err.(*recipes.RecipeError); ok {
logger := ucplog.FromContextOrDiscard(ctx)
logger.Error(err, fmt.Sprintf("failed to execute recipe. Encounted error while processing %s ", recipeError.ErrorDetails.Target))
// Set the deployment status to the recipe error code.
recipeDataModel.Recipe().DeploymentStatus = util.RecipeDeploymentStatus(recipeError.DeploymentStatus)
update := &store.Object{
Expand All @@ -94,8 +98,10 @@ func (c *CreateOrUpdateResource[P, T]) Run(ctx context.Context, req *ctrl.Reques
if err != nil {
return ctrl.Result{}, err
}

return ctrl.NewFailedResult(recipeError.ErrorDetails), nil
}

return ctrl.Result{}, err
}

Expand Down
3 changes: 0 additions & 3 deletions pkg/recipes/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
recipedriver "github.com/radius-project/radius/pkg/recipes/driver"
"github.com/radius-project/radius/pkg/recipes/util"
rpv1 "github.com/radius-project/radius/pkg/rp/v1"
"github.com/radius-project/radius/pkg/ucp/ucplog"
)

// NewEngine creates a new Engine to deploy recipe.
Expand All @@ -51,13 +50,11 @@ type engine struct {
// configuration associated with the recipe, and then executes the recipe using the driver. It returns a RecipeOutput and
// an error if one occurs.
func (e *engine) Execute(ctx context.Context, opts ExecuteOptions) (*recipes.RecipeOutput, error) {
logger := ucplog.FromContextOrDiscard(ctx)
executionStart := time.Now()
result := metrics.SuccessfulOperationState

recipeOutput, definition, err := e.executeCore(ctx, opts.Recipe, opts.PreviousState)
if err != nil {
logger.Error(err, fmt.Sprintf("failed to execute recipe %s ", opts.Recipe.Name))
result = metrics.FailedOperationState
if recipes.GetRecipeErrorDetails(err) != nil {
result = recipes.GetRecipeErrorDetails(err).Code
Expand Down

0 comments on commit 7f9d162

Please sign in to comment.