Skip to content

Commit

Permalink
fix: Skip detection reporting for infra if super (#1630)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahmmcgivern authored Jul 12, 2024
1 parent c11bef6 commit 2bae647
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
26 changes: 25 additions & 1 deletion internal/install/recipe_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"errors"
"fmt"
"github.com/fatih/color"
"os"
"regexp"
"strconv"
"time"

"github.com/fatih/color"

log "github.com/sirupsen/logrus"

"github.com/newrelic/newrelic-cli/internal/cli"
Expand Down Expand Up @@ -372,6 +373,10 @@ func (i *RecipeInstall) reportRecipeStatuses(availableRecipes recipes.RecipeDete
i.status.ReportStatus(d.Status, e)
}
for _, d := range availableRecipes {
if i.shouldSkipReporting(d.Recipe.Name) {
continue
}

e := execution.RecipeStatusEvent{Recipe: *d.Recipe, ValidationDurationMs: d.DurationMs}
i.status.ReportStatus(execution.RecipeStatusTypes.DETECTED, e)
}
Expand All @@ -380,10 +385,29 @@ func (i *RecipeInstall) reportRecipeStatuses(availableRecipes recipes.RecipeDete
func (i *RecipeInstall) reportRecipeRecommendations(availableRecipes recipes.RecipeDetectionResults) {
recipeRecommendations := i.getRecipeRecommendations(availableRecipes)
for _, e := range recipeRecommendations {
if i.shouldSkipReporting(e.Recipe.Name) {
continue
}

i.status.ReportStatus(execution.RecipeStatusTypes.RECOMMENDED, e)
}
}

// Skip reporting for the infra agent if super agent has been targeted.
// The logs-integration also reports a status for the infra agent
// and should be skipped as well.
func (i *RecipeInstall) shouldSkipReporting(name string) bool {
if name == "infrastructure-agent-installer" || name == "logs-integration" {
for _, v := range i.RecipeNames {
if v == "super-agent" || v == "logs-integration-super-agent" {
return true
}
}
}

return false
}

// Report recommendations for recipes that are available but have not been attempted to be installed
func (i *RecipeInstall) getRecipeRecommendations(availableRecipes recipes.RecipeDetectionResults) []execution.RecipeStatusEvent {
isTargetedInstall := i.RecipeNamesProvided() && len(i.RecipeNames) > 0
Expand Down
30 changes: 30 additions & 0 deletions internal/install/recipe_installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,36 @@ func TestInstallOHIAdditionalShouldInstallOnSuperAgentInstalled(t *testing.T) {
assert.Equal(t, 1, statusReporter.ReportInstalled[r2.Recipe.Name], "Recipe Installed")
}

func TestShouldSkipReporting(t *testing.T) {
// Target a recipe
recipeInstall := NewRecipeInstallBuilder().WithTargetRecipeName("super-agent").Build()
// Should this recipe be skipped as a result?
b := recipeInstall.shouldSkipReporting("infrastructure-agent-installer")
assert.Equal(t, true, b, "Super Agent with Infrastructure Agent targeted")

recipeInstall = NewRecipeInstallBuilder().WithTargetRecipeName("super-agent").Build()
b = recipeInstall.shouldSkipReporting("logs-integration")
assert.Equal(t, true, b, "Super Agent Provided")

recipeInstall = NewRecipeInstallBuilder().WithTargetRecipeName("logs-integration-super-agent").Build()
b = recipeInstall.shouldSkipReporting("infrastructure-agent-installer")
assert.Equal(t, true, b, "Super Agent Provided")

recipeInstall = NewRecipeInstallBuilder().WithTargetRecipeName("logs-integration-super-agent").Build()
b = recipeInstall.shouldSkipReporting("logs-integration")
assert.Equal(t, true, b, "Super Agent Provided")

// Super Agent / Logs not included -> should return false

recipeInstall = NewRecipeInstallBuilder().Build()
b = recipeInstall.shouldSkipReporting("infrastructure-agent-installer")
assert.Equal(t, false, b, "Super Agent Provided")

recipeInstall = NewRecipeInstallBuilder().Build()
b = recipeInstall.shouldSkipReporting("logs-integration")
assert.Equal(t, false, b, "Super Agent Provided")
}

func TestPromptIfNotLatestCliVersionDoesNotLogMessagesOrErrorWhenVersionsMatch(t *testing.T) {
getLatestCliVersionReleased = func(ctx context.Context) (string, error) {
return "latest-version", nil
Expand Down

0 comments on commit 2bae647

Please sign in to comment.