Skip to content
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

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

Open
wants to merge 22 commits into
base: feat/env-configuration
Choose a base branch
from

Conversation

mfulb
Copy link
Contributor

@mfulb mfulb commented May 24, 2024

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:

  • verifies the agents view of INI entries and environment variables name mapping matching the manually maintained newrelic-install-php-cfg-mappings.php file
  • verifies the newrelic-install-inject-envvars.php script can properly inject INI values from environment variables

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

@newrelic-php-agent-bot
Copy link

newrelic-php-agent-bot commented May 24, 2024

Test Suite Status Result
Multiverse 4/9 passing
SOAK 50/56 passing

@codecov-commenter
Copy link

codecov-commenter commented May 28, 2024

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 ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##             feat/env-configuration     #906   +/-   ##
=========================================================
  Coverage                          ?   79.00%           
=========================================================
  Files                             ?      193           
  Lines                             ?    27284           
  Branches                          ?        0           
=========================================================
  Hits                              ?    21555           
  Misses                            ?     5729           
  Partials                          ?        0           
Flag Coverage Δ
agent-for-php-7.0 77.74% <80.00%> (?)
agent-for-php-7.1 77.50% <79.31%> (?)
agent-for-php-7.2 78.42% <79.31%> (?)
agent-for-php-7.3 78.44% <79.31%> (?)
agent-for-php-7.4 78.15% <79.31%> (?)
agent-for-php-8.0 78.21% <79.31%> (?)
agent-for-php-8.1 78.20% <79.31%> (?)
agent-for-php-8.2 77.80% <79.31%> (?)
agent-for-php-8.3 77.80% <79.31%> (?)

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.

@mfulb mfulb marked this pull request as ready for review May 29, 2024 18:35
@mfulb mfulb changed the title feat(installer): Adds support for configuration via environment variables [DRAFT] feat(installer): Adds support for configuration via environment variables May 30, 2024
@@ -7,6 +7,7 @@
#include "php_globals.h"
#include "php_hash.h"
#include "php_internal_instrument.h"
#include "php_nrini.h"
Copy link
Member

Choose a reason for hiding this comment

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

This header is already included on line 12:

Suggested change
#include "php_nrini.h"

@@ -420,6 +422,9 @@ fi
# If this is set, it must be set to a valid New Relic license key, and this
# key will be set in the daemon config file.
#
# NOTE: If NR_CONFIG_WITH_ENVIRON is defined and NEW_RELIC_LICENSE is defined
# then the value of NEW_RELIC_LICENSE will be used.s
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# then the value of NEW_RELIC_LICENSE will be used.s
# then the value of NEW_RELIC_LICENSE will be used instead of NR_INSTALL_KEY.

if sed -e "s/REPLACE_WITH_REAL_KEY/${nrkey}/" "${ilibdir}/scripts/newrelic.ini.template" > "${pi_inidir_cli}/newrelic.ini"; then
# check if doing old style injection of just "newrelic.license" or if injecting values from env vars
if [ -n "${NR_CONFIG_WITH_ENVIRON}" ]; then
if php "${ilibdir}/newrelic-install-inject-envvars.php" "${ilibdir}/scripts/newrelic.ini.template" "${pi_inidir_cli}/newrelic.ini"; then
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't starting the daemon be disabled here?

@@ -0,0 +1,84 @@
<?PHP
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<?PHP
<?php

@@ -0,0 +1,61 @@
<?PHP
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<?PHP
<?php

char* ini_name = NULL;
char* env_name = NULL;

if (ini_entry->module_number != NR_PHP_PROCESS_GLOBALS(our_module_number)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

are we safe to always assume that ini_entry will never be NULL?

Comment on lines +1507 to +1508
istat="failed"
if [ -n "${istat}" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

if istat is set to "failed" on the line above, won't this statement always resolve to true? Can't we remove this conditional entirely in that case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Was this istat="failed" is intentional or was it accidentally copied from the else statement above?

@ZNeumann ZNeumann added on hold This issue or pull request is necessary, but better suited for the future and removed ready for review labels Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold This issue or pull request is necessary, but better suited for the future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants