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: add support for pg 7 changes #702

Merged
merged 6 commits into from
Mar 29, 2018
Merged

fix: add support for pg 7 changes #702

merged 6 commits into from
Mar 29, 2018

Conversation

kjin
Copy link
Contributor

@kjin kjin commented Mar 26, 2018

This PR converts the PostGreSQL tracing plugin to TypeScript, makes changes to support the new API in pg@7, adds a few more tests, and changes the way value labels are collected.

  • chore: add pg7 to test fixtures
    • This changes a JSON file that specifies the list of modules to be installed as test fixtures, adding pg@7.
  • refactor: port plugin-pg to typescript
    • This converts plugin-pg.ts to ES6 + type annotations, and installs pg@7 types. There should be no behavioral change.
  • fix: add support for pg 7
    • This adds a patch for pg@7, based on source code and the upgrade guide.
    • Differences in a nutshell
      • In pg@6, an object is always returned by Client#query, and is simultaneously a Promise[Like], an EventEmitter, and an object { text: string; values?: Array, callback?: Function }.
      • In pg@7, the return value of Client#query is either a Promise, EventEmitter, or undefined, depending on the input parameters.
  • fix: get pg 6 query values before call
    • Currently, we get query values from the output object of Client#query; in pg@7, these fields are not guaranteed to exist, so we must gather them from input parameters instead. However, there is a mismatch between values gotten from input and output; output values are coerced to strings and escaped to avoid SQL injection. So to keep things consistent, we now also get values from the inputs to Client#query in pg@6. (I don't think that these values being unescaped should pose a threat because their values are simply stored, not executed; feel free to dispute that.)
  • test: modify tests
    • Modify tests to support both v6 and v7, and also add new test cases for previously uncovered scenarios: promises and generic Submittables. Converting this test to idiomatic TypeScript is out of the scope of this PR.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 26, 2018
@kjin kjin force-pushed the pg-7 branch 2 times, most recently from 99eb8fe to 01b4244 Compare March 26, 2018 23:41
@kjin kjin changed the title [WIP] fix: add support for pg 7 changes fix: add support for pg 7 changes Mar 26, 2018
@jinwoo
Copy link
Contributor

jinwoo commented Mar 27, 2018

Didn't look at the code yet but CI is failing.

@codecov
Copy link

codecov bot commented Mar 28, 2018

Codecov Report

Merging #702 into master will decrease coverage by 0.25%.
The diff coverage is 78.08%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #702      +/-   ##
==========================================
- Coverage   91.02%   90.77%   -0.26%     
==========================================
  Files          29       29              
  Lines        1438     1485      +47     
  Branches      280      293      +13     
==========================================
+ Hits         1309     1348      +39     
- Misses         52       57       +5     
- Partials       77       80       +3
Impacted Files Coverage Δ
src/plugins/plugin-pg.ts 77.92% <78.08%> (+1.25%) ⬆️
src/trace-writer.ts 91.52% <0%> (+0.84%) ⬆️
src/cls-ah.ts 88.46% <0%> (+1.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c13a3bf...314052e. Read the comment docs.

span.addLabel('values', pgQuery.values);
const args: pg_6.QueryReturnValue[] =
Array.prototype.slice.call(arguments, 0);
if (args.length >= 1) {

This comment was marked as spam.

// - ...[text: string, values?: Array<any>]
// See: https://node-postgres.com/guides/upgrading

if (args.length >= 1) {

This comment was marked as spam.


if (args.length >= 1) {
// Extract query text and values, if needed.
if (api.enhancedDatabaseReportingEnabled()) {

This comment was marked as spam.

span.addLabel('error', err);
}
if (res) {
span.addLabel('row_count', res.rowCount);

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants