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

test(instrumentation-mysql2): Add test for mysql2/promise #2525

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Karibash
Copy link

@Karibash Karibash commented Nov 13, 2024

close #650

Which problem is this PR solving?

Add test for mysql2/promise.

Short description of the changes

I added a test to confirm that @opentelemetry/instrumentation-mysql2 works with mysql2/promise.

@Karibash Karibash requested a review from a team as a code owner November 13, 2024 07:32
Copy link

linux-foundation-easycla bot commented Nov 13, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@Karibash Karibash force-pushed the feature/mysql2-promise branch from c848eb5 to 4b73476 Compare November 13, 2024 08:09
@Karibash Karibash marked this pull request as draft November 13, 2024 11:26
@Karibash Karibash force-pushed the feature/mysql2-promise branch from 4b73476 to 67004ba Compare November 13, 2024 15:20
@github-actions github-actions bot added pkg:instrumentation-mysql2 pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found. labels Nov 13, 2024
@Karibash Karibash force-pushed the feature/mysql2-promise branch from 67004ba to 104161c Compare November 13, 2024 15:21
@Karibash Karibash changed the title feat: mysql2/promise instrumentation test(instrumentation-mysql2): Add test for mysql2/promise Nov 13, 2024
@Karibash Karibash force-pushed the feature/mysql2-promise branch from 104161c to d42bfc2 Compare November 13, 2024 15:24
@Karibash Karibash marked this pull request as ready for review November 13, 2024 15:24
Copy link
Contributor

This package does not have an assigned component owner and is considered unmaintained. As such this package is in feature-freeze and this PR will be closed with 14 days unless a new owner or a sponsor (a member of @open-telemetry/javascript-approvers) for the feature is found. It is the responsibility of the author to find a sponsor for this feature.
Are you familiar with this package? Consider becoming a component owner.

Copy link
Contributor

This issue was closed because no owner or sponsor has been found after 14 days

@github-actions github-actions bot closed this Nov 28, 2024
@trentm trentm reopened this Nov 28, 2024
@trentm
Copy link
Contributor

trentm commented Nov 28, 2024

I'll sponsor.

@trentm trentm added the has:sponsor This package or feature has a sponsor that has volunteered to review PRs and respond to questions label Nov 28, 2024
Copy link
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

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

Thanks!
One nit for a possible simplification.

Comment on lines 161 to 162
if (isPoolClusterEndIgnoreCallback()) {
await poolCluster.end();
} else {
await poolCluster.end();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm am guessing you could drop function isPoolClusterEndIgnoreCallback() below and simplify this block to:

Suggested change
if (isPoolClusterEndIgnoreCallback()) {
await poolCluster.end();
} else {
await poolCluster.end();
}
await poolCluster.end();

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in the following commit. In addition, the ESLint error is also fixed.
ef5d5a6

const port = Number(process.env.MYSQL_PORT) || 33306;
const database = process.env.MYSQL_DATABASE || 'test_db';
const host = process.env.MYSQL_HOST || '127.0.0.1';
const user = process.env.MYSQL_USER || 'otel';

Check failure

Code scanning / CodeQL

Hard-coded credentials

The hard-coded value "otel" is used as [user name](1). The hard-coded value "otel" is used as [user name](2).
provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
rootConnection = await mysqlTypes.createConnection({
port,
user: 'root',

Check failure

Code scanning / CodeQL

Hard-coded credentials

The hard-coded value "root" is used as [user name](1).
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.75%. Comparing base (5eb61d8) to head (d42bfc2).
Report is 12 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2525   +/-   ##
=======================================
  Coverage   90.75%   90.75%           
=======================================
  Files         169      169           
  Lines        8018     8018           
  Branches     1632     1632           
=======================================
  Hits         7277     7277           
  Misses        741      741           

see 1 file with indirect coverage changes

@trentm
Copy link
Contributor

trentm commented Nov 28, 2024

@Karibash You'll need to run 'npm run lint:fix' to fix a style error in your added file.

@trentm
Copy link
Contributor

trentm commented Nov 28, 2024

@Karibash Then some of the "TAV" checks are failing. TAV stands for "test-all-versions". The TAV tests effectively run npm test for a number of version of the mysql2 dependency.

Looking at some of the TAV test runs above, it looks like:

Do you know what mysql2 version added support for mysql2/promises? We may want to get the tests in mysql2-promises.test.ts to be skipped in older version of mysql2. I can help with that if you need.

Some mysql2 release dates:

  '2.2.5': '2020-09-21T12:28:13.157Z',
  '2.3.0': '2021-08-05T13:47:23.743Z',
  '2.3.1': '2021-10-15T11:42:14.888Z',
  '2.3.2': '2021-10-16T06:08:46.680Z',
  '2.3.3': '2021-11-14T04:17:46.192Z',
  '3.0.0': '2023-01-12T04:51:01.542Z',

Perhaps [email protected] added promises support, or changed how its promises support works, such that this instrumentation works with it?

You should be able to test locally by running:

cd .../plugins/node/opentelemetry-instrumentation-mysql2
npm install --no-save [email protected]    # or some other version
RUN_MYSQL_TESTS=1 npm test

@Karibash
Copy link
Author

@trentm
Thank you for your detailed explanation!
The reason the test was failing was that the Promise wrapper for PoolCluster did not exist in versions prior to v2.3.0.
In the following commit, I have modified the test so that the Promise tests for PoolCluster are only performed for v2.3.0 and later.
8877f75

@Karibash Karibash force-pushed the feature/mysql2-promise branch from 8877f75 to c68038c Compare December 11, 2024 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has:sponsor This package or feature has a sponsor that has volunteered to review PRs and respond to questions pkg:instrumentation-mysql2 pkg-status:unmaintained:autoclose-scheduled pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for mysql2/promise
2 participants