From 7874c10284a2aaa3f6c8c96df1f15281e15d1574 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 | 22 +++++++++++++++++++ internal/install/types/recipe.go | 1 + 3 files changed, 24 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 bc41efa7b..8fb604978 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" @@ -582,6 +583,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() + se := execution.RecipeStatusEvent{ Recipe: *r, Msg: msg, @@ -665,6 +669,24 @@ func (i *RecipeInstall) optInToSendLogsAndUpdateRecipeMetadata(recipeName string } } +func (i *RecipeInstall) askToReRunInDebugMode() { + 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 infra 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{}