fix(agent): properly name drupal cached pages#1010
fix(agent): properly name drupal cached pages#1010bduranleau-nr wants to merge 6 commits intodevfrom
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.
agent/fw_drupal8.c
Outdated
| != nr_php_error_record_exception(NRPRG(txn), exception, priority, true, | ||
| NULL, | ||
| &NRPRG(exception_filters))) { | ||
| NULL, &NRPRG(exception_filters))) { |
|
agent/fw_drupal8.c
Outdated
| 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) { |
agent/fw_drupal8.c
Outdated
| 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 |
agent/fw_drupal8.c
Outdated
| 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)); |
agent/fw_drupal8.c
Outdated
| #endif // OAPI | ||
| #endif // OAPI |
agent/fw_drupal8.c
Outdated
| #endif // not OAPI | ||
| #endif // not OAPI |
agent/fw_drupal8.c
Outdated
| #endif // OAPI | ||
| #endif // OAPI |
agent/fw_drupal8.c
Outdated
| #endif // OAPI | ||
| #endif // OAPI |
agent/fw_drupal8.c
Outdated
| #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 |
agent/fw_drupal8.c
Outdated
| #endif // OAPI | ||
| #endif // OAPI |
agent/fw_drupal8.c
Outdated
| 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); |
|
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 Report❌ 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. 🚀 New features to boost your workflow:
|
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.
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.
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.
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.
I think 04cbaf6 is a slight improvement on the fallback naming
There was a problem hiding this comment.
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_cachename and metric. This PR injects logic that allows the agent to retrieve the_controllerinformation on a request to meaningfully name a txn involving a cached page.Adds new INI setting
newrelic.framework.drupal.page_cache_naming.enabledto toggle behavior on/off.