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

Draft
wants to merge 8 commits into
base: php84
Choose a base branch
from

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 77.47%. Comparing base (d5cf37b) to head (5a40841).

Additional details and impacted files
@@            Coverage Diff             @@
##            php84     #993      +/-   ##
==========================================
- Coverage   78.03%   77.47%   -0.57%     
==========================================
  Files         196      196              
  Lines       27084    26987      -97     
==========================================
- Hits        21134    20907     -227     
- Misses       5950     6080     +130     
Flag Coverage Δ
agent-for-php-7.2 ?
agent-for-php-7.3 ?
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
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.
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch from 4387b13 to e1aa516 Compare December 21, 2024 00:00
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.
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch from e1aa516 to 81f0369 Compare December 23, 2024 17:03
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.
@lavarou lavarou force-pushed the feat/php-8.4/fix-pdo-instrumentation branch 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.

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.

5 participants