-
Notifications
You must be signed in to change notification settings - Fork 66
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
fix(agent): properly name drupal cached pages #1010
base: dev
Are you sure you want to change the base?
Conversation
Previously, Drupal cached pages were aggregated under the `page_cache` name and metric. This PR injects logic that allows the agent to retrieve the `_controller` information on a request to meaningfully name a txn involving a cached page.
NULL, | ||
&NRPRG(exception_filters))) { | ||
NULL, &NRPRG(exception_filters))) { |
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.
Formatting
|
const zend_class_entry* ce, | ||
const char* method, | ||
size_t method_len, | ||
nrspecialfn_t before_callback, | ||
nrspecialfn_t after_callback, | ||
nrspecialfn_t clean_callback) { | ||
const zend_class_entry* ce, | ||
const char* method, | ||
size_t method_len, | ||
nrspecialfn_t before_callback, | ||
nrspecialfn_t after_callback, | ||
nrspecialfn_t clean_callback) { |
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.
Formatting
class_method, nr_strlen(class_method), | ||
before_callback, after_callback, clean_callback); | ||
class_method, nr_strlen(class_method), before_callback, after_callback, | ||
clean_callback); | ||
|
||
nr_free(class_method); | ||
} | ||
} | ||
#endif // OAPI | ||
#endif // OAPI |
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.
Formatting
zval* curr_hook | ||
= (zval*)nr_stack_get_top(&NRPRG(drupal_invoke_all_hooks)); | ||
zval* curr_hook = (zval*)nr_stack_get_top(&NRPRG(drupal_invoke_all_hooks)); |
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.
Formatting
#endif // OAPI | ||
#endif // OAPI |
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.
Formatting
#endif // not OAPI | ||
#endif // not OAPI |
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.
Formatting
#endif // OAPI | ||
#endif // OAPI |
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.
Formatting
#endif // OAPI | ||
#endif // OAPI |
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.
Formatting
#endif // not OAPI | ||
#endif // not OAPI | ||
|
||
leave: ; | ||
leave:; | ||
#if ZEND_MODULE_API_NO < ZEND_8_0_X_API_NO \ | ||
|| defined OVERWRITE_ZEND_EXECUTE_DATA | ||
/* for OAPI, the _after callback handles this free */ | ||
nr_php_arg_release(&hook); | ||
#endif // not OAPI | ||
#endif // not OAPI |
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.
Formatting
#endif // OAPI | ||
#endif // OAPI |
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.
Formatting
ce, NR_PSTR("invokeallwith"), | ||
nr_drupal94_invoke_all_with, | ||
nr_drupal94_invoke_all_with_after, | ||
nr_drupal94_invoke_all_with_clean); | ||
ce, NR_PSTR("invokeallwith"), nr_drupal94_invoke_all_with, | ||
nr_drupal94_invoke_all_with_after, nr_drupal94_invoke_all_with_clean); |
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.
Formatting
Do we want to add some kind of indication to the txn name or metric that this was the result of a cached page hit? For example, prepending the controller name/route with |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1010 +/- ##
==========================================
- Coverage 78.16% 77.93% -0.24%
==========================================
Files 197 197
Lines 27295 27472 +177
==========================================
+ Hits 21336 21410 +74
- Misses 5959 6062 +103
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
if (NULL == nrfn) { | ||
nrl_warning(NRL_FRAMEWORK, | ||
"Failed to retrieve NR cached page naming function"); | ||
goto end; |
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 could probably set name
to "page_cache" since this is what we just did above when naming wasn't requested. Maybe change the warning to include a notice that "page_cache" was being used as the name because of the failure.
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.
Maybe a better solution to multiple name = nr_strdup("page_cache")
checks is to just check after NR_PHP_WRAPPER_CALL
if name == NULL
and set it to page_cache
that way?
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.
My concern was that it appeared we had a case where we missed naming - if your solution handles these it should work fine.
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.
I think 04cbaf6 is a slight improvement on the fallback naming
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.
On testing, that seems to have broken something... I'll have to look into this a little more
This change handles the edge case exposed in our tests where the agent may fail to inject the cache naming function at enable because it looked for drupal and symfony classes before composer autoload had time to load them. In the normal flow, this would only be a temporary problem since nr_drupal_enable should be re-run every request, and subsequent requests should have these resources available. Our test setup, however, shows that if in the process of handling one request, another request is generated and the agent doesn't re-trigger RINIT processing, the function name from the first request will bleed through to the second request and result in an incorrect name. To fix, extract logic responsible for injecting the cache naming function to its own function and call both at enable and within the PageCache::get function instrumentation, provided the injection function (newrelic_name_cached) is not detected when we look for it. This should strike the best balance between performance and correctness.
Previously, Drupal cached pages were aggregated under the
page_cache
name and metric. This PR injects logic that allows the agent to retrieve the_controller
information on a request to meaningfully name a txn involving a cached page.Adds new INI setting
newrelic.framework.drupal.page_cache_naming.enabled
to toggle behavior on/off.