From d7b90fd7d269d35cb998f037fcb3cf0454852511 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 12 Feb 2023 18:33:51 +0200 Subject: [PATCH] feat(pg): remove support for pg v7 --- .../opentelemetry-instrumentation-pg/.tav.yml | 4 -- .../README.md | 2 +- .../src/instrumentation.ts | 2 +- .../test/pg-pool.test.ts | 12 ---- .../test/pg.test.ts | 12 ---- .../test/utils.ts | 65 ------------------- 6 files changed, 2 insertions(+), 95 deletions(-) delete mode 100644 plugins/node/opentelemetry-instrumentation-pg/test/utils.ts diff --git a/plugins/node/opentelemetry-instrumentation-pg/.tav.yml b/plugins/node/opentelemetry-instrumentation-pg/.tav.yml index 42321ea8b8..fa1d669474 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/.tav.yml +++ b/plugins/node/opentelemetry-instrumentation-pg/.tav.yml @@ -4,7 +4,3 @@ pg: peerDependencies: pg-pool@^3 pretest: npm run --prefix ../../../ lerna:link commands: npm run test - - versions: "7.3.0 || 7.12.1 || 7.18.2" - peerDependencies: pg-pool@^2 - pretest: npm run --prefix ../../../ lerna:link - commands: npm run test diff --git a/plugins/node/opentelemetry-instrumentation-pg/README.md b/plugins/node/opentelemetry-instrumentation-pg/README.md index 3703143057..3f624bd3b3 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/README.md +++ b/plugins/node/opentelemetry-instrumentation-pg/README.md @@ -17,7 +17,7 @@ npm install --save @opentelemetry/instrumentation-pg ### Supported Versions -- `>=7 <9` +- `>=8 <9` ## Usage diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts index 925d7c4c88..774c137275 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts @@ -65,7 +65,7 @@ export class PgInstrumentation extends InstrumentationBase { protected init() { const modulePG = new InstrumentationNodeModuleDefinition( 'pg', - ['7.*', '8.*'], + ['8.*'], moduleExports => { if (isWrapped(moduleExports.Client.prototype.query)) { this._unwrap(moduleExports.Client.prototype, 'query'); diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts index 34622eebce..887c9236a4 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts @@ -44,10 +44,6 @@ import { SemanticAttributes, DbSystemValues, } from '@opentelemetry/semantic-conventions'; -import { isSupported } from './utils'; - -const pgVersion = require('pg/package.json').version; -const nodeVersion = process.versions.node; const memoryExporter = new InMemorySpanExporter(); @@ -118,8 +114,6 @@ describe('pg-pool', () => { const shouldTest = testPostgres || testPostgresLocally; // Skips these tests if false (default) before(function () { - const skipForUnsupported = - process.env.IN_TAV && !isSupported(nodeVersion, pgVersion); const skip = () => { // this.skip() workaround // /~https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 @@ -127,12 +121,6 @@ describe('pg-pool', () => { this.skip(); }; - if (skipForUnsupported) { - console.error( - ` pg - skipped - node@${nodeVersion} and pg@${pgVersion} are not compatible` - ); - skip(); - } if (!shouldTest) { skip(); } diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts index 4ae7fb3f75..f447e3e7ec 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts @@ -45,12 +45,8 @@ import { SemanticAttributes, DbSystemValues, } from '@opentelemetry/semantic-conventions'; -import { isSupported } from './utils'; import { addSqlCommenterComment } from '../src/utils'; -const pgVersion = require('pg/package.json').version; -const nodeVersion = process.versions.node; - const memoryExporter = new InMemorySpanExporter(); const CONFIG = { @@ -120,8 +116,6 @@ describe('pg', () => { } before(async function () { - const skipForUnsupported = - process.env.IN_TAV && !isSupported(nodeVersion, pgVersion); const skip = () => { // this.skip() workaround // /~https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 @@ -129,12 +123,6 @@ describe('pg', () => { this.skip(); }; - if (skipForUnsupported) { - console.error( - ` pg - skipped - node@${nodeVersion} and pg@${pgVersion} are not compatible` - ); - skip(); - } if (!shouldTest) { skip(); } diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/utils.ts b/plugins/node/opentelemetry-instrumentation-pg/test/utils.ts deleted file mode 100644 index 1a42f5b57a..0000000000 --- a/plugins/node/opentelemetry-instrumentation-pg/test/utils.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import * as assert from 'assert'; - -const matchVersions = /([0-9]+)\.([0-9]+)\.([0-9]+)/; -const getVersions = (semver: string) => { - const match = semver.match(matchVersions); - if (match) { - return { - major: parseInt(match[1], 10), - minor: parseInt(match[2], 10), - patch: parseInt(match[3], 10), - }; - } - throw new Error(`Unable to parse version: ${semver}`); -}; - -assert.deepStrictEqual(getVersions('1.23.45'), { - major: 1, - minor: 23, - patch: 45, -}); -assert.deepStrictEqual(getVersions('v2.23.45-beta21'), { - major: 2, - minor: 23, - patch: 45, -}); - -/* - We need to skip tests for pg@7 and node@14+ combination, because in pg@7 - the client never connects. - Fix landed in pg@8: /~https://github.com/brianc/node-postgres/pull/2171 - Ref: /~https://github.com/nodejs/node/issues/38247 -*/ -export const isSupported = ( - nodeVersion: string, - pgVersion: string -): boolean => { - try { - const { major: pgMajor } = getVersions(pgVersion); - const { major: nodeMajor } = getVersions(nodeVersion); - return !(pgMajor === 7 && nodeMajor >= 14); - } catch (e) { - return true; - } -}; - -assert.strictEqual(isSupported('16.0.0', '7.0.0'), false); -assert.strictEqual(isSupported('14.0.0', '7.0.0'), false); -assert.strictEqual(isSupported('12.0.0', '7.0.0'), true); -assert.strictEqual(isSupported('16.0.0', '8.0.0'), true); -assert.strictEqual(isSupported('12.0.0', '8.0.0'), true);