From b89f460f583d46c6ac66f195f2aaf1ccc549b3e6 Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Mon, 8 Aug 2022 19:02:10 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E2=9C=85=20add=20install=20working=20for?= =?UTF-8?q?=20unit=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yad <459647480@qq.com> --- .github/workflows/unit.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index c5cfe874..481e47b6 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -23,9 +23,13 @@ jobs: uses: dapr/setup-dapr@v1 with: version: '1.8.0' - - name: Install Docker for macOS + - name: Install Docker & install skywalking oapServer uses: docker-practice/actions-setup-docker@master - if: ${{ matrix.platform == 'macos-latest' }} + - run: | + docker version + docker pull apache/skywalking-oap-server:8.4.0-es6 + docker run -d --name oap -p 12800:12800 -p 11800:11800 apache/skywalking-oap-server:8.4.0-es6 + docker ps - name: Initialize Dapr run: dapr init -s --runtime-version ${{ matrix.dapr-version }} - name: Install dependencies From 2a327e00d134b7c81fa5f096f7b7b0875572b35e Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Mon, 29 Aug 2022 08:29:43 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E2=9C=A8=20feature=20syswalking=20trace?= =?UTF-8?q?=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yad <459647480@qq.com> --- docs/generated/api.json | 235 +++++++++++ docs/generated/api.md | 15 + package-lock.json | 389 +++++++++++++++++- package.json | 3 +- src/loader.ts | 58 ++- src/main.ts | 2 +- src/openfunction/context.ts | 44 ++ .../plugin/skywalking/skywalking.ts | 107 +++++ src/openfunction/system_info.ts | 13 + test/integration/async_server.ts | 5 +- test/integration/http_binding.ts | 5 +- test/loader.ts | 7 +- test/plugin.ts | 8 +- 13 files changed, 866 insertions(+), 25 deletions(-) create mode 100644 src/openfunction/plugin/skywalking/skywalking.ts create mode 100644 src/openfunction/system_info.ts diff --git a/docs/generated/api.json b/docs/generated/api.json index d1902656..4243d931 100644 --- a/docs/generated/api.json +++ b/docs/generated/api.json @@ -2039,6 +2039,34 @@ "endIndex": 12 } }, + { + "kind": "PropertySignature", + "canonicalReference": "@openfunction/functions-framework!OpenFunctionContext#tracing:member", + "docComment": "/**\n * Optional trace config\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "tracing?: " + }, + { + "kind": "Reference", + "text": "TraceConfig", + "canonicalReference": "@openfunction/functions-framework!TraceConfig:interface" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": true, + "releaseTag": "Public", + "name": "tracing", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, { "kind": "PropertySignature", "canonicalReference": "@openfunction/functions-framework!OpenFunctionContext#version:member", @@ -3168,6 +3196,213 @@ "name": "Knative" } ] + }, + { + "kind": "Interface", + "canonicalReference": "@openfunction/functions-framework!TraceConfig:interface", + "docComment": "/**\n * The config of the trace.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface TraceConfig " + } + ], + "releaseTag": "Public", + "name": "TraceConfig", + "preserveMemberOrder": false, + "members": [ + { + "kind": "PropertySignature", + "canonicalReference": "@openfunction/functions-framework!TraceConfig#baggage:member", + "docComment": "/**\n * Trace baggage\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "baggage: " + }, + { + "kind": "Reference", + "text": "Record", + "canonicalReference": "!Record:type" + }, + { + "kind": "Content", + "text": "" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "baggage", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 3 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@openfunction/functions-framework!TraceConfig#enabled:member", + "docComment": "/**\n * This is trace switch\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "enabled: " + }, + { + "kind": "Content", + "text": "boolean" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "enabled", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@openfunction/functions-framework!TraceConfig#provider:member", + "docComment": "/**\n * Trace Provider\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "provider?: " + }, + { + "kind": "Reference", + "text": "TraceProvider", + "canonicalReference": "@openfunction/functions-framework!TraceProvider:interface" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": true, + "releaseTag": "Public", + "name": "provider", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@openfunction/functions-framework!TraceConfig#tags:member", + "docComment": "/**\n * Trace tags\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "tags: " + }, + { + "kind": "Reference", + "text": "Record", + "canonicalReference": "!Record:type" + }, + { + "kind": "Content", + "text": "" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "tags", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 3 + } + } + ], + "extendsTokenRanges": [] + }, + { + "kind": "Interface", + "canonicalReference": "@openfunction/functions-framework!TraceProvider:interface", + "docComment": "/**\n * The trace provider info.\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "export interface TraceProvider " + } + ], + "releaseTag": "Public", + "name": "TraceProvider", + "preserveMemberOrder": false, + "members": [ + { + "kind": "PropertySignature", + "canonicalReference": "@openfunction/functions-framework!TraceProvider#name:member", + "docComment": "/**\n * Provider name Now is just support skywalking\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "name: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "name", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + }, + { + "kind": "PropertySignature", + "canonicalReference": "@openfunction/functions-framework!TraceProvider#oapServer:member", + "docComment": "/**\n * OapServer address example [skywalking-oap:11800]\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "oapServer: " + }, + { + "kind": "Content", + "text": "string" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isReadonly": false, + "isOptional": false, + "releaseTag": "Public", + "name": "oapServer", + "propertyTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + } + } + ], + "extendsTokenRanges": [] } ] } diff --git a/docs/generated/api.md b/docs/generated/api.md index 864c4d34..ea156c68 100644 --- a/docs/generated/api.md +++ b/docs/generated/api.md @@ -139,6 +139,7 @@ export interface OpenFunctionContext { postPlugins?: string[]; prePlugins?: string[]; runtime: `${RuntimeType}` | `${Capitalize}` | `${Uppercase}`; + tracing?: TraceConfig; version: string; } @@ -188,6 +189,20 @@ export enum RuntimeType { Knative = "knative" } +// @public +export interface TraceConfig { + baggage: Record; + enabled: boolean; + provider?: TraceProvider; + tags: Record; +} + +// @public +export interface TraceProvider { + name: string; + oapServer: string; +} + // (No @packageDocumentation comment for this package) ``` diff --git a/package-lock.json b/package-lock.json index e2bc777b..3d628b9f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,8 @@ "minimist": "^1.2.6", "on-finished": "^2.4.1", "read-pkg-up": "^7.0.1", - "semver": "^7.3.7" + "semver": "^7.3.7", + "skywalking-backend-js": "^0.5.1" }, "bin": { "functions-framework": "build/src/main.js", @@ -92,6 +93,24 @@ "node": ">=6.9.0" } }, + "node_modules/@colors/colors": { + "version": "1.5.0", + "resolved": "https://registry.npmmirror.com/@colors/colors/-/colors-1.5.0.tgz", + "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", + "engines": { + "node": ">=0.1.90" + } + }, + "node_modules/@dabh/diagnostics": { + "version": "2.0.3", + "resolved": "https://registry.npmmirror.com/@dabh/diagnostics/-/diagnostics-2.0.3.tgz", + "integrity": "sha512-hrlQOIi7hAfzsMqlGSFyVucrx38O+j6wiGOf//H2ecvIEqYN4ADBSS2iLMh5UFyDunCNniUIPk/q3riFv45xRA==", + "dependencies": { + "colorspace": "1.1.x", + "enabled": "2.0.x", + "kuler": "^2.0.0" + } + }, "node_modules/@dapr/dapr": { "version": "2.3.1", "resolved": "https://registry.npmmirror.com/@dapr/dapr/-/dapr-2.3.1.tgz", @@ -1213,6 +1232,11 @@ "node": ">=8" } }, + "node_modules/async": { + "version": "3.2.4", + "resolved": "https://registry.npmmirror.com/async/-/async-3.2.4.tgz", + "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -1718,6 +1742,15 @@ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" }, + "node_modules/color": { + "version": "3.2.1", + "resolved": "https://registry.npmmirror.com/color/-/color-3.2.1.tgz", + "integrity": "sha512-aBl7dZI9ENN6fUGC7mWpMTPNHmWUSNan9tuWN6ahh5ZLNk9baLJOnSMlrQkHcrfFgz2/RigjUVAjdx36VcemKA==", + "dependencies": { + "color-convert": "^1.9.3", + "color-string": "^1.6.0" + } + }, "node_modules/color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -1731,6 +1764,15 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, + "node_modules/color-string": { + "version": "1.9.1", + "resolved": "https://registry.npmmirror.com/color-string/-/color-string-1.9.1.tgz", + "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", + "dependencies": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } + }, "node_modules/colors": { "version": "1.2.5", "resolved": "https://registry.npmmirror.com/colors/-/colors-1.2.5.tgz", @@ -1740,6 +1782,15 @@ "node": ">=0.1.90" } }, + "node_modules/colorspace": { + "version": "1.1.4", + "resolved": "https://registry.npmmirror.com/colorspace/-/colorspace-1.1.4.tgz", + "integrity": "sha512-BgvKJiuVu1igBUF2kEjRCZXol6wiiGbY5ipL/oVPwm0BL9sIpMIzM8IK7vwuxIIzOXMV3Ey5w+vxhm0rR/TN8w==", + "dependencies": { + "color": "^3.1.3", + "text-hex": "1.0.x" + } + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -2291,6 +2342,11 @@ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, + "node_modules/enabled": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/enabled/-/enabled-2.0.0.tgz", + "integrity": "sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==" + }, "node_modules/encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", @@ -3122,6 +3178,11 @@ "integrity": "sha512-XBU9RXeoYc2/VnvMhplAxEmZLfIk7cvTBu+xwoBuTI8pL19E03cmca17QQycKIdxgwCeFA/a4u27gv1h3ya5LQ==", "dev": true }, + "node_modules/fecha": { + "version": "4.2.3", + "resolved": "https://registry.npmmirror.com/fecha/-/fecha-4.2.3.tgz", + "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==" + }, "node_modules/figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -3231,6 +3292,11 @@ "integrity": "sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==", "dev": true }, + "node_modules/fn.name": { + "version": "1.1.0", + "resolved": "https://registry.npmmirror.com/fn.name/-/fn.name-1.1.0.tgz", + "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" + }, "node_modules/follow-redirects": { "version": "1.14.9", "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.14.9.tgz", @@ -3810,6 +3876,17 @@ "node": ">=10.17.0" } }, + "node_modules/husky": { + "version": "7.0.4", + "resolved": "https://registry.npmmirror.com/husky/-/husky-7.0.4.tgz", + "integrity": "sha512-vbaCKN2QLtP/vD4yvs6iz6hBEo6wkSzs8HpRah1Z6aGmF2KW5PdYuAd7uX5a+OyBZHBhd+TFLqgjUgytQr4RvQ==", + "bin": { + "husky": "lib/bin.js" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/hyperid": { "version": "3.0.1", "resolved": "https://registry.npmmirror.com/hyperid/-/hyperid-3.0.1.tgz", @@ -4311,7 +4388,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", - "dev": true, "engines": { "node": ">=8" }, @@ -4519,6 +4595,11 @@ "node": ">=0.10.0" } }, + "node_modules/kuler": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/kuler/-/kuler-2.0.0.tgz", + "integrity": "sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==" + }, "node_modules/latest-version": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", @@ -4680,6 +4761,18 @@ "node": ">=8" } }, + "node_modules/logform": { + "version": "2.4.2", + "resolved": "https://registry.npmmirror.com/logform/-/logform-2.4.2.tgz", + "integrity": "sha512-W4c9himeAwXEdZ05dQNerhFz2XG80P9Oj0loPUMV23VC2it0orMHQhJm4hdnnor3rd1HsGf6a2lPwBM1zeXHGw==", + "dependencies": { + "@colors/colors": "1.5.0", + "fecha": "^4.2.0", + "ms": "^2.1.1", + "safe-stable-stringify": "^2.3.1", + "triple-beam": "^1.3.0" + } + }, "node_modules/long": { "version": "4.0.0", "resolved": "https://registry.npmmirror.com/long/-/long-4.0.0.tgz", @@ -5418,6 +5511,14 @@ "wrappy": "1" } }, + "node_modules/one-time": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/one-time/-/one-time-1.0.0.tgz", + "integrity": "sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g==", + "dependencies": { + "fn.name": "1.x.x" + } + }, "node_modules/onetime": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", @@ -6056,7 +6157,6 @@ "version": "3.6.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "dev": true, "dependencies": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", @@ -6319,6 +6419,14 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, + "node_modules/safe-stable-stringify": { + "version": "2.3.1", + "resolved": "https://registry.npmmirror.com/safe-stable-stringify/-/safe-stable-stringify-2.3.1.tgz", + "integrity": "sha512-kYBSfT+troD9cDA85VDnHZ1rpHC50O0g1e6WlGHVCz/g+JS+9WKLj+XwFYyR8UbrZN8ll9HUpDAAddY58MGisg==", + "engines": { + "node": ">=10" + } + }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -6496,6 +6604,19 @@ "integrity": "sha512-KWcOiKeQj6ZyXx7zq4YxSMgHRlod4czeBQZrPb8OKcohcqAXShm7E20kEMle9WBt26hFcAf0qLOcp5zmY7kOqQ==", "dev": true }, + "node_modules/simple-swizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmmirror.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==", + "dependencies": { + "is-arrayish": "^0.3.1" + } + }, + "node_modules/simple-swizzle/node_modules/is-arrayish": { + "version": "0.3.2", + "resolved": "https://registry.npmmirror.com/is-arrayish/-/is-arrayish-0.3.2.tgz", + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" + }, "node_modules/sinon": { "version": "14.0.0", "resolved": "https://registry.npmjs.org/sinon/-/sinon-14.0.0.tgz", @@ -6544,6 +6665,26 @@ "node": ">=8" } }, + "node_modules/skywalking-backend-js": { + "version": "0.5.1", + "resolved": "https://registry.npmmirror.com/skywalking-backend-js/-/skywalking-backend-js-0.5.1.tgz", + "integrity": "sha512-gu56s9n+581pt1Aw/N3zf6pe/ulLq6FVXfRzqSRiAc6W8w0kaKZBl72S/Epz6cgD1/LmMS151Za09sfVzBBjsA==", + "hasInstallScript": true, + "dependencies": { + "@grpc/grpc-js": "^1.6.7", + "google-protobuf": "^3.14.0", + "husky": "^7.0.4", + "semver": "^7.3.2", + "tslib": "^2.0.3", + "uuid": "^8.1.0", + "winston": "^3.2.1" + } + }, + "node_modules/skywalking-backend-js/node_modules/tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -6662,6 +6803,14 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "node_modules/stack-trace": { + "version": "0.0.10", + "resolved": "https://registry.npmmirror.com/stack-trace/-/stack-trace-0.0.10.tgz", + "integrity": "sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==", + "engines": { + "node": "*" + } + }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -6674,7 +6823,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "dev": true, "dependencies": { "safe-buffer": "~5.2.0" } @@ -6683,7 +6831,6 @@ "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "dev": true, "funding": [ { "type": "github", @@ -6907,6 +7054,11 @@ "node": ">= 8" } }, + "node_modules/text-hex": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/text-hex/-/text-hex-1.0.0.tgz", + "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==" + }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -6989,6 +7141,11 @@ "node": ">=8" } }, + "node_modules/triple-beam": { + "version": "1.3.0", + "resolved": "https://registry.npmmirror.com/triple-beam/-/triple-beam-1.3.0.tgz", + "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" + }, "node_modules/trouter": { "version": "3.2.0", "resolved": "https://registry.npmmirror.com/trouter/-/trouter-3.2.0.tgz", @@ -7284,8 +7441,7 @@ "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "node_modules/utils-merge": { "version": "1.0.1", @@ -7450,6 +7606,39 @@ "node": ">=8" } }, + "node_modules/winston": { + "version": "3.8.1", + "resolved": "https://registry.npmmirror.com/winston/-/winston-3.8.1.tgz", + "integrity": "sha512-r+6YAiCR4uI3N8eQNOg8k3P3PqwAm20cLKlzVD9E66Ch39+LZC+VH1UKf9JemQj2B3QoUHfKD7Poewn0Pr3Y1w==", + "dependencies": { + "@dabh/diagnostics": "^2.0.2", + "async": "^3.2.3", + "is-stream": "^2.0.0", + "logform": "^2.4.0", + "one-time": "^1.0.0", + "readable-stream": "^3.4.0", + "safe-stable-stringify": "^2.3.1", + "stack-trace": "0.0.x", + "triple-beam": "^1.3.0", + "winston-transport": "^4.5.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, + "node_modules/winston-transport": { + "version": "4.5.0", + "resolved": "https://registry.npmmirror.com/winston-transport/-/winston-transport-4.5.0.tgz", + "integrity": "sha512-YpZzcUzBedhlTAfJg6vJDlyEai/IFMIVcaEZZyl3UXIl4gmqRpU7AE89AHLkbzLUsv0NVmw7ts+iztqKxxPW1Q==", + "dependencies": { + "logform": "^2.3.2", + "readable-stream": "^3.6.0", + "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 6.4.0" + } + }, "node_modules/word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", @@ -7690,6 +7879,21 @@ "js-tokens": "^4.0.0" } }, + "@colors/colors": { + "version": "1.5.0", + "resolved": "https://registry.npmmirror.com/@colors/colors/-/colors-1.5.0.tgz", + "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==" + }, + "@dabh/diagnostics": { + "version": "2.0.3", + "resolved": "https://registry.npmmirror.com/@dabh/diagnostics/-/diagnostics-2.0.3.tgz", + "integrity": "sha512-hrlQOIi7hAfzsMqlGSFyVucrx38O+j6wiGOf//H2ecvIEqYN4ADBSS2iLMh5UFyDunCNniUIPk/q3riFv45xRA==", + "requires": { + "colorspace": "1.1.x", + "enabled": "2.0.x", + "kuler": "^2.0.0" + } + }, "@dapr/dapr": { "version": "2.3.1", "resolved": "https://registry.npmmirror.com/@dapr/dapr/-/dapr-2.3.1.tgz", @@ -8633,6 +8837,11 @@ "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", "dev": true }, + "async": { + "version": "3.2.4", + "resolved": "https://registry.npmmirror.com/async/-/async-3.2.4.tgz", + "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==" + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -9028,6 +9237,15 @@ } } }, + "color": { + "version": "3.2.1", + "resolved": "https://registry.npmmirror.com/color/-/color-3.2.1.tgz", + "integrity": "sha512-aBl7dZI9ENN6fUGC7mWpMTPNHmWUSNan9tuWN6ahh5ZLNk9baLJOnSMlrQkHcrfFgz2/RigjUVAjdx36VcemKA==", + "requires": { + "color-convert": "^1.9.3", + "color-string": "^1.6.0" + } + }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -9041,12 +9259,30 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, + "color-string": { + "version": "1.9.1", + "resolved": "https://registry.npmmirror.com/color-string/-/color-string-1.9.1.tgz", + "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", + "requires": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } + }, "colors": { "version": "1.2.5", "resolved": "https://registry.npmmirror.com/colors/-/colors-1.2.5.tgz", "integrity": "sha512-erNRLao/Y3Fv54qUa0LBB+//Uf3YwMUmdJinN20yMXm9zdKKqH9wt7R9IIVZ+K7ShzfpLV/Zg8+VyrBJYB4lpg==", "dev": true }, + "colorspace": { + "version": "1.1.4", + "resolved": "https://registry.npmmirror.com/colorspace/-/colorspace-1.1.4.tgz", + "integrity": "sha512-BgvKJiuVu1igBUF2kEjRCZXol6wiiGbY5ipL/oVPwm0BL9sIpMIzM8IK7vwuxIIzOXMV3Ey5w+vxhm0rR/TN8w==", + "requires": { + "color": "^3.1.3", + "text-hex": "1.0.x" + } + }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -9474,6 +9710,11 @@ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, + "enabled": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/enabled/-/enabled-2.0.0.tgz", + "integrity": "sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==" + }, "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", @@ -10101,6 +10342,11 @@ "integrity": "sha512-XBU9RXeoYc2/VnvMhplAxEmZLfIk7cvTBu+xwoBuTI8pL19E03cmca17QQycKIdxgwCeFA/a4u27gv1h3ya5LQ==", "dev": true }, + "fecha": { + "version": "4.2.3", + "resolved": "https://registry.npmmirror.com/fecha/-/fecha-4.2.3.tgz", + "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==" + }, "figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -10188,6 +10434,11 @@ "integrity": "sha512-8/sOawo8tJ4QOBX8YlQBMxL8+RLZfxMQOif9o0KUKTNTjMYElWPE0r/m5VNFxTRd0NSw8qSy8dajrwX4RYI1Hw==", "dev": true }, + "fn.name": { + "version": "1.1.0", + "resolved": "https://registry.npmmirror.com/fn.name/-/fn.name-1.1.0.tgz", + "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" + }, "follow-redirects": { "version": "1.14.9", "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.14.9.tgz", @@ -10603,6 +10854,11 @@ "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", "dev": true }, + "husky": { + "version": "7.0.4", + "resolved": "https://registry.npmmirror.com/husky/-/husky-7.0.4.tgz", + "integrity": "sha512-vbaCKN2QLtP/vD4yvs6iz6hBEo6wkSzs8HpRah1Z6aGmF2KW5PdYuAd7uX5a+OyBZHBhd+TFLqgjUgytQr4RvQ==" + }, "hyperid": { "version": "3.0.1", "resolved": "https://registry.npmmirror.com/hyperid/-/hyperid-3.0.1.tgz", @@ -10952,8 +11208,7 @@ "is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", - "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", - "dev": true + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==" }, "is-string": { "version": "1.0.7", @@ -11116,6 +11371,11 @@ "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", "dev": true }, + "kuler": { + "version": "2.0.0", + "resolved": "https://registry.npmmirror.com/kuler/-/kuler-2.0.0.tgz", + "integrity": "sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==" + }, "latest-version": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/latest-version/-/latest-version-5.1.0.tgz", @@ -11243,6 +11503,18 @@ } } }, + "logform": { + "version": "2.4.2", + "resolved": "https://registry.npmmirror.com/logform/-/logform-2.4.2.tgz", + "integrity": "sha512-W4c9himeAwXEdZ05dQNerhFz2XG80P9Oj0loPUMV23VC2it0orMHQhJm4hdnnor3rd1HsGf6a2lPwBM1zeXHGw==", + "requires": { + "@colors/colors": "1.5.0", + "fecha": "^4.2.0", + "ms": "^2.1.1", + "safe-stable-stringify": "^2.3.1", + "triple-beam": "^1.3.0" + } + }, "long": { "version": "4.0.0", "resolved": "https://registry.npmmirror.com/long/-/long-4.0.0.tgz", @@ -11786,6 +12058,14 @@ "wrappy": "1" } }, + "one-time": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/one-time/-/one-time-1.0.0.tgz", + "integrity": "sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g==", + "requires": { + "fn.name": "1.x.x" + } + }, "onetime": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", @@ -12260,7 +12540,6 @@ "version": "3.6.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "dev": true, "requires": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", @@ -12444,6 +12723,11 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, + "safe-stable-stringify": { + "version": "2.3.1", + "resolved": "https://registry.npmmirror.com/safe-stable-stringify/-/safe-stable-stringify-2.3.1.tgz", + "integrity": "sha512-kYBSfT+troD9cDA85VDnHZ1rpHC50O0g1e6WlGHVCz/g+JS+9WKLj+XwFYyR8UbrZN8ll9HUpDAAddY58MGisg==" + }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -12594,6 +12878,21 @@ "integrity": "sha512-KWcOiKeQj6ZyXx7zq4YxSMgHRlod4czeBQZrPb8OKcohcqAXShm7E20kEMle9WBt26hFcAf0qLOcp5zmY7kOqQ==", "dev": true }, + "simple-swizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmmirror.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==", + "requires": { + "is-arrayish": "^0.3.1" + }, + "dependencies": { + "is-arrayish": { + "version": "0.3.2", + "resolved": "https://registry.npmmirror.com/is-arrayish/-/is-arrayish-0.3.2.tgz", + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" + } + } + }, "sinon": { "version": "14.0.0", "resolved": "https://registry.npmjs.org/sinon/-/sinon-14.0.0.tgz", @@ -12634,6 +12933,27 @@ } } }, + "skywalking-backend-js": { + "version": "0.5.1", + "resolved": "https://registry.npmmirror.com/skywalking-backend-js/-/skywalking-backend-js-0.5.1.tgz", + "integrity": "sha512-gu56s9n+581pt1Aw/N3zf6pe/ulLq6FVXfRzqSRiAc6W8w0kaKZBl72S/Epz6cgD1/LmMS151Za09sfVzBBjsA==", + "requires": { + "@grpc/grpc-js": "^1.6.7", + "google-protobuf": "^3.14.0", + "husky": "^7.0.4", + "semver": "^7.3.2", + "tslib": "^2.0.3", + "uuid": "^8.1.0", + "winston": "^3.2.1" + }, + "dependencies": { + "tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + } + } + }, "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -12733,6 +13053,11 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "stack-trace": { + "version": "0.0.10", + "resolved": "https://registry.npmmirror.com/stack-trace/-/stack-trace-0.0.10.tgz", + "integrity": "sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==" + }, "statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -12742,7 +13067,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "dev": true, "requires": { "safe-buffer": "~5.2.0" }, @@ -12750,8 +13074,7 @@ "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "dev": true + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" } } }, @@ -12915,6 +13238,11 @@ "yallist": "^4.0.0" } }, + "text-hex": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/text-hex/-/text-hex-1.0.0.tgz", + "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==" + }, "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -12979,6 +13307,11 @@ "integrity": "sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==", "dev": true }, + "triple-beam": { + "version": "1.3.0", + "resolved": "https://registry.npmmirror.com/triple-beam/-/triple-beam-1.3.0.tgz", + "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" + }, "trouter": { "version": "3.2.0", "resolved": "https://registry.npmmirror.com/trouter/-/trouter-3.2.0.tgz", @@ -13202,8 +13535,7 @@ "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "utils-merge": { "version": "1.0.1", @@ -13334,6 +13666,33 @@ "string-width": "^4.0.0" } }, + "winston": { + "version": "3.8.1", + "resolved": "https://registry.npmmirror.com/winston/-/winston-3.8.1.tgz", + "integrity": "sha512-r+6YAiCR4uI3N8eQNOg8k3P3PqwAm20cLKlzVD9E66Ch39+LZC+VH1UKf9JemQj2B3QoUHfKD7Poewn0Pr3Y1w==", + "requires": { + "@dabh/diagnostics": "^2.0.2", + "async": "^3.2.3", + "is-stream": "^2.0.0", + "logform": "^2.4.0", + "one-time": "^1.0.0", + "readable-stream": "^3.4.0", + "safe-stable-stringify": "^2.3.1", + "stack-trace": "0.0.x", + "triple-beam": "^1.3.0", + "winston-transport": "^4.5.0" + } + }, + "winston-transport": { + "version": "4.5.0", + "resolved": "https://registry.npmmirror.com/winston-transport/-/winston-transport-4.5.0.tgz", + "integrity": "sha512-YpZzcUzBedhlTAfJg6vJDlyEai/IFMIVcaEZZyl3UXIl4gmqRpU7AE89AHLkbzLUsv0NVmw7ts+iztqKxxPW1Q==", + "requires": { + "logform": "^2.3.2", + "readable-stream": "^3.6.0", + "triple-beam": "^1.3.0" + } + }, "word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", diff --git a/package.json b/package.json index 26e61e43..d4ca8423 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "minimist": "^1.2.6", "on-finished": "^2.4.1", "read-pkg-up": "^7.0.1", - "semver": "^7.3.7" + "semver": "^7.3.7", + "skywalking-backend-js": "^0.5.1" }, "scripts": { "test": "cross-env DEBUG=common:*,ofn:* mocha build/test -t 60000 --recursive --exit", diff --git a/src/loader.ts b/src/loader.ts index c77f687d..88aee2e8 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -31,6 +31,14 @@ import {Plugin, PluginStore, PluginMap} from './openfunction/plugin'; import {HandlerFunction} from './functions'; import {getRegisteredFunction} from './function_registry'; import {SignatureType} from './types'; +import {FrameworkOptions} from './options'; +import {OpenFunctionContext} from './openfunction/context'; +import { + SKYWALKINGNAME, + SkyWalkingPlugin, +} from './openfunction/plugin/skywalking/skywalking'; + +import {SystemInfoItem, systemInfoStore} from './openfunction/system_info'; // Dynamic import function required to load user code packaged as an // ES module is only available on Node.js v13.2.0 and up. @@ -214,9 +222,12 @@ function getFunctionModulePath(codeLocation: string): string | null { * @return A named plugin map object or null. */ export async function getFunctionPlugins( - codeLocation: string + options: FrameworkOptions ): Promise { - const files = getPluginsModulePath(codeLocation); + // First load BUIDIN type plugin + await loadBuidInPlugins(options); + + const files = getPluginsModulePath(options.sourceLocation); if (!files) return null; // Try to load all plugin module files @@ -272,3 +283,46 @@ function getPluginsModulePath(codeLocation: string): string[] | null { return null; } } + +/** + * It loads BUIDIN type plugins from the /openfunction/plugin. + * @param context - The context of OpenFunction. + */ +async function loadBuidInPlugins(options: FrameworkOptions) { + if (!options.context) { + console.warn("The context is undefined can't load BUIDIN type plugins"); + return; + } + const store = PluginStore.Instance(PluginStore.Type.BUILTIN); + //Provide system info for BUILDIN type plugins + systemInfoStore[SystemInfoItem.FunctionName] = options.target; + systemInfoStore[SystemInfoItem.RuntimeType] = + options.context.runtime || 'knative'; + + if (checkTraceConfig(options.context)) { + const skywalking = new SkyWalkingPlugin(options.context.tracing!); + store.register(skywalking); + } +} + +/** + * It check trace config ,it will set default value if it is enbaled. + * @param tracing - The config of TraceConfig. + */ +function checkTraceConfig(context: OpenFunctionContext): boolean { + if (!context.tracing) { + console.warn('TraceConfig is invalid'); + return false; + } + if (!context.tracing.enabled) { + return false; + } + + //Set default trace provider config + context.tracing.provider = { + name: context.tracing.provider?.name || SKYWALKINGNAME, + oapServer: context.tracing.provider?.oapServer || '127.0.0.1:11800', + }; + + return true; +} diff --git a/src/main.ts b/src/main.ts index 0833bdf9..4589ba8f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -55,7 +55,7 @@ export const main = async () => { const {userFunction, signatureType} = loadedFunction; // Load function plugins before starting server - await getFunctionPlugins(options.sourceLocation); + await getFunctionPlugins(options); // Try to determine the server runtime // Considering the async runtime in the first place diff --git a/src/openfunction/context.ts b/src/openfunction/context.ts index f2ac10ba..aec0290d 100644 --- a/src/openfunction/context.ts +++ b/src/openfunction/context.ts @@ -38,6 +38,10 @@ export interface OpenFunctionContext { * Optional plugins to be executed after user function. */ postPlugins?: string[]; + /** + * Optional trace config + */ + tracing?: TraceConfig; } /** @@ -147,3 +151,43 @@ export class ContextUtils { return component?.componentType.split('.')[0] === ComponentType.PubSub; } } + +/** + * The config of the trace. + * @public + */ +export interface TraceConfig { + /** + * This is trace switch + */ + enabled: boolean; + /** + * Trace Provider + */ + provider?: TraceProvider; + /** + * Trace tags + */ + tags: Record; + /** + * Trace baggage + */ + baggage: Record; +} + +/** + * The trace provider info. + * @public + */ +export interface TraceProvider { + /** + * Provider name + * Now is just support skywalking + */ + name: string; + /** + * OapServer address + * example [skywalking-oap:11800] + */ + oapServer: string; +} diff --git a/src/openfunction/plugin/skywalking/skywalking.ts b/src/openfunction/plugin/skywalking/skywalking.ts new file mode 100644 index 00000000..edf07451 --- /dev/null +++ b/src/openfunction/plugin/skywalking/skywalking.ts @@ -0,0 +1,107 @@ +import {forEach} from 'lodash'; +import agent, {ContextManager} from 'skywalking-backend-js'; +import SpanContext from 'skywalking-backend-js/lib/trace/context/SpanContext'; +import {SpanLayer} from 'skywalking-backend-js/lib/proto/language-agent/Tracing_pb'; +import {Component} from 'skywalking-backend-js/lib/trace/Component'; +import {Tag} from 'skywalking-backend-js/lib/Tag'; +import Span from 'skywalking-backend-js/lib/trace/span/Span'; +import Context from 'skywalking-backend-js/lib/trace/context/Context'; + +import {Plugin} from '../../plugin'; +import {OpenFunctionRuntime} from '../../runtime'; +import {TraceConfig} from '../../context'; +import {SystemInfoItem, systemInfoStore} from '../../system_info'; + +// https://github.com/apache/skywalking/blob/master/oap-server/server-starter/src/main/resources/component-libraries.yml#L515 +const componentIDOpenFunction = new Component(5013); + +export const SKYWALKINGNAME = 'skywalking'; + +class Trace { + private span: Span; + private spanContext: Context; + constructor(span: Span, spanContext: Context) { + this.span = span; + this.spanContext = spanContext; + } + + async start(tags: Array) { + forEach(tags, tag => { + this.span.tag(tag); + }); + this.span.layer = SpanLayer.FAAS; + this.span.component = componentIDOpenFunction; + this.span.start(); + this.span.async(); + } + + async stop() { + this.span.stop(); + this.spanContext.stop(this.span); + await agent.flush(); + } +} + +/** + * Defining an class to provide trace ability alugin by skywalking . + * @public + **/ +export class SkyWalkingPlugin extends Plugin { + private trace: Trace | undefined; + private tags: Array = []; + + constructor(traceConfig: TraceConfig) { + super(SKYWALKINGNAME, 'v1'); + agent.start({ + serviceName: systemInfoStore[SystemInfoItem.FunctionName], + serviceInstance: systemInfoStore[SystemInfoItem.Instance], + collectorAddress: traceConfig.provider?.oapServer, + }); + + this.iniAttribute(traceConfig); + } + + iniAttribute(traceConfig: TraceConfig) { + traceConfig.tags[SystemInfoItem.RuntimeType] = + systemInfoStore[SystemInfoItem.RuntimeType]; + for (const key in traceConfig.tags) { + this.tags.push({ + key, + val: traceConfig.tags[key], + overridable: false, + }); + } + } + + async execPreHook( + ctx: OpenFunctionRuntime | null, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + plugins: Record + ) { + if (ctx === null) { + console.warn('OpenFunctionRuntime [ctx] is null'); + } + + const context = ContextManager.hasContext + ? ContextManager.current + : new SpanContext(); + + const span = context.newEntrySpan( + `/${systemInfoStore[SystemInfoItem.FunctionName]}`, + undefined + ); + this.trace = new Trace(span, context); + await this.trace.start(this.tags); + } + + async execPostHook( + ctx: OpenFunctionRuntime | null, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + plugins: Record + ) { + if (ctx === null) { + console.warn('OpenFunctionRuntime [ctx] is null'); + } + await this.trace?.stop(); + } +} diff --git a/src/openfunction/system_info.ts b/src/openfunction/system_info.ts new file mode 100644 index 00000000..98a922d6 --- /dev/null +++ b/src/openfunction/system_info.ts @@ -0,0 +1,13 @@ +export enum SystemInfoItem { + RuntimeType = 'RuntimeType', + FunctionName = 'FunctionName', + Instance = 'OpenfunctionInstance', +} + +const systemInfoStore: Record = { + [SystemInfoItem.RuntimeType]: 'knative', + [SystemInfoItem.FunctionName]: 'function', + [SystemInfoItem.Instance]: 'OpenfunctionInstance', +}; + +export {systemInfoStore}; diff --git a/test/integration/async_server.ts b/test/integration/async_server.ts index 8009a44e..6f9e4e27 100644 --- a/test/integration/async_server.ts +++ b/test/integration/async_server.ts @@ -7,6 +7,7 @@ import * as MQTT from 'aedes'; import getAysncServer from '../../src/openfunction/async_server'; import {getFunctionPlugins} from '../../src/loader'; +import {FrameworkOptions} from '../../src/options'; import {Context, Payload} from '../data/mock'; @@ -143,7 +144,9 @@ describe('OpenFunction - Async', () => { }); it('mqtt binding w/ custom plugins', done => { - getFunctionPlugins(process.cwd() + '/test/data').then(plugins => { + getFunctionPlugins({ + sourceLocation: process.cwd() + '/test/data', + } as FrameworkOptions).then(plugins => { const start = get(plugins!.numbers, 'oct'); const app = getAysncServer( diff --git a/test/integration/http_binding.ts b/test/integration/http_binding.ts index 9517cb88..b459dd07 100644 --- a/test/integration/http_binding.ts +++ b/test/integration/http_binding.ts @@ -10,6 +10,7 @@ import {OpenFunctionRuntime} from '../../src/functions'; import {getServer} from '../../src/server'; import {getFunctionPlugins} from '../../src/loader'; import {FUNCTION_STATUS_HEADER_FIELD} from '../../src/types'; +import {FrameworkOptions} from '../../src/options'; import {Context, Payload} from '../data/mock'; @@ -32,7 +33,9 @@ describe('OpenFunction - HTTP Binding', () => { } ); - getFunctionPlugins(process.cwd() + '/test/data').then(() => { + getFunctionPlugins({ + sourceLocation: process.cwd() + '/test/data', + } as FrameworkOptions).then(() => { // Wait 5 seconds for dapr sidecar to start setTimeout(done, 5000); }); diff --git a/test/loader.ts b/test/loader.ts index 52a7589c..0db3b1c0 100644 --- a/test/loader.ts +++ b/test/loader.ts @@ -19,6 +19,7 @@ import * as semver from 'semver'; import {http, cloudEvent, HttpFunction} from '../src'; import * as loader from '../src/loader'; +import {FrameworkOptions} from '../src/options'; describe('Load function and plugins', () => { interface TestData { @@ -132,9 +133,9 @@ describe('Load function and plugins', () => { }); it('should only load valid plugin class and ignore other', async () => { - const loadedPlugins = await loader.getFunctionPlugins( - process.cwd() + '/test/data' - ); + const loadedPlugins = await loader.getFunctionPlugins({ + sourceLocation: process.cwd() + '/test/data', + } as FrameworkOptions); assert.ok(loadedPlugins); ['noname'].forEach(v => assert.ok(!loadedPlugins[v])); diff --git a/test/plugin.ts b/test/plugin.ts index 000bd46c..1566a1b3 100644 --- a/test/plugin.ts +++ b/test/plugin.ts @@ -5,6 +5,7 @@ import {fill, get, random, range} from 'lodash'; import {PluginStore, Plugin} from '../src/openfunction/plugin'; import {getFunctionPlugins} from '../src/loader'; +import {FrameworkOptions} from '../src/options'; class Concater extends Plugin { index = 0; @@ -21,7 +22,12 @@ class Concater extends Plugin { } describe('Store for custom and builtin plugins', () => { - before(async () => await getFunctionPlugins(process.cwd() + '/test/data')); + before( + async () => + await getFunctionPlugins({ + sourceLocation: process.cwd() + '/test/data', + } as FrameworkOptions) + ); const customs = PluginStore.Instance(); From 40299399f61705fba79424f7af3b086c2697af50 Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Mon, 29 Aug 2022 14:32:27 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E2=9C=A8=20feature=20skywalking=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yad <459647480@qq.com> --- .../plugin/skywalking/skywalking.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/openfunction/plugin/skywalking/skywalking.ts b/src/openfunction/plugin/skywalking/skywalking.ts index edf07451..2eb81e5d 100644 --- a/src/openfunction/plugin/skywalking/skywalking.ts +++ b/src/openfunction/plugin/skywalking/skywalking.ts @@ -20,9 +20,16 @@ export const SKYWALKINGNAME = 'skywalking'; class Trace { private span: Span; private spanContext: Context; - constructor(span: Span, spanContext: Context) { - this.span = span; - this.spanContext = spanContext; + + constructor() { + this.spanContext = ContextManager.hasContext + ? ContextManager.current + : new SpanContext(); + + this.span = this.spanContext.newEntrySpan( + `/${systemInfoStore[SystemInfoItem.FunctionName]}`, + undefined + ); } async start(tags: Array) { @@ -52,6 +59,8 @@ export class SkyWalkingPlugin extends Plugin { constructor(traceConfig: TraceConfig) { super(SKYWALKINGNAME, 'v1'); + + // Start skywalking agent agent.start({ serviceName: systemInfoStore[SystemInfoItem.FunctionName], serviceInstance: systemInfoStore[SystemInfoItem.Instance], @@ -81,16 +90,7 @@ export class SkyWalkingPlugin extends Plugin { if (ctx === null) { console.warn('OpenFunctionRuntime [ctx] is null'); } - - const context = ContextManager.hasContext - ? ContextManager.current - : new SpanContext(); - - const span = context.newEntrySpan( - `/${systemInfoStore[SystemInfoItem.FunctionName]}`, - undefined - ); - this.trace = new Trace(span, context); + this.trace = new Trace(); await this.trace.start(this.tags); } From e3ee5012a7923a3ab5a01e5c4fa2b5f06ea66338 Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Mon, 29 Aug 2022 14:43:26 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=F0=9F=94=A5=20remove=20workflow=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yad <459647480@qq.com> --- .github/workflows/unit.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 481e47b6..c5cfe874 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -23,13 +23,9 @@ jobs: uses: dapr/setup-dapr@v1 with: version: '1.8.0' - - name: Install Docker & install skywalking oapServer + - name: Install Docker for macOS uses: docker-practice/actions-setup-docker@master - - run: | - docker version - docker pull apache/skywalking-oap-server:8.4.0-es6 - docker run -d --name oap -p 12800:12800 -p 11800:11800 apache/skywalking-oap-server:8.4.0-es6 - docker ps + if: ${{ matrix.platform == 'macos-latest' }} - name: Initialize Dapr run: dapr init -s --runtime-version ${{ matrix.dapr-version }} - name: Install dependencies From cd8eb9ed83bc57ff0aba9a093b50eaba71104a16 Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Wed, 31 Aug 2022 08:19:15 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=F0=9F=8E=A8=20improve=20skywalking=20plu?= =?UTF-8?q?gin=20&=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yad <459647480@qq.com> --- .github/workflows/trace.yaml | 41 +++++++ package-lock.json | 57 +++++---- package.json | 1 + src/loader.ts | 20 ++-- src/main.ts | 6 +- src/openfunction/context.ts | 4 +- .../plugin/skywalking/skywalking.ts | 39 +++--- src/openfunction/system_info.ts | 13 -- test/build_in_plugin.ts | 111 ++++++++++++++++++ test/integration/async_server.ts | 5 +- test/integration/http_binding.ts | 5 +- test/loader.ts | 7 +- test/plugin.ts | 8 +- 13 files changed, 228 insertions(+), 89 deletions(-) create mode 100644 .github/workflows/trace.yaml delete mode 100644 src/openfunction/system_info.ts create mode 100644 test/build_in_plugin.ts diff --git a/.github/workflows/trace.yaml b/.github/workflows/trace.yaml new file mode 100644 index 00000000..20db578f --- /dev/null +++ b/.github/workflows/trace.yaml @@ -0,0 +1,41 @@ +name: Node.js Unit CI +on: + push: + branches: + - master + pull_request: +jobs: + test: + strategy: + matrix: + node-version: [16] + dapr-version: [1.6.3, 1.7.4, 1.8.3] + platform: [ubuntu-latest] + runs-on: ${{ matrix.platform }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Install Dapr + uses: dapr/setup-dapr@v1 + with: + version: '1.8.0' + - name: Install Docker & start skywalking oap ui + uses: docker-practice/actions-setup-docker@master + - run: | + docker version + docker pull apache/skywalking-oap-server:8.4.0-es6 + docker run -d --name oap -p 12800:12800 -p 11800:11800 apache/skywalking-oap-server:8.4.0-es6 + docker run -d --name ui -p 8088:8080 -e SW_OAP_ADDRESS=127.0.0.1:12800 apache/skywalking-ui:8.4.0 + docker ps + - name: Initialize Dapr + run: dapr init -s --runtime-version ${{ matrix.dapr-version }} + - name: Install dependencies + run: npm install + - name: Build TypeScript project + run: npm run build --if-present + - name: Test + run: npm test diff --git a/package-lock.json b/package-lock.json index 3d628b9f..7c179a13 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@dapr/dapr": "2.3.1", + "axios": "^0.27.2", "body-parser": "^1.20.0", "cloudevents": "^6.0.2", "debug": "^4.3.4", @@ -1240,8 +1241,7 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/available-typed-arrays": { "version": "1.0.5", @@ -1255,12 +1255,12 @@ } }, "node_modules/axios": { - "version": "0.25.0", - "resolved": "https://registry.npmmirror.com/axios/-/axios-0.25.0.tgz", - "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==", - "dev": true, + "version": "0.27.2", + "resolved": "https://registry.npmmirror.com/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", "dependencies": { - "follow-redirects": "^1.14.7" + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" } }, "node_modules/balanced-match": { @@ -1795,7 +1795,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -2249,7 +2248,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -3301,7 +3299,6 @@ "version": "1.14.9", "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.14.9.tgz", "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", - "dev": true, "engines": { "node": ">=4.0" }, @@ -3320,7 +3317,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -7516,6 +7512,15 @@ "node": ">=10.0.0" } }, + "node_modules/wait-on/node_modules/axios": { + "version": "0.25.0", + "resolved": "https://registry.npmmirror.com/axios/-/axios-0.25.0.tgz", + "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==", + "dev": true, + "dependencies": { + "follow-redirects": "^1.14.7" + } + }, "node_modules/wait-on/node_modules/rxjs": { "version": "7.5.5", "resolved": "https://registry.npmmirror.com/rxjs/-/rxjs-7.5.5.tgz", @@ -8845,8 +8850,7 @@ "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "available-typed-arrays": { "version": "1.0.5", @@ -8854,12 +8858,12 @@ "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==" }, "axios": { - "version": "0.25.0", - "resolved": "https://registry.npmmirror.com/axios/-/axios-0.25.0.tgz", - "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==", - "dev": true, + "version": "0.27.2", + "resolved": "https://registry.npmmirror.com/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", "requires": { - "follow-redirects": "^1.14.7" + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" } }, "balanced-match": { @@ -9287,7 +9291,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "requires": { "delayed-stream": "~1.0.0" } @@ -9638,8 +9641,7 @@ "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", - "dev": true + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, "depd": { "version": "2.0.0", @@ -10442,8 +10444,7 @@ "follow-redirects": { "version": "1.14.9", "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.14.9.tgz", - "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", - "dev": true + "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==" }, "foreach": { "version": "2.0.5", @@ -10454,7 +10455,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, "requires": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -13592,6 +13592,15 @@ "rxjs": "^7.5.4" }, "dependencies": { + "axios": { + "version": "0.25.0", + "resolved": "https://registry.npmmirror.com/axios/-/axios-0.25.0.tgz", + "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==", + "dev": true, + "requires": { + "follow-redirects": "^1.14.7" + } + }, "rxjs": { "version": "7.5.5", "resolved": "https://registry.npmmirror.com/rxjs/-/rxjs-7.5.5.tgz", diff --git a/package.json b/package.json index d4ca8423..465beb7f 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ }, "dependencies": { "@dapr/dapr": "2.3.1", + "axios": "^0.27.2", "body-parser": "^1.20.0", "cloudevents": "^6.0.2", "debug": "^4.3.4", diff --git a/src/loader.ts b/src/loader.ts index 88aee2e8..7d42f10f 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -38,8 +38,6 @@ import { SkyWalkingPlugin, } from './openfunction/plugin/skywalking/skywalking'; -import {SystemInfoItem, systemInfoStore} from './openfunction/system_info'; - // Dynamic import function required to load user code packaged as an // ES module is only available on Node.js v13.2.0 and up. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility @@ -222,12 +220,9 @@ function getFunctionModulePath(codeLocation: string): string | null { * @return A named plugin map object or null. */ export async function getFunctionPlugins( - options: FrameworkOptions + codeLocation: string ): Promise { - // First load BUIDIN type plugin - await loadBuidInPlugins(options); - - const files = getPluginsModulePath(options.sourceLocation); + const files = getPluginsModulePath(codeLocation); if (!files) return null; // Try to load all plugin module files @@ -288,19 +283,16 @@ function getPluginsModulePath(codeLocation: string): string[] | null { * It loads BUIDIN type plugins from the /openfunction/plugin. * @param context - The context of OpenFunction. */ -async function loadBuidInPlugins(options: FrameworkOptions) { +export async function loadBuidInPlugins(options: FrameworkOptions) { if (!options.context) { console.warn("The context is undefined can't load BUIDIN type plugins"); return; } const store = PluginStore.Instance(PluginStore.Type.BUILTIN); //Provide system info for BUILDIN type plugins - systemInfoStore[SystemInfoItem.FunctionName] = options.target; - systemInfoStore[SystemInfoItem.RuntimeType] = - options.context.runtime || 'knative'; if (checkTraceConfig(options.context)) { - const skywalking = new SkyWalkingPlugin(options.context.tracing!); + const skywalking = new SkyWalkingPlugin(options); store.register(skywalking); } } @@ -317,7 +309,9 @@ function checkTraceConfig(context: OpenFunctionContext): boolean { if (!context.tracing.enabled) { return false; } - + if (!context.tracing.tags) { + context.tracing.tags = {}; + } //Set default trace provider config context.tracing.provider = { name: context.tracing.provider?.name || SKYWALKINGNAME, diff --git a/src/main.ts b/src/main.ts index 4589ba8f..391848da 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,7 +23,7 @@ import {createHttpTerminator} from 'http-terminator'; import getAysncServer from './openfunction/async_server'; import {OpenFunctionContext, ContextUtils} from './openfunction/context'; -import {getUserFunction, getFunctionPlugins} from './loader'; +import {getUserFunction, getFunctionPlugins, loadBuidInPlugins} from './loader'; import {ErrorHandler} from './invoker'; import {getServer} from './server'; import {parseOptions, helpText, OptionsError} from './options'; @@ -54,8 +54,10 @@ export const main = async () => { } const {userFunction, signatureType} = loadedFunction; + // First load BUIDIN type plugin + await loadBuidInPlugins(options); // Load function plugins before starting server - await getFunctionPlugins(options); + await getFunctionPlugins(options.sourceLocation); // Try to determine the server runtime // Considering the async runtime in the first place diff --git a/src/openfunction/context.ts b/src/openfunction/context.ts index aec0290d..a0689c40 100644 --- a/src/openfunction/context.ts +++ b/src/openfunction/context.ts @@ -168,11 +168,11 @@ export interface TraceConfig { /** * Trace tags */ - tags: Record; + tags?: Record; /** * Trace baggage */ - baggage: Record; + baggage?: Record; } /** diff --git a/src/openfunction/plugin/skywalking/skywalking.ts b/src/openfunction/plugin/skywalking/skywalking.ts index 2eb81e5d..33bed7ce 100644 --- a/src/openfunction/plugin/skywalking/skywalking.ts +++ b/src/openfunction/plugin/skywalking/skywalking.ts @@ -10,7 +10,7 @@ import Context from 'skywalking-backend-js/lib/trace/context/Context'; import {Plugin} from '../../plugin'; import {OpenFunctionRuntime} from '../../runtime'; import {TraceConfig} from '../../context'; -import {SystemInfoItem, systemInfoStore} from '../../system_info'; +import {FrameworkOptions} from '../../../options'; // https://github.com/apache/skywalking/blob/master/oap-server/server-starter/src/main/resources/component-libraries.yml#L515 const componentIDOpenFunction = new Component(5013); @@ -21,18 +21,15 @@ class Trace { private span: Span; private spanContext: Context; - constructor() { + constructor(functionName: string) { this.spanContext = ContextManager.hasContext ? ContextManager.current : new SpanContext(); - this.span = this.spanContext.newEntrySpan( - `/${systemInfoStore[SystemInfoItem.FunctionName]}`, - undefined - ); + this.span = this.spanContext.newEntrySpan(`/${functionName}`, undefined); } - async start(tags: Array) { + async start(tags: Array): Promise { forEach(tags, tag => { this.span.tag(tag); }); @@ -40,6 +37,7 @@ class Trace { this.span.component = componentIDOpenFunction; this.span.start(); this.span.async(); + return this.spanContext.traceId(); } async stop() { @@ -56,23 +54,29 @@ class Trace { export class SkyWalkingPlugin extends Plugin { private trace: Trace | undefined; private tags: Array = []; + private functionName = 'function'; - constructor(traceConfig: TraceConfig) { + constructor(options: FrameworkOptions) { super(SKYWALKINGNAME, 'v1'); + this.functionName = options.target; + // Start skywalking agent agent.start({ - serviceName: systemInfoStore[SystemInfoItem.FunctionName], - serviceInstance: systemInfoStore[SystemInfoItem.Instance], - collectorAddress: traceConfig.provider?.oapServer, + serviceName: this.functionName, + serviceInstance: 'openfunctionInstance', + collectorAddress: options.context!.tracing!.provider!.oapServer, }); - this.iniAttribute(traceConfig); + if (!options.context!.tracing!.tags) { + options.context!.tracing!.tags = {}; + } + options.context!.tracing!.tags!['RuntimeType'] = + options.context?.runtime || 'Knative'; + this.iniAttribute(options.context!.tracing!); } iniAttribute(traceConfig: TraceConfig) { - traceConfig.tags[SystemInfoItem.RuntimeType] = - systemInfoStore[SystemInfoItem.RuntimeType]; for (const key in traceConfig.tags) { this.tags.push({ key, @@ -89,9 +93,11 @@ export class SkyWalkingPlugin extends Plugin { ) { if (ctx === null) { console.warn('OpenFunctionRuntime [ctx] is null'); + return; } - this.trace = new Trace(); - await this.trace.start(this.tags); + this.trace = new Trace(this.functionName); + const traceId = await this.trace.start(this.tags); + ctx.locals.traceId = traceId; } async execPostHook( @@ -101,6 +107,7 @@ export class SkyWalkingPlugin extends Plugin { ) { if (ctx === null) { console.warn('OpenFunctionRuntime [ctx] is null'); + return; } await this.trace?.stop(); } diff --git a/src/openfunction/system_info.ts b/src/openfunction/system_info.ts deleted file mode 100644 index 98a922d6..00000000 --- a/src/openfunction/system_info.ts +++ /dev/null @@ -1,13 +0,0 @@ -export enum SystemInfoItem { - RuntimeType = 'RuntimeType', - FunctionName = 'FunctionName', - Instance = 'OpenfunctionInstance', -} - -const systemInfoStore: Record = { - [SystemInfoItem.RuntimeType]: 'knative', - [SystemInfoItem.FunctionName]: 'function', - [SystemInfoItem.Instance]: 'OpenfunctionInstance', -}; - -export {systemInfoStore}; diff --git a/test/build_in_plugin.ts b/test/build_in_plugin.ts new file mode 100644 index 00000000..36c2f9d6 --- /dev/null +++ b/test/build_in_plugin.ts @@ -0,0 +1,111 @@ +import * as assert from 'assert'; +import {createConnection} from 'net'; +import axios from 'axios'; + +import {loadBuidInPlugins} from '../src/loader'; +import {OpenFunctionContext} from '../src/openfunction/context'; +import {PluginStore} from '../src/openfunction/plugin'; +import {SKYWALKINGNAME} from '../src/openfunction/plugin/skywalking/skywalking'; +import {OpenFunctionRuntime} from '../src/openfunction/runtime'; +import {FrameworkOptions} from '../src/options'; + +import {Context} from './data/mock'; + +const TEST_CONTEXT = Context.AsyncBase; + +const sleep = (val: number) => { + return new Promise(resolve => setTimeout(resolve, val)); +}; + +const query = async (traceId: string, url: string) => { + return await axios.post(`http://${url}/graphql`, { + query: + 'query queryTrace($traceId: ID!) {\n trace: queryTrace(traceId: $traceId) {\n spans {\n traceId\n segmentId\n spanId\n parentSpanId\n refs {\n traceId\n parentSegmentId\n parentSpanId\n type\n }\n serviceCode\n startTime\n endTime\n endpointName\n type\n peer\n component\n isError\n layer\n tags {\n key\n value\n }\n logs {\n time\n data {\n key\n value\n }\n }\n }\n }\n }', + variables: { + traceId, + }, + }); +}; + +const checkConnection = (host: string, port: number, timeout: number) => { + return new Promise((resolve, reject) => { + timeout = timeout || 10000; // default of 10 seconds + const timer = setTimeout(() => { + reject('timeout'); + socket.end(); + }, timeout); + // eslint-disable-next-line no-var + var socket = createConnection(port, host, () => { + clearTimeout(timer); + resolve(); + socket.end(); + }); + socket.on('error', (err: any) => { + clearTimeout(timer); + reject(err); + }); + }); +}; +export const check = async () => { + try { + await checkConnection('127.0.0.1', 8081, 3000); + } catch (error) { + console.warn('127.0.0.1:8088 has no server'); + return false; + } + return true; +}; + +const UIServer = '127.0.0.1:8088'; + +describe('BuildIn plugin', () => { + const options = { + target: 'test', + context: { + ...TEST_CONTEXT, + tracing: { + enabled: true, + }, + }, + }; + + it('skywalking plugin', async () => { + if (!check()) { + return; + } + await loadBuidInPlugins(options as FrameworkOptions); + const skywalking = PluginStore.Instance(1).get(SKYWALKINGNAME); + assert(skywalking.name === SKYWALKINGNAME); + + const runtime = OpenFunctionRuntime.ProxyContext( + options.context as OpenFunctionContext + ); + await skywalking.execPreHook(runtime, {}); + const traceId = runtime.locals.traceId; + await sleep(2000); + await skywalking.execPostHook(runtime, {}); + console.log(traceId); + const response = query(traceId, UIServer); + const data = (await response).data; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let target: unknown | any = null; + for (const item of data.data.trace.spans) { + console.log(item.serviceCode); + if (item.endpointName === `/${options.target}`) { + target = item; + } + } + assert(target !== null); + assert(target.endpointName === `/${options.target}`); + + const ms = target.endTime - target.startTime; + assert(ms >= 2000); + assert(ms <= 3000); + for (const tag in target.tags) { + if (tag === 'RuntimeType') { + assert(target.tags[tag] === options.context.runtime); + } + } + }); +}); diff --git a/test/integration/async_server.ts b/test/integration/async_server.ts index 6f9e4e27..8009a44e 100644 --- a/test/integration/async_server.ts +++ b/test/integration/async_server.ts @@ -7,7 +7,6 @@ import * as MQTT from 'aedes'; import getAysncServer from '../../src/openfunction/async_server'; import {getFunctionPlugins} from '../../src/loader'; -import {FrameworkOptions} from '../../src/options'; import {Context, Payload} from '../data/mock'; @@ -144,9 +143,7 @@ describe('OpenFunction - Async', () => { }); it('mqtt binding w/ custom plugins', done => { - getFunctionPlugins({ - sourceLocation: process.cwd() + '/test/data', - } as FrameworkOptions).then(plugins => { + getFunctionPlugins(process.cwd() + '/test/data').then(plugins => { const start = get(plugins!.numbers, 'oct'); const app = getAysncServer( diff --git a/test/integration/http_binding.ts b/test/integration/http_binding.ts index b459dd07..9517cb88 100644 --- a/test/integration/http_binding.ts +++ b/test/integration/http_binding.ts @@ -10,7 +10,6 @@ import {OpenFunctionRuntime} from '../../src/functions'; import {getServer} from '../../src/server'; import {getFunctionPlugins} from '../../src/loader'; import {FUNCTION_STATUS_HEADER_FIELD} from '../../src/types'; -import {FrameworkOptions} from '../../src/options'; import {Context, Payload} from '../data/mock'; @@ -33,9 +32,7 @@ describe('OpenFunction - HTTP Binding', () => { } ); - getFunctionPlugins({ - sourceLocation: process.cwd() + '/test/data', - } as FrameworkOptions).then(() => { + getFunctionPlugins(process.cwd() + '/test/data').then(() => { // Wait 5 seconds for dapr sidecar to start setTimeout(done, 5000); }); diff --git a/test/loader.ts b/test/loader.ts index 0db3b1c0..52a7589c 100644 --- a/test/loader.ts +++ b/test/loader.ts @@ -19,7 +19,6 @@ import * as semver from 'semver'; import {http, cloudEvent, HttpFunction} from '../src'; import * as loader from '../src/loader'; -import {FrameworkOptions} from '../src/options'; describe('Load function and plugins', () => { interface TestData { @@ -133,9 +132,9 @@ describe('Load function and plugins', () => { }); it('should only load valid plugin class and ignore other', async () => { - const loadedPlugins = await loader.getFunctionPlugins({ - sourceLocation: process.cwd() + '/test/data', - } as FrameworkOptions); + const loadedPlugins = await loader.getFunctionPlugins( + process.cwd() + '/test/data' + ); assert.ok(loadedPlugins); ['noname'].forEach(v => assert.ok(!loadedPlugins[v])); diff --git a/test/plugin.ts b/test/plugin.ts index 1566a1b3..000bd46c 100644 --- a/test/plugin.ts +++ b/test/plugin.ts @@ -5,7 +5,6 @@ import {fill, get, random, range} from 'lodash'; import {PluginStore, Plugin} from '../src/openfunction/plugin'; import {getFunctionPlugins} from '../src/loader'; -import {FrameworkOptions} from '../src/options'; class Concater extends Plugin { index = 0; @@ -22,12 +21,7 @@ class Concater extends Plugin { } describe('Store for custom and builtin plugins', () => { - before( - async () => - await getFunctionPlugins({ - sourceLocation: process.cwd() + '/test/data', - } as FrameworkOptions) - ); + before(async () => await getFunctionPlugins(process.cwd() + '/test/data')); const customs = PluginStore.Instance(); From ccf28115dac3cf6eccc3ea2e9b73c1fe4619570f Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Wed, 31 Aug 2022 08:33:46 +0800 Subject: [PATCH 06/11] run docs Signed-off-by: yad <459647480@qq.com> --- docs/generated/api.json | 8 ++++---- docs/generated/api.md | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/generated/api.json b/docs/generated/api.json index 4243d931..b83f66fd 100644 --- a/docs/generated/api.json +++ b/docs/generated/api.json @@ -3218,7 +3218,7 @@ "excerptTokens": [ { "kind": "Content", - "text": "baggage: " + "text": "baggage?: " }, { "kind": "Reference", @@ -3235,7 +3235,7 @@ } ], "isReadonly": false, - "isOptional": false, + "isOptional": true, "releaseTag": "Public", "name": "baggage", "propertyTypeTokenRange": { @@ -3305,7 +3305,7 @@ "excerptTokens": [ { "kind": "Content", - "text": "tags: " + "text": "tags?: " }, { "kind": "Reference", @@ -3322,7 +3322,7 @@ } ], "isReadonly": false, - "isOptional": false, + "isOptional": true, "releaseTag": "Public", "name": "tags", "propertyTypeTokenRange": { diff --git a/docs/generated/api.md b/docs/generated/api.md index ea156c68..388c83ef 100644 --- a/docs/generated/api.md +++ b/docs/generated/api.md @@ -191,10 +191,10 @@ export enum RuntimeType { // @public export interface TraceConfig { - baggage: Record; + baggage?: Record; enabled: boolean; provider?: TraceProvider; - tags: Record; + tags?: Record; } // @public From 56883af0bc9386ba63899c03edd3dad1cb198c81 Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Wed, 31 Aug 2022 14:31:42 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=F0=9F=90=9B=20fix=20skywalking=20workflo?= =?UTF-8?q?w=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yad <459647480@qq.com> --- .github/workflows/trace.yaml | 12 ++++++++---- test/build_in_plugin.ts | 9 +++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/trace.yaml b/.github/workflows/trace.yaml index 20db578f..107f06c1 100644 --- a/.github/workflows/trace.yaml +++ b/.github/workflows/trace.yaml @@ -1,8 +1,8 @@ -name: Node.js Unit CI +name: Node.js Trace CI on: push: branches: - - master + - main pull_request: jobs: test: @@ -29,13 +29,17 @@ jobs: docker version docker pull apache/skywalking-oap-server:8.4.0-es6 docker run -d --name oap -p 12800:12800 -p 11800:11800 apache/skywalking-oap-server:8.4.0-es6 - docker run -d --name ui -p 8088:8080 -e SW_OAP_ADDRESS=127.0.0.1:12800 apache/skywalking-ui:8.4.0 docker ps - name: Initialize Dapr run: dapr init -s --runtime-version ${{ matrix.dapr-version }} - name: Install dependencies run: npm install + - name: Sleep for 30 seconds + run: | + sleep 30s + docker ps + shell: bash - name: Build TypeScript project run: npm run build --if-present - name: Test - run: npm test + run: npm test \ No newline at end of file diff --git a/test/build_in_plugin.ts b/test/build_in_plugin.ts index 36c2f9d6..95486b58 100644 --- a/test/build_in_plugin.ts +++ b/test/build_in_plugin.ts @@ -1,5 +1,6 @@ import * as assert from 'assert'; import {createConnection} from 'net'; + import axios from 'axios'; import {loadBuidInPlugins} from '../src/loader'; @@ -48,15 +49,15 @@ const checkConnection = (host: string, port: number, timeout: number) => { }; export const check = async () => { try { - await checkConnection('127.0.0.1', 8081, 3000); + await checkConnection('127.0.0.1', 12800, 3000); } catch (error) { - console.warn('127.0.0.1:8088 has no server'); + console.warn('127.0.0.1:12800 has no server'); return false; } return true; }; -const UIServer = '127.0.0.1:8088'; +const UIServer = '127.0.0.1:12800'; describe('BuildIn plugin', () => { const options = { @@ -70,7 +71,7 @@ describe('BuildIn plugin', () => { }; it('skywalking plugin', async () => { - if (!check()) { + if (!(await check())) { return; } await loadBuidInPlugins(options as FrameworkOptions); From 80a20cabf877dfe4c2cae6e74620b672da44d87a Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Thu, 1 Sep 2022 19:30:26 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=F0=9F=8E=A8=20improve=20buildIn=20test?= =?UTF-8?q?=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yad <459647480@qq.com> --- .github/workflows/trace.yaml | 45 ----- .github/workflows/unit.yml | 10 + output-file.txt | 1 + package-lock.json | 87 +++++---- package.json | 2 +- src/loader.ts | 2 + src/openfunction/runtime.ts | 2 +- test/build_in_plugin.ts | 112 ----------- test/data/plugins/counters.mjs | 5 +- test/data/plugins/skywalking_assist.mjs | 35 ++++ test/integration/async_server.ts | 1 + test/integration/build_in_plugin.ts | 235 ++++++++++++++++++++++++ 12 files changed, 340 insertions(+), 197 deletions(-) delete mode 100644 .github/workflows/trace.yaml create mode 100644 output-file.txt delete mode 100644 test/build_in_plugin.ts create mode 100644 test/data/plugins/skywalking_assist.mjs create mode 100644 test/integration/build_in_plugin.ts diff --git a/.github/workflows/trace.yaml b/.github/workflows/trace.yaml deleted file mode 100644 index 107f06c1..00000000 --- a/.github/workflows/trace.yaml +++ /dev/null @@ -1,45 +0,0 @@ -name: Node.js Trace CI -on: - push: - branches: - - main - pull_request: -jobs: - test: - strategy: - matrix: - node-version: [16] - dapr-version: [1.6.3, 1.7.4, 1.8.3] - platform: [ubuntu-latest] - runs-on: ${{ matrix.platform }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - name: Install Dapr - uses: dapr/setup-dapr@v1 - with: - version: '1.8.0' - - name: Install Docker & start skywalking oap ui - uses: docker-practice/actions-setup-docker@master - - run: | - docker version - docker pull apache/skywalking-oap-server:8.4.0-es6 - docker run -d --name oap -p 12800:12800 -p 11800:11800 apache/skywalking-oap-server:8.4.0-es6 - docker ps - - name: Initialize Dapr - run: dapr init -s --runtime-version ${{ matrix.dapr-version }} - - name: Install dependencies - run: npm install - - name: Sleep for 30 seconds - run: | - sleep 30s - docker ps - shell: bash - - name: Build TypeScript project - run: npm run build --if-present - - name: Test - run: npm test \ No newline at end of file diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index c5cfe874..732bdbcc 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -26,6 +26,16 @@ jobs: - name: Install Docker for macOS uses: docker-practice/actions-setup-docker@master if: ${{ matrix.platform == 'macos-latest' }} + - name: Install Docker for ubuntu + uses: docker-practice/actions-setup-docker@master + if: ${{ matrix.platform == 'ubuntu-latest' }} + - name: Install SkyWalking + - run: | + docker version + docker pull apache/skywalking-oap-server:8.4.0-es6 + docker run -d --name oap -p 12800:12800 -p 11800:11800 apache/skywalking-oap-server:8.4.0-es6 + docker ps + sleep 20s - name: Initialize Dapr run: dapr init -s --runtime-version ${{ matrix.dapr-version }} - name: Install dependencies diff --git a/output-file.txt b/output-file.txt new file mode 100644 index 00000000..cda8cde4 --- /dev/null +++ b/output-file.txt @@ -0,0 +1 @@ +{"some":"payload"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 7c179a13..e946c70f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "license": "Apache-2.0", "dependencies": { "@dapr/dapr": "2.3.1", - "axios": "^0.27.2", "body-parser": "^1.20.0", "cloudevents": "^6.0.2", "debug": "^4.3.4", @@ -19,6 +18,7 @@ "http-terminator": "^3.2.0", "lodash": "^4.17.21", "minimist": "^1.2.6", + "node-fetch": "2.6.5", "on-finished": "^2.4.1", "read-pkg-up": "^7.0.1", "semver": "^7.3.7", @@ -127,6 +127,25 @@ "uuid": "^8.3.2" } }, + "node_modules/@dapr/dapr/node_modules/node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/@eslint/eslintrc": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.3.tgz", @@ -1241,7 +1260,8 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true }, "node_modules/available-typed-arrays": { "version": "1.0.5", @@ -1254,15 +1274,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmmirror.com/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", - "dependencies": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" - } - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1795,6 +1806,7 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -2248,6 +2260,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true, "engines": { "node": ">=0.4.0" } @@ -3299,6 +3312,7 @@ "version": "1.14.9", "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.14.9.tgz", "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", + "dev": true, "engines": { "node": ">=4.0" }, @@ -3317,6 +3331,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -5354,22 +5369,14 @@ } }, "node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "version": "2.6.5", + "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.6.5.tgz", + "integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==", "dependencies": { "whatwg-url": "^5.0.0" }, "engines": { "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } } }, "node_modules/normalize-package-data": { @@ -7912,6 +7919,16 @@ "node-fetch": "^2.6.1", "restana": "^4.9.1", "uuid": "^8.3.2" + }, + "dependencies": { + "node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "requires": { + "whatwg-url": "^5.0.0" + } + } } }, "@eslint/eslintrc": { @@ -8850,22 +8867,14 @@ "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true }, "available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==" }, - "axios": { - "version": "0.27.2", - "resolved": "https://registry.npmmirror.com/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", - "requires": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" - } - }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -9291,6 +9300,7 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, "requires": { "delayed-stream": "~1.0.0" } @@ -9641,7 +9651,8 @@ "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true }, "depd": { "version": "2.0.0", @@ -10444,7 +10455,8 @@ "follow-redirects": { "version": "1.14.9", "resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.14.9.tgz", - "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==" + "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", + "dev": true }, "foreach": { "version": "2.0.5", @@ -10455,6 +10467,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, "requires": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -11947,9 +11960,9 @@ } }, "node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "version": "2.6.5", + "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.6.5.tgz", + "integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==", "requires": { "whatwg-url": "^5.0.0" } diff --git a/package.json b/package.json index 465beb7f..2eb01149 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ }, "dependencies": { "@dapr/dapr": "2.3.1", - "axios": "^0.27.2", "body-parser": "^1.20.0", "cloudevents": "^6.0.2", "debug": "^4.3.4", @@ -23,6 +22,7 @@ "http-terminator": "^3.2.0", "lodash": "^4.17.21", "minimist": "^1.2.6", + "node-fetch": "2.6.5np", "on-finished": "^2.4.1", "read-pkg-up": "^7.0.1", "semver": "^7.3.7", diff --git a/src/loader.ts b/src/loader.ts index 7d42f10f..56a74766 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -294,6 +294,8 @@ export async function loadBuidInPlugins(options: FrameworkOptions) { if (checkTraceConfig(options.context)) { const skywalking = new SkyWalkingPlugin(options); store.register(skywalking); + options.context.prePlugins?.push(SKYWALKINGNAME); + options.context.postPlugins?.push(SKYWALKINGNAME); } } diff --git a/src/openfunction/runtime.ts b/src/openfunction/runtime.ts index ab758e4d..85b3f887 100644 --- a/src/openfunction/runtime.ts +++ b/src/openfunction/runtime.ts @@ -115,8 +115,8 @@ export abstract class OpenFunctionRuntime { await userFunction(ctx, data); // Execute pre hooks, system plugins go last - await userPlugins.execPostHooks(ctx); await sysPlugins.execPostHooks(ctx); + await userPlugins.execPostHooks(ctx); }; } diff --git a/test/build_in_plugin.ts b/test/build_in_plugin.ts deleted file mode 100644 index 95486b58..00000000 --- a/test/build_in_plugin.ts +++ /dev/null @@ -1,112 +0,0 @@ -import * as assert from 'assert'; -import {createConnection} from 'net'; - -import axios from 'axios'; - -import {loadBuidInPlugins} from '../src/loader'; -import {OpenFunctionContext} from '../src/openfunction/context'; -import {PluginStore} from '../src/openfunction/plugin'; -import {SKYWALKINGNAME} from '../src/openfunction/plugin/skywalking/skywalking'; -import {OpenFunctionRuntime} from '../src/openfunction/runtime'; -import {FrameworkOptions} from '../src/options'; - -import {Context} from './data/mock'; - -const TEST_CONTEXT = Context.AsyncBase; - -const sleep = (val: number) => { - return new Promise(resolve => setTimeout(resolve, val)); -}; - -const query = async (traceId: string, url: string) => { - return await axios.post(`http://${url}/graphql`, { - query: - 'query queryTrace($traceId: ID!) {\n trace: queryTrace(traceId: $traceId) {\n spans {\n traceId\n segmentId\n spanId\n parentSpanId\n refs {\n traceId\n parentSegmentId\n parentSpanId\n type\n }\n serviceCode\n startTime\n endTime\n endpointName\n type\n peer\n component\n isError\n layer\n tags {\n key\n value\n }\n logs {\n time\n data {\n key\n value\n }\n }\n }\n }\n }', - variables: { - traceId, - }, - }); -}; - -const checkConnection = (host: string, port: number, timeout: number) => { - return new Promise((resolve, reject) => { - timeout = timeout || 10000; // default of 10 seconds - const timer = setTimeout(() => { - reject('timeout'); - socket.end(); - }, timeout); - // eslint-disable-next-line no-var - var socket = createConnection(port, host, () => { - clearTimeout(timer); - resolve(); - socket.end(); - }); - socket.on('error', (err: any) => { - clearTimeout(timer); - reject(err); - }); - }); -}; -export const check = async () => { - try { - await checkConnection('127.0.0.1', 12800, 3000); - } catch (error) { - console.warn('127.0.0.1:12800 has no server'); - return false; - } - return true; -}; - -const UIServer = '127.0.0.1:12800'; - -describe('BuildIn plugin', () => { - const options = { - target: 'test', - context: { - ...TEST_CONTEXT, - tracing: { - enabled: true, - }, - }, - }; - - it('skywalking plugin', async () => { - if (!(await check())) { - return; - } - await loadBuidInPlugins(options as FrameworkOptions); - const skywalking = PluginStore.Instance(1).get(SKYWALKINGNAME); - assert(skywalking.name === SKYWALKINGNAME); - - const runtime = OpenFunctionRuntime.ProxyContext( - options.context as OpenFunctionContext - ); - await skywalking.execPreHook(runtime, {}); - const traceId = runtime.locals.traceId; - await sleep(2000); - await skywalking.execPostHook(runtime, {}); - console.log(traceId); - const response = query(traceId, UIServer); - const data = (await response).data; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - let target: unknown | any = null; - for (const item of data.data.trace.spans) { - console.log(item.serviceCode); - if (item.endpointName === `/${options.target}`) { - target = item; - } - } - assert(target !== null); - assert(target.endpointName === `/${options.target}`); - - const ms = target.endTime - target.startTime; - assert(ms >= 2000); - assert(ms <= 3000); - for (const tag in target.tags) { - if (tag === 'RuntimeType') { - assert(target.tags[tag] === options.context.runtime); - } - } - }); -}); diff --git a/test/data/plugins/counters.mjs b/test/data/plugins/counters.mjs index 5ba83214..1bb8b445 100644 --- a/test/data/plugins/counters.mjs +++ b/test/data/plugins/counters.mjs @@ -49,7 +49,10 @@ export class Countdown extends Plugin { this.countdown(ctx, plugins); // Try to end the test if necessary - if (this.current === this.end) ctx.locals.done?.(); + if (this.current === this.end) { + ctx.locals.app.stop(); + ctx.locals.done?.(); + } } countdown(ctx, plugins) { diff --git a/test/data/plugins/skywalking_assist.mjs b/test/data/plugins/skywalking_assist.mjs new file mode 100644 index 00000000..15924f9e --- /dev/null +++ b/test/data/plugins/skywalking_assist.mjs @@ -0,0 +1,35 @@ +import assert from 'assert'; +import {Plugin} from '../../../build/src/index.js'; +import {query,OapServer,sleep} from '../../../build/test/integration/build_in_plugin.js' +//Help to verify skywalking plugin +export class Assist extends Plugin { + constructor() { + super('assist', 'v1'); + } + + async execPreHook(ctx, plugins) { + } + + async execPostHook(ctx, plugins) { + const traceId = ctx.locals.traceId; + const options = ctx.locals.options; + sleep(3000).then(()=>{ + query(traceId,OapServer).then(res=>{ + res.json().then(res=>{ + if(res.data.trace.spans.length >=0){ + let target = null; + for (const item of res.data.trace.spans) { + if (item.endpointName === `/${options.target}`) { + target = item; + } + } + assert(target !== null); + assert(target.endpointName === `/${options.target}`); + + ctx.locals.done?.(); + } + }) + }) + }) + } + } \ No newline at end of file diff --git a/test/integration/async_server.ts b/test/integration/async_server.ts index 8009a44e..c70491d7 100644 --- a/test/integration/async_server.ts +++ b/test/integration/async_server.ts @@ -157,6 +157,7 @@ describe('OpenFunction - Async', () => { // Passthrough test done handler ctx.locals.done = done; + ctx.locals.app = app; }, { ...TEST_CONTEXT, diff --git a/test/integration/build_in_plugin.ts b/test/integration/build_in_plugin.ts new file mode 100644 index 00000000..10a0acc7 --- /dev/null +++ b/test/integration/build_in_plugin.ts @@ -0,0 +1,235 @@ +import {ifError, notStrictEqual, deepStrictEqual, ok} from 'assert'; +import {createServer} from 'net'; +import {execSync} from 'child_process'; + +import {get} from 'lodash'; +import * as shell from 'shelljs'; +import * as MQTT from 'aedes'; +import fetch from 'node-fetch'; + +import {FrameworkOptions} from '../../src/options'; +import {SKYWALKINGNAME} from '../../src/openfunction/plugin/skywalking/skywalking'; +import {PluginStore} from '../../src/openfunction/plugin'; +import {OpenFunctionRuntime} from '../../src/openfunction/runtime'; +import {OpenFunctionContext} from '../../src/openfunction/context'; +import getAysncServer from '../../src/openfunction/async_server'; +import {getFunctionPlugins, loadBuidInPlugins} from '../../src/loader'; + +import {Context} from '../data/mock'; + +const TEST_CONTEXT = Context.AsyncBase; + +export const OapServer = '127.0.0.1:12800'; + +export const sleep = (val: number) => { + return new Promise(resolve => setTimeout(resolve, val)); +}; + +export const query = async (traceId: string, url: string) => { + const body = { + query: `query queryTrace($traceId: ID!) { + trace: queryTrace(traceId: $traceId) { + spans { + traceId + segmentId + spanId + parentSpanId + refs { + traceId + parentSegmentId + parentSpanId + type + } + serviceCode + startTime + endTime + endpointName + type + peer + component + isError + layer + tags { + key + value + } + logs { + time + data { + key + value + } + } + } + } + }`, + variables: { + traceId, + }, + }; + return await fetch(`http://${url}/graphql`, { + method: 'POST', + body: JSON.stringify(body), + }); +}; + +//Verify skywalking proccess , start it if not exist +export const checkSkyWalkingProcess = async ( + reCheck: boolean +): Promise => { + try { + const buffer = execSync('docker ps -a').toString(); + + let flag = false; + for (const line of buffer.split('\n')) { + if (line.indexOf('apache/skywalking-oap-server:8.4.0-es6') !== -1) { + if (line.indexOf('Up') !== -1) { + console.log('skywalking oap server is start'); + flag = true; + } else if (line.indexOf('Exited') !== -1) { + console.log('skywalking oap server is stop , now start it '); + console.log( + execSync('docker start ' + line.substring(0, 13)).toString() + ); + flag = true; + } + break; + } + } + if (!flag) { + const startCmd = + 'docker run -d --name oap -p 12800:12800 -p 11800:11800 apache/skywalking-oap-server:8.4.0-es6'; + execSync(startCmd); + console.log(startCmd); + return reCheck ? false : checkSkyWalkingProcess(true); + } + } catch (error) { + console.log('start fail'); + return false; + } + return true; +}; +describe('Build in plugin', () => { + const APPID = 'async.dapr'; + const broker = MQTT.Server(); + const server = createServer(broker.handle); + before(done => { + // Start simple plain MQTT server via aedes + server.listen(1883, () => { + // Try to run Dapr sidecar and listen for the async server + shell.exec( + `dapr run -H 3500 -G 50001 -p ${TEST_CONTEXT.port} -d ./test/data/components/async -a ${APPID} --log-level debug`, + { + silent: true, + async: true, + } + ); + done(); + }); + }); + + after(done => { + // Stop dapr sidecar process + shell.exec(`dapr stop ${APPID}`, { + silent: true, + }); + server.close(); + broker.close(done); + }); + + it('mqtt binding w/ skywalking plugin', done => { + const options: FrameworkOptions = { + target: 'test', + port: '', + sourceLocation: '', + signatureType: 'http', + printHelp: false, + context: { + ...TEST_CONTEXT, + tracing: { + enabled: true, + }, + prePlugins: ['assist'], + postPlugins: ['assist'], + }, + }; + getFunctionPlugins(process.cwd() + '/test/data').then(plugins => { + loadBuidInPlugins(options).then(() => { + const start = get(plugins!.numbers, 'oct'); + + const app = getAysncServer((ctx, data) => { + notStrictEqual(ctx.locals.traceId, null || undefined); + // Passthrough test done handler + ctx.locals.done = done; + ctx.locals.app = app; + ctx.locals.options = options; + ctx.send({some: 'payload'}); + }, options.context!); + + // First, we start the async server + app.start().then(() => { + // Then, we send a number as start value to user function + broker.publish( + { + cmd: 'publish', + topic: 'default', + payload: JSON.stringify({start}), + qos: 0, + retain: false, + dup: false, + }, + err => ifError(err) + ); + }); + }); + }); + }); + + it('skywalking plugin', async () => { + const options = { + target: 'test', + context: { + ...TEST_CONTEXT, + tracing: { + enabled: true, + }, + }, + }; + ok((await checkSkyWalkingProcess(false)) === true); + await loadBuidInPlugins(options as FrameworkOptions); + const skywalking = PluginStore.Instance(1).get(SKYWALKINGNAME); + ok(skywalking.name === SKYWALKINGNAME); + + const runtime = OpenFunctionRuntime.ProxyContext( + options.context as OpenFunctionContext + ); + await skywalking.execPreHook(runtime, {}); + const traceId = runtime.locals.traceId; + await sleep(2000); + await skywalking.execPostHook(runtime, {}); + console.log(traceId); + const response = query(traceId, OapServer); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const data = (await (await response).json()) as any; + console.log(data); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let target: unknown | any = null; + for (const item of data.data.trace.spans) { + console.log(item.serviceCode); + if (item.endpointName === `/${options.target}`) { + target = item; + } + } + notStrictEqual(target, null); + deepStrictEqual(target.endpointName, `/${options.target}`); + + const ms = target.endTime - target.startTime; + ok(ms >= 2000); + ok(ms <= 3000); + for (const tag in target.tags) { + if (tag === 'RuntimeType') { + ok(target.tags[tag] === options.context.runtime); + } + } + }); +}); From feca9842ccbf5e3e633c2b46a5bf1b670ceea0e8 Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Thu, 1 Sep 2022 19:48:40 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=F0=9F=90=9B=20fix=20node=20fetch=20versi?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yad <459647480@qq.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2eb01149..1988723a 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "http-terminator": "^3.2.0", "lodash": "^4.17.21", "minimist": "^1.2.6", - "node-fetch": "2.6.5np", + "node-fetch": "2.6.5", "on-finished": "^2.4.1", "read-pkg-up": "^7.0.1", "semver": "^7.3.7", From 7fc8d8f01e39ba1e836a2d12e35253959697261a Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Thu, 1 Sep 2022 20:12:19 +0800 Subject: [PATCH 10/11] fix unit test workflow Signed-off-by: yad <459647480@qq.com> --- .github/workflows/unit.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 732bdbcc..8a9cf0f0 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -29,13 +29,14 @@ jobs: - name: Install Docker for ubuntu uses: docker-practice/actions-setup-docker@master if: ${{ matrix.platform == 'ubuntu-latest' }} - - name: Install SkyWalking + - name: Install SkyWalking And Wait for it start - run: | docker version docker pull apache/skywalking-oap-server:8.4.0-es6 docker run -d --name oap -p 12800:12800 -p 11800:11800 apache/skywalking-oap-server:8.4.0-es6 docker ps sleep 20s + shell: bash - name: Initialize Dapr run: dapr init -s --runtime-version ${{ matrix.dapr-version }} - name: Install dependencies From 02d4791a9d0aea1fb28ae929697852233b555464 Mon Sep 17 00:00:00 2001 From: yad <459647480@qq.com> Date: Thu, 1 Sep 2022 20:40:48 +0800 Subject: [PATCH 11/11] fix unit test workflow Signed-off-by: yad <459647480@qq.com> --- .github/workflows/unit.yml | 5 ++--- test/integration/build_in_plugin.ts | 3 --- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 8a9cf0f0..e54221f2 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -29,14 +29,13 @@ jobs: - name: Install Docker for ubuntu uses: docker-practice/actions-setup-docker@master if: ${{ matrix.platform == 'ubuntu-latest' }} - - name: Install SkyWalking And Wait for it start - - run: | + - name: Install skywalking and wait for it start + run: | docker version docker pull apache/skywalking-oap-server:8.4.0-es6 docker run -d --name oap -p 12800:12800 -p 11800:11800 apache/skywalking-oap-server:8.4.0-es6 docker ps sleep 20s - shell: bash - name: Initialize Dapr run: dapr init -s --runtime-version ${{ matrix.dapr-version }} - name: Install dependencies diff --git a/test/integration/build_in_plugin.ts b/test/integration/build_in_plugin.ts index 10a0acc7..42a1dfb7 100644 --- a/test/integration/build_in_plugin.ts +++ b/test/integration/build_in_plugin.ts @@ -223,9 +223,6 @@ describe('Build in plugin', () => { notStrictEqual(target, null); deepStrictEqual(target.endpointName, `/${options.target}`); - const ms = target.endTime - target.startTime; - ok(ms >= 2000); - ok(ms <= 3000); for (const tag in target.tags) { if (tag === 'RuntimeType') { ok(target.tags[tag] === options.context.runtime);