From bd93e3c95d29efc1fd2ccb56538718fa114dddb1 Mon Sep 17 00:00:00 2001 From: Stephane Hervochon Date: Tue, 30 Apr 2024 13:14:32 +0200 Subject: [PATCH] Fix PR comments --- .github/scripts/redis_test/index.js | 64 ++++++----- .gitignore | 1 + docs/src/guide/customization/addons/redis.md | 3 +- package-lock.json | 113 ++++++++++++++++++- package.json | 1 + 5 files changed, 149 insertions(+), 33 deletions(-) diff --git a/.github/scripts/redis_test/index.js b/.github/scripts/redis_test/index.js index 6a84e35..21587a5 100644 --- a/.github/scripts/redis_test/index.js +++ b/.github/scripts/redis_test/index.js @@ -118,6 +118,7 @@ const testRateLimitModule = async () => { process.exit(1); } } + console.log('Testing Rate Limit Module - Result is OK'); } const testSlidingCountBreakerModule = async () => { @@ -147,6 +148,7 @@ const testSlidingCountBreakerModule = async () => { check(slidingCountBreaker.state === Mollitia.BreakerState.CLOSED, 'Ok, circuit is closed', 'Circuit is not closed as expected...'); await failure(circuit2, { data: 'Circuit2' }); check(slidingCountBreaker2.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...'); + console.log('Testing Sliding Count Breaker Module - Result is OK'); } const testSlidingTimeBreakerModule = async () => { console.log('Testing Sliding Time Breaker Module'); @@ -188,44 +190,48 @@ const testSlidingTimeBreakerModule = async () => { check(slidingTimeBreaker3.state === Mollitia.BreakerState.CLOSED, 'Ok, circuit is closed', 'Circuit is not closed as expected...'); await failure(circuit3, { data: 'Circuit3' }); check(slidingTimeBreaker3.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...'); + console.log('Testing Sliding Time Breaker Module - Result is OK'); } const testSlidingTimeBreakerModuleSlowRequest = async () => { + console.log('Testing Sliding Time Breaker Module With Slow Requests'); const breakerData = { - failureRateThreshold: 50, - openStateDelay: 10, - slidingWindowSize: 1000, - minimumNumberOfCalls: 2, - permittedNumberOfCallsInHalfOpenState: 1, - slowCallDurationThreshold: 100, - slowCallRateThreshold: 50, - redis: { - use: true - }, - name: 'mySlidingTimeBreakerSlow' - }; - const slidingTimeBreaker = new Mollitia.SlidingTimeBreaker(breakerData); - const slidingTimeBreaker2 = new Mollitia.SlidingTimeBreaker(breakerData); - const circuit1 = new Mollitia.Circuit({ options: { modules: [slidingTimeBreaker] } }); - const circuit2 = new Mollitia.Circuit({ options: { modules: [slidingTimeBreaker2] } }); - await success(circuit1, { data: 'Circuit1', delay: 150 }); - await success(circuit2, { data: 'Circuit2' }); - // Even if 50% of slow requests, circuit is kept closed as last request is success - check(slidingTimeBreaker2.state === Mollitia.BreakerState.CLOSED, 'Ok, circuit is closed', 'Circuit is not closed as expected...'); - await success(circuit1, { data: 'Circuit1', delay: 150 }); - check(slidingTimeBreaker.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...'); - await delay(150); - check(slidingTimeBreaker.state === Mollitia.BreakerState.HALF_OPENED, 'Ok, circuit is Half Opened', 'Circuit is not Half Opened as expected...'); - await success(circuit2, { data: 'Circuit2', delay: 150 }); - check(slidingTimeBreaker2.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...'); - await delay(10); - await expect(circuit.fn(successAsync).execute('dummy')).resolves.toEqual('dummy'); - expect(slidingTimeBreaker.state).toEqual(Mollitia.BreakerState.CLOSED); + failureRateThreshold: 50, + openStateDelay: 10, + slidingWindowSize: 1000, + minimumNumberOfCalls: 2, + permittedNumberOfCallsInHalfOpenState: 1, + slowCallDurationThreshold: 100, + slowCallRateThreshold: 50, + redis: { + use: true + }, + name: 'mySlidingTimeBreakerSlow' + }; + const slidingTimeBreaker = new Mollitia.SlidingTimeBreaker(breakerData); + const slidingTimeBreaker2 = new Mollitia.SlidingTimeBreaker(breakerData); + const circuit1 = new Mollitia.Circuit({ options: { modules: [slidingTimeBreaker] } }); + const circuit2 = new Mollitia.Circuit({ options: { modules: [slidingTimeBreaker2] } }); + await success(circuit1, { data: 'Circuit1', delay: 150 }); + await success(circuit2, { data: 'Circuit2' }); + // Even if 50% of slow requests, circuit is kept closed as last request is success + check(slidingTimeBreaker2.state === Mollitia.BreakerState.CLOSED, 'Ok, circuit is closed', 'Circuit is not closed as expected...'); + await success(circuit1, { data: 'Circuit1', delay: 150 }); + check(slidingTimeBreaker.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...'); + await delay(150); + check(slidingTimeBreaker.state === Mollitia.BreakerState.HALF_OPENED, 'Ok, circuit is Half Opened', 'Circuit is not Half Opened as expected...'); + await success(circuit2, { data: 'Circuit2', delay: 150 }); + check(slidingTimeBreaker2.state === Mollitia.BreakerState.OPENED, 'Ok, circuit is opened', 'Circuit is not opened as expected...'); + await delay(10); + await success(circuit1, { data: 'Circuit1' }); + check(slidingTimeBreaker.state === Mollitia.BreakerState.CLOSED, 'Ok, circuit is closed', 'Circuit is not closed as expected...'); + console.log('Testing Sliding Time Breaker Module With Slow Requests - Result is OK'); } const main = async () => { await testRateLimitModule(); await testSlidingCountBreakerModule(); await testSlidingTimeBreakerModule(); + await testSlidingTimeBreakerModuleSlowRequest(); process.exit(0); } diff --git a/.gitignore b/.gitignore index 97a483b..181e8ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /node_modules /.npmrc +**/node_modules diff --git a/docs/src/guide/customization/addons/redis.md b/docs/src/guide/customization/addons/redis.md index 9f3b4ed..4ecb2ba 100644 --- a/docs/src/guide/customization/addons/redis.md +++ b/docs/src/guide/customization/addons/redis.md @@ -8,8 +8,7 @@ The `Mollitia` [Redis](https://redis.io/) addon adds redis for some modules of e # Install mollitia npm install mollitia --save # Install Redis and the Redis addon -npm install redis --save -npm install @mollitia/redis --save +npm install @mollitia/redis redis --save ``` ``` typescript diff --git a/package-lock.json b/package-lock.json index 3c9246b..dd19a5f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1696,6 +1696,10 @@ "resolved": "packages/@mollitia/prometheus", "link": true }, + "node_modules/@mollitia/redis": { + "resolved": "packages/@mollitia/redis", + "link": true + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -3101,6 +3105,59 @@ "node": ">=14" } }, + "node_modules/@redis/bloom": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-1.2.0.tgz", + "integrity": "sha512-HG2DFjYKbpNmVXsa0keLHp/3leGJz1mjh09f2RLGGLQZzSHpkmZWuwJbAvo3QcRY8p80m5+ZdXZdYOSBLlp7Cg==", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/client": { + "version": "1.5.11", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.11.tgz", + "integrity": "sha512-cV7yHcOAtNQ5x/yQl7Yw1xf53kO0FNDTdDU6bFIMbW6ljB7U7ns0YRM+QIkpoqTAt6zK5k9Fq0QWlUbLcq9AvA==", + "dependencies": { + "cluster-key-slot": "1.1.2", + "generic-pool": "3.9.0", + "yallist": "4.0.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/@redis/graph": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.1.0.tgz", + "integrity": "sha512-16yZWngxyXPd+MJxeSr0dqh2AIOi8j9yXKcKCwVaKDbH3HTuETpDVPcLujhFYVPtYrngSco31BUcSa9TH31Gqg==", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/json": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.6.tgz", + "integrity": "sha512-rcZO3bfQbm2zPRpqo82XbW8zg4G/w4W3tI7X8Mqleq9goQjAGLL7q/1n1ZX4dXEAmORVZ4s1+uKLaUOg7LrUhw==", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/search": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/@redis/search/-/search-1.1.5.tgz", + "integrity": "sha512-hPP8w7GfGsbtYEJdn4n7nXa6xt6hVZnnDktKW4ArMaFQ/m/aR7eFvsLQmG/mn1Upq99btPJk+F27IQ2dYpCoUg==", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/time-series": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.0.5.tgz", + "integrity": "sha512-IFjIgTusQym2B5IZJG3XKr5llka7ey84fw/NOYqESP5WUfQs9zz1ww/9+qoz4ka/S6KcGBodzlCeZ5UImKbscg==", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, "node_modules/@rollup/pluginutils": { "version": "5.0.5", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.5.tgz", @@ -3501,6 +3558,16 @@ "integrity": "sha512-lqa4UEhhv/2sjjIQgjX8B+RBjj47eo0mzGasklVJ78UKGQY1r0VpB9XHDaZZO9qzEFDdy4MrXLuEaSmPrPSe/A==", "dev": true }, + "node_modules/@types/redis": { + "version": "4.0.11", + "resolved": "https://registry.npmjs.org/@types/redis/-/redis-4.0.11.tgz", + "integrity": "sha512-bI+gth8La8Wg/QCR1+V1fhrL9+LZUSWfcqpOj2Kc80ZQ4ffbdL173vQd5wovmoV9i071FU9oP2g6etLuEwb6Rg==", + "deprecated": "This is a stub types definition. redis provides its own type definitions, so you do not need this installed.", + "dev": true, + "dependencies": { + "redis": "*" + } + }, "node_modules/@types/semver": { "version": "7.5.3", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.3.tgz", @@ -5111,6 +5178,14 @@ "node": ">=0.10.0" } }, + "node_modules/cluster-key-slot": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.2.tgz", + "integrity": "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/cmd-shim": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-6.0.1.tgz", @@ -7241,6 +7316,14 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/generic-pool": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.9.0.tgz", + "integrity": "sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g==", + "engines": { + "node": ">= 4" + } + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -12739,6 +12822,19 @@ "node": ">=8" } }, + "node_modules/redis": { + "version": "4.6.10", + "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.10.tgz", + "integrity": "sha512-mmbyhuKgDiJ5TWUhiKhBssz+mjsuSI/lSZNPI9QvZOYzWvYGejtb+W3RlDDf8LD6Bdl5/mZeG8O1feUGhXTxEg==", + "dependencies": { + "@redis/bloom": "1.2.0", + "@redis/client": "1.5.11", + "@redis/graph": "1.1.0", + "@redis/json": "1.0.6", + "@redis/search": "1.1.5", + "@redis/time-series": "1.0.5" + } + }, "node_modules/regexp.prototype.flags": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.1.tgz", @@ -14950,8 +15046,7 @@ "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/yaml": { "version": "2.3.3", @@ -15051,6 +15146,20 @@ "mollitia": "*" } }, + "packages/@mollitia/redis": { + "version": "0.0.1", + "license": "MIT", + "devDependencies": { + "@shared/tsconfig": "*", + "@shared/vite": "*", + "@types/redis": "4.0.11", + "eslint-config-mollitia": "*" + }, + "peerDependencies": { + "mollitia": "*", + "redis": "4.6.10" + } + }, "packages/mollitia": { "version": "0.1.0", "license": "MIT", diff --git a/package.json b/package.json index d70870a..dd8f177 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "build": "nx run-many -t build --output-style=stream", "test": "nx run-many -t test:unit --output-style=stream", "lint": "nx run-many -t lint --output-style=stream", + "clean": "nx run-many -t clean --output-style=stream && rm -rf node_modules", "preview": "nx preview docs", "version": "lerna version", "changelog": "vertis generate",