Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions daemon/internal/newrelic/integration/php_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,18 +290,20 @@ func (pkgs *PhpPackagesCollection) OverrideVersionsFile() string {
//
// Returns:
// - []PhpPackage with extracted package info, sorted by package name
// - []string notes to be added to the test
// - nil upon error processing JSON
//
// Notes: Currently only supports an application created with composer
func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, error) {
func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, []string, error) {

var err error

if nil == pkgs {
return nil, fmt.Errorf("GatherInstallPackages(): pkgs is nil")
return nil, nil, fmt.Errorf("GatherInstallPackages(): pkgs is nil")
}

var supported []string
var notes []string

// get list of packages we expected the agent to detect
// this can be one of 3 scenarios:
Expand Down Expand Up @@ -331,12 +333,12 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
if 0 < len(pkgs.config.supportedListFile) {
supported, err = LoadSupportedPackagesList(pkgs.config.path, pkgs.config.supportedListFile)
if nil != err {
return nil, err
return nil, nil, err
}
} else if 0 < len(pkgs.config.expectedPackages) {
supported = pkgs.config.expectedPackages
} else if !pkgs.config.expectAllDetected {
return nil, fmt.Errorf("Error determining expected packages - supported_packages and expected_packages are both empty " +
return nil, nil, fmt.Errorf("Error determining expected packages - supported_packages and expected_packages are both empty " +
"and expect_all is false")
}

Expand Down Expand Up @@ -366,6 +368,16 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
} else {
version = v.Version
}

// Remove any additional information extracted (hashes, etc).
// The composer versioning standard is to not include any spaces
// yet sometimes this standard is broken
version_splits := strings.Split(version, " ")
if len(version_splits) > 1 {
notes = append(notes, fmt.Sprintf("Used shortened package version from composer. Originally was \"%s\"", version))
version = version_splits[0]
}

pkgs.packages = append(pkgs.packages, PhpPackage{v.Name, version})
//fmt.Printf(" -> %s in supported!\n", v.Name)
} else {
Expand Down Expand Up @@ -402,15 +414,15 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
}
}
} else {
return nil, fmt.Errorf("ERROR - unknown method '%s'\n", splitCmd[0])
return nil, nil, fmt.Errorf("ERROR - unknown method '%s'\n", splitCmd[0])
}

// sort by package name to aid comparision later
sort.Slice(pkgs.packages, func(i, j int) bool {
return pkgs.packages[i].Name < pkgs.packages[j].Name
})

return pkgs.packages, nil
return pkgs.packages, notes, nil
}

// convert PhpPackage to collector JSON representation
Expand Down
8 changes: 7 additions & 1 deletion daemon/internal/newrelic/integration/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ func (t *Test) comparePhpPackages(harvest *newrelic.Harvest) {

if nil != t.phpPackagesConfig {
var err error
var notes []string

expectNullPkgs = "null" == string(t.phpPackagesConfig)
if expectNullPkgs {
Expand All @@ -652,11 +653,16 @@ func (t *Test) comparePhpPackages(harvest *newrelic.Harvest) {
return
}

expectedPackages, err = expectedPkgsCollection.GatherInstalledPackages()
expectedPackages, notes, err = expectedPkgsCollection.GatherInstalledPackages()
if nil != err {
t.Fatal(err)
return
}
if nil != notes {
for _, note := range notes {
t.AddNote(note)
}
}

// Determine if we expect an exact match between expected and actual packages
// when using the composer API in the agent to detect packages it is possible
Expand Down