Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Updated fall back error message
Browse files Browse the repository at this point in the history
NSSPKrishna committed Jun 20, 2024
1 parent 77a8ee9 commit fd00784
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/install/execution/recipe_log_forwarder.go
Original file line number Diff line number Diff line change
@@ -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})
}
}
23 changes: 23 additions & 0 deletions internal/install/recipe_installer.go
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions internal/install/types/recipe.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ const (
GoldenRecipeName = "alerts-golden-signal"
SuperAgentRecipeName = "super-agent"
SuperAgentProcessName = "newrelic-super-agent"
InfraAgentProcessName = "newrelic-infra"
)

var RecipeVariables = map[string]string{}

0 comments on commit fd00784

Please sign in to comment.