From fd00784d304bac13f35b314f8fc13f4c6d84cff5 Mon Sep 17 00:00:00 2001 From: NSSPKrishna Date: Thu, 20 Jun 2024 19:21:34 +0530 Subject: [PATCH] fix: Updated fall back error message --- .../install/execution/recipe_log_forwarder.go | 2 +- internal/install/recipe_installer.go | 23 +++++++++++++++++++ internal/install/types/recipe.go | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/install/execution/recipe_log_forwarder.go b/internal/install/execution/recipe_log_forwarder.go index f410263c3..da3ae99fb 100644 --- a/internal/install/execution/recipe_log_forwarder.go +++ b/internal/install/execution/recipe_log_forwarder.go @@ -106,7 +106,7 @@ func (lf *RecipeLogForwarder) SendLogsToNewRelic(recipeName string, data []strin func (lf *RecipeLogForwarder) buildLogEntryBatch(recipeName string, data []string) { now := time.Now().UnixMilli() for _, line := range data { - now++ //using timestamp to retain log sequence + now++ // using timestamp to retain log sequence lf.LogEntries = append(lf.LogEntries, LogEntry{map[string]interface{}{"nr-install-recipe": recipeName, "timestamp": now}, "cli-output", line}) } } diff --git a/internal/install/recipe_installer.go b/internal/install/recipe_installer.go index 7c19c2fde..e79dc53da 100644 --- a/internal/install/recipe_installer.go +++ b/internal/install/recipe_installer.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/fatih/color" "os" "regexp" "strconv" @@ -581,6 +582,9 @@ func (i *RecipeInstall) executeAndValidate(ctx context.Context, m *types.Discove // opts in/out of sending cli logs, and this must occur before we build the RecipeStatusEvent to post to NR msg := fmt.Sprintf("execution failed for %s: %s", r.Name, err) i.optInToSendLogsAndUpdateRecipeMetadata(r.Name) + // FIX: This should rerun the executed command + i.askToReRunInDebugMode(r.Name) + se := execution.RecipeStatusEvent{ Recipe: *r, Msg: msg, @@ -664,6 +668,25 @@ func (i *RecipeInstall) optInToSendLogsAndUpdateRecipeMetadata(recipeName string } } +func (i *RecipeInstall) askToReRunInDebugMode(recipeName string) { + i.progressIndicator.Fail("Installing " + recipeName) + recipeOutput := i.recipeExecutor.GetRecipeOutput() + logCaptureEnabledForRecipe := i.recipeExecutor.GetOutput().IsCapturedCliOutput() + if len(recipeOutput) > 0 && logCaptureEnabledForRecipe { + i.promptUserToReRun() + } +} + +func (i *RecipeInstall) promptUserToReRun() { + fmt.Printf("\n%s Installation failed. To help identify the issue, you can re-run the installation command with the --debug flag. This will enable verbose logging and provide more detailed information about each step of the installation process. Use the command newrelic install --debug to start the installation with debug mode enabled.", color.YellowString("\u0021")) + + // NOTE: This is only after Infra is installed on the host. If no infa agent is present then root/.newrelic wouldn't be created + if i.processEvaluator.FindProcess(types.InfraAgentProcessName) { + fmt.Printf("\n%s For viewing the logs, please navigate to /root/.newrelic/newrelic-cli.log. ", color.YellowString("\u0021")) + } + +} + type validationFunc func() (string, error) // Post install validation diff --git a/internal/install/types/recipe.go b/internal/install/types/recipe.go index c6f52153d..7d5c3f639 100644 --- a/internal/install/types/recipe.go +++ b/internal/install/types/recipe.go @@ -15,6 +15,7 @@ const ( GoldenRecipeName = "alerts-golden-signal" SuperAgentRecipeName = "super-agent" SuperAgentProcessName = "newrelic-super-agent" + InfraAgentProcessName = "newrelic-infra" ) var RecipeVariables = map[string]string{}