-
Notifications
You must be signed in to change notification settings - Fork 70
feat(agent): Drupal hook attribute instrumentation #1030
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a784009
feat(agent): add drupal hook attribute instrumentation
bduranleau-nr ab1d33e
fix: clean up mem freeing
bduranleau-nr 45aace1
undef helper macro
bduranleau-nr e102476
review: reduce memory allocation
bduranleau-nr aa17d9e
review: remove frees
bduranleau-nr 4d7c50d
review: improve conditional
bduranleau-nr cfe4066
review: use STR_KEY_VAL zend loop
bduranleau-nr 3523159
cleanup: remove undef
bduranleau-nr a942c20
review: flatten conditional
bduranleau-nr 95091bb
fix warnings
bduranleau-nr 75b5329
clarify warning
bduranleau-nr 593513b
remove NULL check
bduranleau-nr ce376b2
add integration tests
bduranleau-nr 1d993a0
test: add valid drupal hookmap test
bduranleau-nr 0a18a7a
fix: check for 0 length array values and key strings
bduranleau-nr 2fcfaf4
fix: skipif for 7.4+
bduranleau-nr 808910b
review feedback
bduranleau-nr faefa68
rename validation fn
bduranleau-nr 0a83aa1
review: optimize class string comparison
bduranleau-nr 7b424c2
Update agent/fw_drupal8.c
bduranleau-nr 16daf2a
fix conditional
bduranleau-nr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/integration/frameworks/drupal/mock_module_handler_empty_array.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Verify agent behavior when key value is an empty array */ | ||
|
||
namespace Drupal\Core\Extension { | ||
interface ModuleHandlerInterface | ||
{ | ||
public function invokeAllWith($hook_str, $callback); | ||
} | ||
class ModuleHandler implements ModuleHandlerInterface | ||
{ | ||
protected array $hookImplementationsMap = array( | ||
zsistla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'hookname' => array('classname' => array('methodname' => 'modulename')), | ||
'hookname_b' => array(), | ||
'hookname_c' => array('classname_c' => array('methodname_c' => 'modulename_c')), | ||
); | ||
|
||
// to avoid editor warnings | ||
public function invokeAllWith($hook_str, $callback) | ||
{ | ||
return null; | ||
} | ||
|
||
// for debugging purposes | ||
public function dump() | ||
{ | ||
var_dump($this->hookImplementationsMap); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/integration/frameworks/drupal/mock_module_handler_empty_key.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Verify agent behavior when key is an empty string */ | ||
|
||
namespace Drupal\Core\Extension { | ||
interface ModuleHandlerInterface | ||
{ | ||
public function invokeAllWith($hook_str, $callback); | ||
} | ||
class ModuleHandler implements ModuleHandlerInterface | ||
{ | ||
protected array $hookImplementationsMap = array( | ||
'hookname' => array('classname' => array('methodname' => 'modulename')), | ||
'hookname_b' => array('' => array('methodname_b' => 'modulename_b')), | ||
'hookname_c' => array('classname_c' => array('methodname_c' => 'modulename_c')), | ||
); | ||
|
||
// to avoid editor warnings | ||
public function invokeAllWith($hook_str, $callback) | ||
{ | ||
return null; | ||
} | ||
|
||
// for debugging purposes | ||
public function dump() | ||
{ | ||
var_dump($this->hookImplementationsMap); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/integration/frameworks/drupal/mock_module_handler_invalid_key.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Verify agent behavior when map key is not a string */ | ||
|
||
namespace Drupal\Core\Extension { | ||
interface ModuleHandlerInterface | ||
{ | ||
public function invokeAllWith($hook_str, $callback); | ||
} | ||
class ModuleHandler implements ModuleHandlerInterface | ||
{ | ||
protected array $hookImplementationsMap = array( | ||
'hookname' => array('classname' => array('methodname' => 'modulename')), | ||
1 => array('classname_b' => array('methodname_b' => 'modulename_b')), | ||
'hookname_c' => array('classname_c', array('methodname_c', 'modulename_c')), | ||
); | ||
|
||
// to avoid editor warnings | ||
public function invokeAllWith($hook_str, $callback) | ||
{ | ||
return null; | ||
} | ||
|
||
// for debugging purposes | ||
public function dump() | ||
{ | ||
var_dump($this->hookImplementationsMap); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/integration/frameworks/drupal/mock_module_handler_invalid_map.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Verify agent behavior when hookImplemementationsMap is not an array */ | ||
|
||
namespace Drupal\Core\Extension { | ||
interface ModuleHandlerInterface | ||
{ | ||
public function invokeAllWith($hook_str, $callback); | ||
} | ||
class ModuleHandler implements ModuleHandlerInterface | ||
{ | ||
protected string $hookImplementationsMap = 'just a string'; | ||
|
||
// to avoid editor warnings | ||
public function invokeAllWith($hook_str, $callback) | ||
{ | ||
return null; | ||
} | ||
|
||
// for debugging purposes | ||
public function dump() | ||
{ | ||
var_dump($this->hookImplementationsMap); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/integration/frameworks/drupal/mock_module_handler_invalid_module.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Verify agent behavior when module name is not a string */ | ||
|
||
namespace Drupal\Core\Extension { | ||
interface ModuleHandlerInterface | ||
{ | ||
public function invokeAllWith($hook_str, $callback); | ||
} | ||
class ModuleHandler implements ModuleHandlerInterface | ||
{ | ||
protected array $hookImplementationsMap = array( | ||
'hookname' => array('classname' => array('methodname' => 'modulename')), | ||
'hookname_b' => array('classname_b' => array('methodname_b' => array(1, 2, 3))), | ||
'hookname_c' => array('classname_c' => array('methodname_c' => 'modulename_c')), | ||
); | ||
|
||
// to avoid editor warnings | ||
public function invokeAllWith($hook_str, $callback) | ||
{ | ||
return null; | ||
} | ||
|
||
// for debugging purposes | ||
public function dump() | ||
{ | ||
var_dump($this->hookImplementationsMap); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/integration/frameworks/drupal/mock_module_handler_invalid_value.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Verify agent behavior when key value is not an array */ | ||
|
||
namespace Drupal\Core\Extension { | ||
interface ModuleHandlerInterface | ||
{ | ||
public function invokeAllWith($hook_str, $callback); | ||
} | ||
class ModuleHandler implements ModuleHandlerInterface | ||
{ | ||
protected array $hookImplementationsMap = array( | ||
'hookname' => array('classname' => array('methodname' => 'modulename')), | ||
'hookname_b' => array('classname_b' => 'just a string'), | ||
'hookname_c' => array('classname_c' => array('methodname_c' => 'modulename_c')), | ||
); | ||
|
||
// to avoid editor warnings | ||
public function invokeAllWith($hook_str, $callback) | ||
{ | ||
return null; | ||
} | ||
|
||
// for debugging purposes | ||
public function dump() | ||
{ | ||
var_dump($this->hookImplementationsMap); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/integration/frameworks/drupal/mock_module_handler_valid.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Verify agent behavior on valid hookImplementationsMap */ | ||
|
||
namespace Drupal\Core\Extension { | ||
interface ModuleHandlerInterface | ||
{ | ||
public function invokeAllWith($hook_str, $callback); | ||
} | ||
class ModuleHandler implements ModuleHandlerInterface | ||
{ | ||
protected array $hookImplementationsMap = array( | ||
'hookname' => array('classname' => array('methodname' => 'modulename')), | ||
'hookname_b' => array('classname_b' => array('methodname_b' => 'modulename_b')), | ||
'hookname_c' => array('classname_c' => array('methodname_c' => 'modulename_c')), | ||
); | ||
|
||
// to avoid editor warnings | ||
public function invokeAllWith($hook_str, $callback) | ||
{ | ||
return null; | ||
} | ||
|
||
// for debugging purposes | ||
public function dump() | ||
{ | ||
var_dump($this->hookImplementationsMap); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/integration/frameworks/drupal/test_hook_implementations_map_empty_array.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
Verify agent behavior when key value is an empty array | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, '7.4', '<')) { | ||
die("skip: PHP >= 7.4 required\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
newrelic.framework = drupal8 | ||
*/ | ||
|
||
/*EXPECT_TRACED_ERRORS null */ | ||
|
||
/*EXPECT_ERROR_EVENTS null */ | ||
|
||
/*EXPECT | ||
*/ | ||
|
||
require_once __DIR__ . '/mock_module_handler_empty_array.php'; | ||
|
||
// This specific API is needed for us to instrument the ModuleHandler | ||
class Drupal | ||
{ | ||
public function moduleHandler() | ||
{ | ||
return new Drupal\Core\Extension\ModuleHandler(); | ||
} | ||
} | ||
|
||
// Create module handler | ||
$drupal = new Drupal(); | ||
$handler = $drupal->moduleHandler(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.