-
Notifications
You must be signed in to change notification settings - Fork 70
fix(daemon): aggregate packages throughout harvest #1103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1103 +/- ##
==========================================
- Coverage 78.12% 77.95% -0.17%
==========================================
Files 193 192 -1
Lines 27989 27792 -197
==========================================
- Hits 21866 21666 -200
- Misses 6123 6126 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
if pkg.Name == expectedPackages[i].Name { | ||
//fmt.Printf("Match - index = %d\n", j) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were all of these comments left in previously for ease of future debugging efforts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the origin of these comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the autoformatter remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did while I was debugging a problem with the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
packages.data = append(packages.data, PhpPackagesKey{name, version}) | ||
} | ||
|
||
packages.numSeen = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this field does any more - but if we keep it should it be incremented by the number of packages created in the for
loop above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also interested in how this gets resolved. See related comment: https://github.com/newrelic/newrelic-php-agent/pull/1103/files#r2261468915
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Brian!
ac27f9a
to
59cf8f6
Compare
// NumSaved returns the total number PHP packages payloads stored. | ||
// Should always be 0 or 1. The agent reports all the PHP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "Should always be 0 or 1" still valid? Now that daemon potentially holds on to multiple php packages payloads received from the agent, shouldn't this represent the number of times the daemon received php packages payload from the agent in a given harvest cycle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell this value isn't sent to the backend or used anywhere other than the conditional checks as an indicator that packages
have been set for the current harvest. I don't believe it is used in any kind of metrics or instrumentation data, so maybe we should consider changing it entirely to a bool
. I think this was added as an artifact of the other Event types that report seen vs saved, but it doesn't really fit cleanly into the packages VM logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least the comment should be updated because it is misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addition of packages.filteredData was causing the processor_test to hang, due to packages.filteredData only being set during the harvest process. The harvest.empty check would fail, and the harvest would never occur, causing the test to hang indefinitely
since the final result of the package data is no longer in the PhpPackages.data field, add an app instance to execute the filterPhpPackages logic and set the result == pkg.filteredData. This will allow the `CollectorJSON` function to run successfully and return the expected result.
Refactor package filtering logic. Previously filtering was owned by the App module. This caused depedency problems when trying to invoke filtering (necessary for final json generation) outside of the app context. Moving ownership to the PhpPackages module allows access to filtering whenever relevant. Also refactored ownership of JSON generation. Package JSON generation is no longer split between the filter method and the CollectorJSON method and is instead fully owned by CollectorJSON.
consolidate the SetPhpPackages method into the AddPhpPackagesFromData method. Instead of storing the data as json, unmarshal it and store the raw data in the `data` slice as a PhpPackagesKey struct. Reject bad data immediately instead of allowing it to persist in the data array.
906481a
to
76c2044
Compare
Fixes a bug in the daemon behavior where only the last VM package data payload from the agent was harvested by the daemon. See this line to better understand the general behavior at play:
newrelic-php-agent/daemon/internal/newrelic/php_packages.go
Line 57 in 765888d
This issue was exposed by SOAK testing the composer VM once-per-process package detection, where the composer package data was being overridden by the legacy VM data. The fix required a refactor to how the daemon stores and processes package data, while still observing the need to de-duplicate data sent to the
update_loaded_modules
endpoint for processing.The
filterPhpPackages
logic was removed fromApp
and placed under thePhpPackages
struct as the newFilter
function.The former
data
JSONString
field has been converted into aPhpPackagesKey
slice
to store all of the package data sent by the agent for a single harvest cycle. Data received from the agent is no longer stored as JSON, but unmarshalled and verified before the daemon accepts it and stores it as aPhpPackagesKey
slice
with the raw name and version. Invalid package data received from the agent will no longer be stored indata
by default and is instead discarded. To store the filtered package data, a newfilteredPkgs
PhpPackagesKey
slice
field has been added to thePhpPackages
struct.The responsibility of marshalling the final json payload for the backend endpoint has been consolidated into the
CollectorJSON
function for simpler data handling, and better accessibility for testing.SetPhpPackages
has been removed and logic consolidated into the parent caller,AddPhpPackagesFromData
.