Skip to content

Commit

Permalink
Merge pull request #645 from newrelic/queryConstrain
Browse files Browse the repository at this point in the history
chore(install): constrain recipe lookups using discovery manifest
  • Loading branch information
zlesnr authored Jan 27, 2021
2 parents 5b0310c + acc8b65 commit 46ce600
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion internal/install/discovery/process_filterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

type ProcessFilterer interface {
filter(context.Context, []types.GenericProcess) ([]types.MatchedProcess, error)
filter(context.Context, []types.GenericProcess, types.DiscoveryManifest) ([]types.MatchedProcess, error)
}
2 changes: 1 addition & 1 deletion internal/install/discovery/psutil_discoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *PSUtilDiscoverer) Discover(ctx context.Context) (*types.DiscoveryManife
processes = append(processes, PSUtilProcess(*pp))
}

matchedProcesses, err := p.processFilterer.filter(ctx, processes)
matchedProcesses, err := p.processFilterer.filter(ctx, processes, m)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions internal/install/discovery/regex_process_filterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ func NewRegexProcessFilterer(r recipes.RecipeFetcher) *RegexProcessFilterer {
return &f
}

func (f *RegexProcessFilterer) filter(ctx context.Context, processes []types.GenericProcess) ([]types.MatchedProcess, error) {
func (f *RegexProcessFilterer) filter(ctx context.Context, processes []types.GenericProcess, manifest types.DiscoveryManifest) ([]types.MatchedProcess, error) {
matchedProcesses := getMatchedProcesses(processes)
log.Debugf("Filtering recipes with %d processes...", len(matchedProcesses))

recipes, err := f.recipeFetcher.FetchRecipes(ctx)
recipes, err := f.recipeFetcher.FetchRecipes(ctx, &manifest)
if err != nil {
return nil, fmt.Errorf("could not retrieve process filter criteria: %s", err)
}

for _, r := range recipes {
log.Tracef("Match using recipe DisplayName: %s RecipeProcessMatch: %s", r.DisplayName, r.ProcessMatch)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/install/discovery/regex_process_filterer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestFilter(t *testing.T) {
}

f := NewRegexProcessFilterer(mockRecipeFetcher)
filtered, err := f.filter(context.Background(), processes)
filtered, err := f.filter(context.Background(), processes, types.DiscoveryManifest{})

require.NoError(t, err)
require.NotNil(t, filtered)
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestShouldFilterWithCmdLineInsteadOfName(t *testing.T) {
mockRecipeFetcher := recipes.NewMockRecipeFetcher()
mockRecipeFetcher.FetchRecipesVal = r
f := NewRegexProcessFilterer(mockRecipeFetcher)
filtered, err := f.filter(context.Background(), processes)
filtered, err := f.filter(context.Background(), processes, types.DiscoveryManifest{})

require.NoError(t, err)
require.NotNil(t, filtered)
Expand Down
2 changes: 1 addition & 1 deletion internal/install/recipes/mock_recipe_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (f *MockRecipeFetcher) FetchRecipe(ctx context.Context, manifest *types.Dis
return f.FetchRecipeVal, f.FetchRecipeErr
}

func (f *MockRecipeFetcher) FetchRecipes(ctx context.Context) ([]types.Recipe, error) {
func (f *MockRecipeFetcher) FetchRecipes(ctx context.Context, manifest *types.DiscoveryManifest) ([]types.Recipe, error) {
f.FetchRecipesCallCount++
return f.FetchRecipesVal, f.FetchRecipesErr
}
Expand Down
2 changes: 1 addition & 1 deletion internal/install/recipes/recipe_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import (
type RecipeFetcher interface {
FetchRecipe(context.Context, *types.DiscoveryManifest, string) (*types.Recipe, error)
FetchRecommendations(context.Context, *types.DiscoveryManifest) ([]types.Recipe, error)
FetchRecipes(context.Context) ([]types.Recipe, error)
FetchRecipes(context.Context, *types.DiscoveryManifest) ([]types.Recipe, error)
}
13 changes: 11 additions & 2 deletions internal/install/recipes/service_recipe_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,18 @@ func (f *ServiceRecipeFetcher) FetchRecommendations(ctx context.Context, manifes
}

// FetchRecipes fetches all available recipes from the recipe service.
func (f *ServiceRecipeFetcher) FetchRecipes(ctx context.Context) ([]types.Recipe, error) {
func (f *ServiceRecipeFetcher) FetchRecipes(ctx context.Context, manifest *types.DiscoveryManifest) ([]types.Recipe, error) {
var resp recipeSearchQueryResult
if err := f.client.QueryWithResponseAndContext(ctx, recipeSearchQuery, nil, &resp); err != nil {

criteria := recipeSearchInput{
InstallTarget: createInstallTarget(manifest),
}

vars := map[string]interface{}{
"criteria": criteria,
}

if err := f.client.QueryWithResponseAndContext(ctx, recipeSearchQuery, vars, &resp); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion internal/install/recipes/service_recipe_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestFetchFilters(t *testing.T) {

s := NewServiceRecipeFetcher(c)

recipes, err := s.FetchRecipes(context.Background())
recipes, err := s.FetchRecipes(context.Background(), &types.DiscoveryManifest{})
require.NoError(t, err)
require.NotNil(t, recipes)
require.NotEmpty(t, recipes)
Expand Down

0 comments on commit 46ce600

Please sign in to comment.