Skip to content

Commit

Permalink
Merge pull request #642 from newrelic/flowReWork
Browse files Browse the repository at this point in the history
chore(install): rework flow based on output spec
  • Loading branch information
zlesnr authored Jan 27, 2021
2 parents 694e166 + 9b82167 commit be774b6
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 107 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.13
require (
github.com/briandowns/spinner v1.12.0
github.com/client9/misspell v0.3.4
github.com/fatih/color v1.10.0
github.com/git-chglog/git-chglog v0.10.0
github.com/go-task/task/v3 v3.2.2
github.com/golangci/golangci-lint v1.35.2
Expand Down
3 changes: 3 additions & 0 deletions internal/install/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

var (
assumeYes bool
advancedMode bool
recipeNames []string
recipePaths []string
skipDiscovery bool
Expand All @@ -32,6 +33,7 @@ var Command = &cobra.Command{
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
ic := InstallerContext{
AdvancedMode: advancedMode,
AssumeYes: assumeYes,
RecipeNames: recipeNames,
RecipePaths: recipePaths,
Expand Down Expand Up @@ -83,4 +85,5 @@ func init() {
Command.Flags().BoolVar(&debug, "debug", false, "debug level logging")
Command.Flags().BoolVar(&trace, "trace", false, "trace level logging")
Command.Flags().BoolVarP(&assumeYes, "assumeYes", "y", false, "use \"yes\" for all questions during install")
Command.Flags().BoolVarP(&advancedMode, "advanced", "", false, "use \"advanced\" mode")
}
4 changes: 3 additions & 1 deletion internal/install/discovery/psutil_discoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func (p *PSUtilDiscoverer) Discover(ctx context.Context) (*types.DiscoveryManife
var pp *process.Process
pp, err = process.NewProcess(pid)
if err != nil {
log.Debugf("cannot read pid %d: %s", pid, err)
if err != process.ErrorProcessNotRunning {
log.Debugf("cannot read pid %d: %s", pid, err)
}
continue
}

Expand Down
4 changes: 2 additions & 2 deletions internal/install/discovery/regex_process_filterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func (f *RegexProcessFilterer) filter(ctx context.Context, processes []types.Gen
return nil, fmt.Errorf("could not retrieve process filter criteria: %s", err)
}
for _, r := range recipes {
log.Debugf("Match using recipe DisplayName: %s RecipeProcessMatch: %s", r.DisplayName, r.ProcessMatch)
log.Tracef("Match using recipe DisplayName: %s RecipeProcessMatch: %s", r.DisplayName, r.ProcessMatch)
}

matches := []types.MatchedProcess{}
for _, p := range matchedProcesses {
log.Debugf("Match using process command: %s", p.Command)
log.Tracef("Match using process command: %s", p.Command)
isMatch := false
for _, r := range recipes {
isMatch = isMatch || match(r, &p)
Expand Down
18 changes: 15 additions & 3 deletions internal/install/execution/go_task_recipe_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func NewGoTaskRecipeExecutor() *GoTaskRecipeExecutor {
}

func (re *GoTaskRecipeExecutor) Prepare(ctx context.Context, m types.DiscoveryManifest, r types.Recipe, assumeYes bool) (types.RecipeVars, error) {
log.WithFields(log.Fields{
"name": r.Name,
}).Debug("preparing recipe")

vars := types.RecipeVars{}

results := []types.RecipeVars{}
Expand Down Expand Up @@ -212,7 +216,7 @@ func varsFromInput(inputVars []recipes.VariableConfig, assumeYes bool) (types.Re
} else {
log.WithFields(log.Fields{
"name": envConfig.Name,
}).Debug("required env var not found, prompting for input")
}).Debug("required environment variable not found")

envValue, err = varFromPrompt(envConfig)
if err != nil {
Expand All @@ -230,11 +234,19 @@ func varFromPrompt(envConfig recipes.VariableConfig) (string, error) {
msg := fmt.Sprintf("value for %s required", envConfig.Name)

if envConfig.Prompt != "" {
msg = fmt.Sprintf("%s: %s", envConfig.Name, envConfig.Prompt)
msg = envConfig.Prompt
}

templates := &promptui.PromptTemplates{
Prompt: "{{ . | bold }} ",
Valid: "{{ . | bold }} ",
Invalid: "{{ . | bold }} ",
Success: " - {{ . }} ",
}

prompt := promptui.Prompt{
Label: msg,
Label: msg,
Templates: templates,
}

if envConfig.Secret {
Expand Down
4 changes: 3 additions & 1 deletion internal/install/execution/mock_status_reporter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package execution

import "github.com/newrelic/newrelic-cli/internal/install/types"
import (
"github.com/newrelic/newrelic-cli/internal/install/types"
)

// MockStatusReporter is a mock implementation of the ExecutionStatusReporter
// interface that provides method spies for testing scenarios.
Expand Down
5 changes: 5 additions & 0 deletions internal/install/execution/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func (s *StatusRollup) withRecipeEvent(e RecipeStatusEvent, rs StatusType) {
s.withEntityGUID(e.EntityGUID)
}

log.WithFields(log.Fields{
"recipe_name": e.Recipe.Name,
"status": rs,
}).Debug("recipe event")

found := s.getStatus(e.Recipe)

if found != nil {
Expand Down
27 changes: 24 additions & 3 deletions internal/install/execution/terminal_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/newrelic/newrelic-cli/internal/install/types"
log "github.com/sirupsen/logrus"
)

type TerminalStatusReporter struct {
Expand Down Expand Up @@ -33,6 +34,24 @@ func (r TerminalStatusReporter) ReportRecipeSkipped(status *StatusRollup, event
}

func (r TerminalStatusReporter) ReportRecipesAvailable(status *StatusRollup, recipes []types.Recipe) error {
if len(recipes) > 0 {
fmt.Println("The following will be installed, based on what has been discovered on your system.")
}

for _, r := range recipes {
log.WithFields(log.Fields{
"name": r.Name,
}).Debug("found available integration")

if r.DisplayName != "" {
fmt.Printf(" %s\n", r.DisplayName)
} else {
fmt.Printf(" %s\n", r.Name)
}
}

fmt.Println()

return nil
}

Expand All @@ -47,15 +66,17 @@ func (r TerminalStatusReporter) ReportComplete(status *StatusRollup) error {
}

msg := `
Success! Your data is available in New Relic.
Success! Your data is available in New Relic.
Go to New Relic to confirm and start exploring your data.`
Go to New Relic to confirm and start exploring your data.`

fmt.Println(msg)

for _, entityGUID := range status.EntityGUIDs {
fmt.Printf("\n\thttps://one.newrelic.com/redirect/entity/%s\n", entityGUID)
fmt.Printf("\n https://one.newrelic.com/redirect/entity/%s\n", entityGUID)
}

fmt.Println()

return nil
}
10 changes: 10 additions & 0 deletions internal/install/install_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package install

// nolint: maligned
type InstallerContext struct {
AdvancedMode bool
AssumeYes bool
RecipeNames []string
RecipePaths []string
Expand Down Expand Up @@ -38,3 +39,12 @@ func (i *InstallerContext) RecipeNamesProvided() bool {
func (i *InstallerContext) RecipesProvided() bool {
return i.RecipePathsProvided() || i.RecipeNamesProvided()
}

// ShouldPrompt determines if the user should be prompted for input.
func (i *InstallerContext) ShouldPrompt() bool {
if i.AdvancedMode {
return true
}

return i.RecipesProvided() || i.AssumeYes
}
Loading

0 comments on commit be774b6

Please sign in to comment.