Skip to content

Conversation

bduranleau-nr
Copy link
Contributor

@bduranleau-nr bduranleau-nr commented Jul 15, 2025

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:

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 from App and placed under the PhpPackages struct as the new Filter function.

The former data JSONString field has been converted into a PhpPackagesKey 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 a PhpPackagesKey slice with the raw name and version. Invalid package data received from the agent will no longer be stored in data by default and is instead discarded. To store the filtered package data, a new filteredPkgs PhpPackagesKey slice field has been added to the PhpPackages 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.

@newrelic-php-agent-bot
Copy link

newrelic-php-agent-bot commented Jul 15, 2025

Test Suite Status Result
Multiverse 16/16 passing
SOAK 85/85 passing

@codecov-commenter
Copy link

codecov-commenter commented Jul 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.95%. Comparing base (b78ac2d) to head (76c2044).

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     
Flag Coverage Δ
agent-for-php-7.2 78.37% <ø> (ø)
agent-for-php-7.3 78.38% <ø> (ø)
agent-for-php-7.4 ?
agent-for-php-8.0 ?
agent-for-php-8.1 77.77% <ø> (ø)
agent-for-php-8.2 ?
agent-for-php-8.3 77.38% <ø> (ø)
agent-for-php-8.4 77.40% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bduranleau-nr bduranleau-nr marked this pull request as ready for review July 31, 2025 22:00
if pkg.Name == expectedPackages[i].Name {
//fmt.Printf("Match - index = %d\n", j)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These debug messages were added in 76334f2 and commented out in b925fed.

@zsistla zsistla added this to the next-release milestone Aug 1, 2025

packages.data = append(packages.data, PhpPackagesKey{name, version})
}

packages.numSeen = 1
Copy link
Contributor

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?

Copy link
Member

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

mfulb
mfulb previously approved these changes Aug 4, 2025
Copy link
Contributor

@mfulb mfulb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Brian!

Comment on lines 30 to 31
// NumSaved returns the total number PHP packages payloads stored.
// Should always be 0 or 1. The agent reports all the PHP
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lavarou
lavarou previously approved these changes Aug 7, 2025
zsistla
zsistla previously approved these changes Aug 8, 2025
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.
@bduranleau-nr bduranleau-nr force-pushed the fix/vm-package-aggregation branch from 906481a to 76c2044 Compare August 8, 2025 20:15
@lavarou lavarou removed this from the next-release milestone Aug 11, 2025
@zsistla zsistla added this to the next-release milestone Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants