From 7f9d1629ac207289002349e08108d36fea7b2c70 Mon Sep 17 00:00:00 2001 From: nithyatsu Date: Fri, 15 Sep 2023 14:15:14 -0700 Subject: [PATCH] add log entry in case of receipe failure --- .../backend/controller/createorupdateresource.go | 6 ++++++ pkg/recipes/engine/engine.go | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/portableresources/backend/controller/createorupdateresource.go b/pkg/portableresources/backend/controller/createorupdateresource.go index b911c676f4d..fe03f10c69f 100644 --- a/pkg/portableresources/backend/controller/createorupdateresource.go +++ b/pkg/portableresources/backend/controller/createorupdateresource.go @@ -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" @@ -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. @@ -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{ @@ -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 } diff --git a/pkg/recipes/engine/engine.go b/pkg/recipes/engine/engine.go index 5772a173f23..ef812035b73 100644 --- a/pkg/recipes/engine/engine.go +++ b/pkg/recipes/engine/engine.go @@ -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. @@ -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