-
Notifications
You must be signed in to change notification settings - Fork 63
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
base: feat/env-configuration
Are you sure you want to change the base?
Conversation
Test API useful for getting all INI entries and matching environment variable names.
Gives a mapping from INI entry name to matching environment variable name.
Start of a script that will inject environment variable config values into a newrelic.ini config file.
|
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Needed all installer files to fit within a single glob so artifacts could be specfiied with simple wildcard.
@@ -7,6 +7,7 @@ | |||
#include "php_globals.h" | |||
#include "php_hash.h" | |||
#include "php_internal_instrument.h" | |||
#include "php_nrini.h" |
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.
This header is already included on line 12:
#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 |
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.
# 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 |
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.
Shouldn't starting the daemon be disabled here?
@@ -0,0 +1,84 @@ | |||
<?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.
<?PHP | |
<?php |
@@ -0,0 +1,61 @@ | |||
<?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.
<?PHP | |
<?php |
char* ini_name = NULL; | ||
char* env_name = NULL; | ||
|
||
if (ini_entry->module_number != NR_PHP_PROCESS_GLOBALS(our_module_number)) { |
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.
are we safe to always assume that ini_entry
will never be NULL
?
istat="failed" | ||
if [ -n "${istat}" ]; then |
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.
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?
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.
Was this istat="failed"
is intentional or was it accidentally copied from the else
statement above?
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 thenewrelic.ini
file. This will only be available when freshly installing the agent and a freshnewrelic.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:newrelic-install-php-cfg-mappings.php
filenewrelic-install-inject-envvars.php
script can properly inject INI values from environment variablesThe
verify-inject-script
was added to the GHA workflow for PR runs so it is checked regularly.