-
Notifications
You must be signed in to change notification settings - Fork 67
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(agent): Drupal hook attribute instrumentation #1030
base: dev
Are you sure you want to change the base?
Conversation
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1030 +/- ##
==========================================
+ Coverage 77.58% 77.87% +0.28%
==========================================
Files 198 198
Lines 27715 27754 +39
==========================================
+ Hits 21503 21613 +110
+ Misses 6212 6141 -71
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
agent/fw_drupal8.c
Outdated
hook_attribute_instrumentation | ||
= nr_drupal_hook_attribute_instrument(*retval_ptr); | ||
|
||
if (!hook_attribute_instrumentation) { |
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.
nr_drupal_hook_attribute_instrument
will only return true
if it's able to walk the entire hookImplementationsMap
. What will happen if it fails mid way? Which hook instrumentation will be used? Does nr_drupal_hook_attribute_instrument
cleanup its partial work if it fails to walk the entire hookImplementationsMap
? Could you add a test for this 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.
If walking the map fails halfway through, we exit the function and return false. The wraprecs that are already created remain, and we revert back to the old method of wrapping hooks.
Which hook instrumentation will be used?
The answer would be "both". The attribute based instrumentation would persist for anything it managed to wrap, and the other methods act as a fallback to hopefully plug the gaps. I don't see anticipate any negative side-effects from this, do you?
Could you add a test for this case?
This would be difficult and doesn't fit neatly into our established test paradigms, The dependency here is a lot of Drupal code, from Drupal::moduleHandler
to the hookImplementationsMap
. Is there a specific concern you have with this failing partway though walking the map?
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.
Given #1030 (comment), I would feel more comfortable having a test with mocked implementation of Drupal\Core\Extension\ModuleHandlerInterface
that has corrupted hookImplementationsMap
property in every possible way - invalid type of the property (not an array), first level has invalid key and value, second level has invalid key and value, third level has invalid key and value.
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.
agent/fw_drupal8.c
Outdated
hook_val) { | ||
if ((NULL == hook_key) || (0 == nr_php_is_zval_valid_array(hook_val))) { | ||
nrl_warning(NRL_FRAMEWORK, | ||
"hookImplementationsMap[hook = %s]: invalid value", |
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 can happen when NULL == hook_key
, so more appropriate message would be:
"hookImplementationsMap[hook = %s]: invalid value", | |
"hookImplementationsMap[hook = %s]: invalid key or value", |
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.
value
here was intended to be generic, as in "an invalid value was returned" and not the specifc map value for a key, but I've fixed it here ea0e4cf
agent/fw_drupal8.c
Outdated
if ((NULL == hook_key) || (0 == nr_php_is_zval_valid_array(hook_val))) { | ||
nrl_warning(NRL_FRAMEWORK, | ||
"hookImplementationsMap[hook = %s]: invalid value", | ||
NRSAFESTR(ZEND_STRING_VALUE(hook_key))); |
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 will seg fault if hook_key
is NULL
- ZEND_STRING_VALUE
dereferences pointer it is passed.
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 warnings have been fixed here d876e0e
zval* module_val = NULL; | ||
|
||
char* hookpath = NULL; | ||
|
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.
Could check module_handler
for NULL and exit early.
return false; | ||
} | ||
|
||
if (!nr_php_is_zval_valid_array(hook_implementation_map)) { |
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.
nr_php_is_zval_valid_array
will already check hook_implementation_map
for NULL ; it doesn't need the extra check right above.
if ((NULL == hook_key) || (0 == nr_php_is_zval_valid_array(hook_val))) { | ||
nrl_warning(NRL_FRAMEWORK, | ||
"hookImplementationsMap[hook]: invalid key or value"); | ||
return false; |
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.
Do we want to return here or just skip this round of the loop?
What if the first hook_key or hook_val is invalid, but the next one is good?
if ((NULL == class_key) || (0 == nr_php_is_zval_valid_array(class_val))) { | ||
nrl_warning(NRL_FRAMEWORK, | ||
"hookImplementationsMap[class]: invalid key or value"); | ||
return false; |
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.
Similar to https://github.com/newrelic/newrelic-php-agent/pull/1030/files#r1974532294, do we want to exit the whole function or just skip this round of the loop.
|| (0 == nr_php_is_zval_valid_string(module_val))) { | ||
nrl_warning(NRL_FRAMEWORK, | ||
"hookImplementationsMap[method]: invalid key or value"); | ||
return false; |
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.
https://github.com/newrelic/newrelic-php-agent/pull/1030/files#r1974532294
skip this round of the loop or completely exit?
Adds support for Drupal Attribute Hooks added in Drupal 11.1.