newrelic / newrelic-php-agent

The New Relic PHP Agent
https://opensource.newrelic.com/projects/newrelic/newrelic-php-agent
Apache License 2.0
114 stars 60 forks source link

feat(installer): Adds support for configuration via environment variables #906

Open mfulb opened 1 month ago

mfulb commented 1 month ago

This PR adds a new feature for the newrelic-install.sh script which will scan environment variables for properly named variables and inject these values into the newrelic.ini file. This will only be available when freshly installing the agent and a fresh newrelic.ini is being created. For the feature to be triggered the environment variableNR_CONFIG_WITH_ENVIRON must be set to a non-empty string.

A manually maintained mapping file (newrelic-install-php-cfg-mappings.php) is used to track the mapping from INI entry name to the matching environment variable name. Whenever INI entries for the agent are added or removed this file must be updated as well.

A new test only API was added to the agent which returns a PHP array containing the INI entry names and the corresponding environment variable names. This list is built dynamically from the INI entry definitions in the agent.

A new test target called verify-inject-script is added which runs two tests:

The verify-inject-script was added to the GHA workflow for PR runs so it is checked regularly.

newrelic-php-agent-bot commented 1 month ago
Test Suite Status Result
Multiverse :x: 4/9 passing
SOAK :x: 50/56 passing
codecov-commenter commented 1 month ago

Codecov Report

Attention: Patch coverage is 80.00000% with 6 lines in your changes missing coverage. Please review.

Please upload report for BASE (feat/env-configuration@787c147). Learn more about missing BASE report.

Files Patch % Lines
agent/php_nrini.c 76.92% 6 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## feat/env-configuration #906 +/- ## ========================================================= Coverage ? 79.00% ========================================================= Files ? 193 Lines ? 27284 Branches ? 0 ========================================================= Hits ? 21555 Misses ? 5729 Partials ? 0 ``` | [Flag](https://app.codecov.io/gh/newrelic/newrelic-php-agent/pull/906/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | Coverage Δ | | |---|---|---| | [agent-for-php-7.0](https://app.codecov.io/gh/newrelic/newrelic-php-agent/pull/906/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `77.74% <80.00%> (?)` | | | [agent-for-php-7.1](https://app.codecov.io/gh/newrelic/newrelic-php-agent/pull/906/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `77.50% <79.31%> (?)` | | | [agent-for-php-7.2](https://app.codecov.io/gh/newrelic/newrelic-php-agent/pull/906/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `78.42% <79.31%> (?)` | | | [agent-for-php-7.3](https://app.codecov.io/gh/newrelic/newrelic-php-agent/pull/906/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `78.44% <79.31%> (?)` | | | [agent-for-php-7.4](https://app.codecov.io/gh/newrelic/newrelic-php-agent/pull/906/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `78.15% <79.31%> (?)` | | | [agent-for-php-8.0](https://app.codecov.io/gh/newrelic/newrelic-php-agent/pull/906/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `78.21% <79.31%> (?)` | | | [agent-for-php-8.1](https://app.codecov.io/gh/newrelic/newrelic-php-agent/pull/906/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `78.20% <79.31%> (?)` | | | [agent-for-php-8.2](https://app.codecov.io/gh/newrelic/newrelic-php-agent/pull/906/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `77.80% <79.31%> (?)` | | | [agent-for-php-8.3](https://app.codecov.io/gh/newrelic/newrelic-php-agent/pull/906/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `77.80% <79.31%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.