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

add plugin mysql #29

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 131 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@
"@types/google-protobuf": "^3.7.2",
"@types/jest": "^26.0.15",
"@types/node": "^14.0.11",
"@types/resolve": "^1.19.0",
"@types/semver": "^7.2.0",
"@types/uuid": "^8.0.0",
"axios": "^0.21.0",
"express": "^4.17.1",
"grpc-tools": "^1.10.0",
"grpc_tools_node_protoc_ts": "^4.0.0",
"jest": "^26.6.3",
"mysql2": "^2.2.5",
"prettier": "^2.0.5",
"testcontainers": "^6.2.0",
"ts-jest": "^26.4.4",
Expand All @@ -62,6 +64,7 @@
"dependencies": {
"google-protobuf": "^3.14.0",
"grpc": "^1.10.1",
"resolve": "^1.19.0",
"semver": "^7.3.2",
"tslib": "^2.0.3",
"uuid": "^8.1.0",
Expand Down
21 changes: 21 additions & 0 deletions src/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,25 @@ export default {
val: `${val}`,
} as Tag;
},
dbType: (val: string | undefined): Tag => {
return {
key: 'db.type',
overridable: true,
val: `${val}`,
};
},
dbInstance: (val: string | undefined): Tag => {
return {
key: 'db.instance',
overridable: true,
val: `${val}`,
};
},
dbStatement: (val: string | undefined): Tag => {
return {
key: 'db.statement',
overridable: true,
val: `${val}`,
};
},
};
46 changes: 24 additions & 22 deletions src/core/PluginInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as path from 'path';
import SwPlugin from '../core/SwPlugin';
import { createLogger } from '../logging';
import * as semver from 'semver';
import resolve from 'resolve';

const logger = createLogger(__filename);

Expand All @@ -33,7 +34,7 @@ while (topModule.parent) {
export default class PluginInstaller {
private readonly pluginDir: string;
readonly require: (name: string) => any = topModule.require.bind(topModule);
private readonly resolve = (request: string) => (module.constructor as any)._resolveFilename(request, topModule);
private readonly resolve = (request: string) => resolve.sync(request);
Copy link
Contributor

Choose a reason for hiding this comment

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

Question about this, the current form (module.constructor as any)._resolveFilename(request, topModule); ensures that the resolution is done from the point of view of the topmost module (the main app). This is necessary because if for example you have skwalking npm linked into a project instead of installed alongside all its dependancies then normal resolve will get the wrong path, one that sits in the skywalking node_modules path instead of the applicatiuon. Does the resolve package do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I missed this point. According to the documentation resolve, this can be done by
private readonly resolve = (request: string) => resolve.sync(request, {basedir: path.dirname(topModule.id) });
if You agree i will update later

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, well I checked your fix and it seems to work, so I am ok with this.


constructor() {
this.pluginDir = path.resolve(__dirname, '..', 'plugins');
Expand All @@ -57,7 +58,8 @@ export default class PluginInstaller {
}

const packageJsonPath = this.resolve(`${plugin.module}/package.json`);
const version = this.require(packageJsonPath).version;

const version = JSON.parse(fs.readFileSync(packageJsonPath).toString()).version;

if (!semver.satisfies(version, plugin.versions)) {
logger.info(`Plugin ${plugin.module} ${version} doesn't satisfy the supported version ${plugin.versions}`);
Expand All @@ -74,30 +76,30 @@ export default class PluginInstaller {

install(): void {
fs.readdirSync(this.pluginDir)
.filter((file) => !(file.endsWith('.d.ts') || file.endsWith('.js.map')))
.forEach((file) => {
let plugin;
const pluginFile = path.join(this.pluginDir, file);
.filter((file) => !(file.endsWith('.d.ts') || file.endsWith('.js.map')))
.forEach((file) => {
let plugin;
const pluginFile = path.join(this.pluginDir, file);

try {
plugin = require(pluginFile).default as SwPlugin;
const { isSupported, version } = this.checkModuleVersion(plugin);
try {
plugin = require(pluginFile).default as SwPlugin;
const { isSupported, version } = this.checkModuleVersion(plugin);

if (!isSupported) {
logger.info(`Plugin ${plugin.module} ${version} doesn't satisfy the supported version ${plugin.versions}`);
return;
}
if (!isSupported) {
logger.info(`Plugin ${plugin.module} ${version} doesn't satisfy the supported version ${plugin.versions}`);
return;
}

logger.info(`Installing plugin ${plugin.module} ${plugin.versions}`);
logger.info(`Installing plugin ${plugin.module} ${plugin.versions}`);

plugin.install(this);
} catch (e) {
if (plugin) {
logger.error(`Error installing plugin ${plugin.module} ${plugin.versions}`);
} else {
logger.error(`Error processing plugin ${pluginFile}`);
plugin.install(this);
} catch (e) {
if (plugin) {
logger.error(`Error installing plugin ${plugin.module} ${plugin.versions}`);
} else {
logger.error(`Error processing plugin ${pluginFile} ${e}`);
}
}
}
});
});
}
}
Loading