Skip to content
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 PDO instrumentation in PHP 8.4 #993

Merged
merged 17 commits into from
Jan 7, 2025

Conversation

lavarou
Copy link
Member

@lavarou lavarou commented Dec 10, 2024

PHP 8.4 includes implementation of PDO driver specific sub-classes RFC (see https://wiki.php.net/rfc/pdo_driver_specific_subclasses). This means that when database access code uses new factory method PDO::connect to create PDO object, an instance of driver specific sub-class of PDO is returned instead of an instance of generic PDO class. This means that instrumentation of generic PDO class is not enough to provide instrumentation of datastores. Add wrappers for driver specific subclasses of PDO supported by the agent: Pdo\Firebird, Pdo\Mysql, Pdo\Odbc, Pdo\Pgsql, Pdo\Sqlite.

@lavarou lavarou requested review from ZNeumann and zsistla December 10, 2024 21:01
@lavarou lavarou self-assigned this Dec 10, 2024
@newrelic-php-agent-bot
Copy link

newrelic-php-agent-bot commented Dec 10, 2024

Test Suite Status Result
Multiverse 7/7 passing
SOAK 62/62 passing

@lavarou lavarou marked this pull request as draft December 10, 2024 21:01
@lavarou lavarou requested a review from mfulb December 10, 2024 21:26
@zsistla
Copy link
Contributor

zsistla commented Dec 11, 2024

Great job with the investigation and fix!

@lavarou lavarou force-pushed the feat/php-8.4/fix-api-number branch from 508be9b to bbe7ed0 Compare December 11, 2024 14:23
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch from 62506bd to 2f8830a Compare December 11, 2024 14:23
Base automatically changed from feat/php-8.4/fix-api-number to zjn/84 December 12, 2024 16:57
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch from 2f8830a to dcc238f Compare December 12, 2024 16:57
@codecov-commenter
Copy link

codecov-commenter commented Dec 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.04%. Comparing base (3585eba) to head (8cca073).

Additional details and impacted files
@@            Coverage Diff             @@
##            php84     #993      +/-   ##
==========================================
+ Coverage   78.03%   78.04%   +0.01%     
==========================================
  Files         196      196              
  Lines       27084    27104      +20     
==========================================
+ Hits        21134    21154      +20     
  Misses       5950     5950              
Flag Coverage Δ
agent-for-php-7.2 78.03% <ø> (ø)
agent-for-php-7.3 78.05% <ø> (ø)
agent-for-php-7.4 77.76% <ø> (ø)
agent-for-php-8.0 77.13% <ø> (ø)
agent-for-php-8.1 77.79% <ø> (ø)
agent-for-php-8.2 77.38% <ø> (ø)
agent-for-php-8.3 77.38% <ø> (ø)
agent-for-php-8.4 77.40% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zsistla zsistla added this to the PHP 8.4 support milestone Dec 16, 2024
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch from dcc238f to 9807f77 Compare December 17, 2024 14:50
@lavarou lavarou changed the base branch from zjn/84 to php84 December 17, 2024 14:53
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch from ea6cce9 to 043f6bf Compare December 17, 2024 21:53
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch from e121c97 to 4387b13 Compare December 20, 2024 20:24
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch 3 times, most recently from 3405121 to 5a40841 Compare December 24, 2024 20:55
*/

/*INI
;comment=Set explain_threshold to 0 to ensure that the slow query is recorded.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted the comments explaining these settings to be as close to the settings as possible. The reason for ;comment=... construct is because integration_runner expects key=value format for anything (including comments) in INI directive.

@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch 2 times, most recently from 381d972 to adf1f02 Compare December 28, 2024 03:28
@lavarou lavarou marked this pull request as ready for review December 28, 2024 03:53
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch from adf1f02 to f5471b1 Compare December 28, 2024 03:55
@hahuja2 hahuja2 added this to the next-release milestone Jan 6, 2025
Copy link
Contributor

@mfulb mfulb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very thorough and encompassing improvement in our test coverage - nice Michal!

Copy link
Contributor

@bduranleau-nr bduranleau-nr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean & detailed addition 👍

@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch from bd5f704 to 4484c3f Compare January 7, 2025 20:16
lavarou added 17 commits January 7, 2025 15:22
PHP 8.4 includes implementation of PDO driver specific sub-classes RFC
(see https://wiki.php.net/rfc/pdo_driver_specific_subclasses). This
means that when database access code uses new factory method
`PDO::connect` to create PDO object, an instance of driver specific
sub-class of `PDO` is returned instead of an instance of generic `PDO`
class. This means that instrumentation of generic `PDO` class is not
enough to provide instrumentation of datastores. Add wrappers for driver
specific subclasses of `PDO` supported by the agent: `Pdo\Firebird`,
`Pdo\Mysql`, `Pdo\Odbc`, `Pdo\Pgsql`, `Pdo\Sqlite`.
Back in 2015 when datastore integration tests were refactored to extract
common configuration into `config.php`, setting the value of global
variable `$MYSQL_DB` to the value of `MYSQL_DB` env var with help of
`isset_or` was not preserved - it was left out as a TODO item. However,
since mysql tests need to occasionally create tables in the database, as
well as insert data into those tables, `$MYSQL_USER` needs permissions
to do that. When mysqldb test service is provisioned, permissions are
granted automatically for the database name stored in `$MYSQL_DB` env
var. Therefore `$MYSQL_DB` must be set to the value of `MYSQL_DB` env
var in order for create table to work. However, this means that all
queries about MySQL's tables metadata stored in `information_schema`
database need to specify full table path, i.e.: `SELECT * from
information_schema.tables` rather than just `SELECT * from tables`.
Test output depends on PHP version and backing database -  value for id
column can be returned as int or string. Instead of splitting the test
by PHP version and backing database normalize test output to always
return value of id column as int.
Test that agent creates datastore metrics when `PDO::query` and `PDO::execute`
are provided connection object created using either `PDO::connect` factory
method or PDO's specialized subclass constructor.
Test different variants of calls to PDO::query with various types of
conn object for mysql, pgsql and sqlite databases.
Test that agent creates datastore metrics, datastore spans and slow sql traces
when `PDO::prepare` is provided connection object created using all supported
methods: either `PDO::connect` factory method or PDO's base class or specialized
subclass constructor.
Use legacy name for SQLite's schema table (sqlite_master) for compatibility
with older PHPs (7.2 and 7.3).
Test that agent creates datastore instance metrics, and includes datastore
instance attributes in datastore spans and slow sql traces when connection
object is created using all supported methods: either `PDO::connect` factory
method or PDO's base class or specialized subclass constructor.
Explain how pdo/*.inc test files are used by driver specific tests.
Make test purpose clearer by using more expressive test file names that reflect
test purpose.
Make test purpose clearer by using more expressive test file names that reflect
test purpose.
Make test purpose clearer by using more expressive test file names that reflect
test purpose.
Reorganize tests docstrings.
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch from 4484c3f to 8cca073 Compare January 7, 2025 20:23
@lavarou lavarou merged commit 1e81310 into php84 Jan 7, 2025
61 checks passed
@lavarou lavarou deleted the feat/php-8.4/fix-pdo-instrumentation branch January 7, 2025 20:53
ZNeumann pushed a commit that referenced this pull request Jan 7, 2025
PHP 8.4 includes implementation of PDO driver specific sub-classes RFC
(see https://wiki.php.net/rfc/pdo_driver_specific_subclasses). This
means that when database access code uses new factory method
`PDO::connect` to create PDO object, an instance of driver specific
sub-class of `PDO` is returned instead of an instance of generic `PDO`
class. This means that instrumentation of generic `PDO` class is not
enough to provide instrumentation of datastores. Add wrappers for driver
specific subclasses of `PDO` supported by the agent: `Pdo\Firebird`,
`Pdo\Mysql`, `Pdo\Odbc`, `Pdo\Pgsql`, `Pdo\Sqlite`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants