@abyss-project/monitor 1.0.79 → 1.0.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +33 -33
- package/README.md +33 -33
- package/dist/middlewares/rate-limit/rate-limit.lua.js +72 -72
- package/jest.config.ts +14 -14
- package/package.json +1 -1
- package/tsconfig.json +35 -35
package/.eslintrc.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
parser: '@typescript-eslint/parser',
|
|
3
|
-
parserOptions: {
|
|
4
|
-
project: 'tsconfig.json',
|
|
5
|
-
tsconfigRootDir: __dirname,
|
|
6
|
-
sourceType: 'module',
|
|
7
|
-
},
|
|
8
|
-
plugins: ['@typescript-eslint/eslint-plugin', 'filenames-simple'],
|
|
9
|
-
extends: [
|
|
10
|
-
'plugin:@typescript-eslint/recommended',
|
|
11
|
-
'plugin:prettier/recommended',
|
|
12
|
-
],
|
|
13
|
-
root: true,
|
|
14
|
-
env: {
|
|
15
|
-
node: true,
|
|
16
|
-
jest: true,
|
|
17
|
-
},
|
|
18
|
-
ignorePatterns: ['.eslintrc.js'],
|
|
19
|
-
rules: {
|
|
20
|
-
'@typescript-eslint/interface-name-prefix': 'off',
|
|
21
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
22
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
23
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
24
|
-
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
|
|
25
|
-
'filenames-simple/naming-convention': [
|
|
26
|
-
'error',
|
|
27
|
-
{
|
|
28
|
-
// Use custom regexp to match migration file
|
|
29
|
-
rule: '^([a-z0-9]*)(-[a-z0-9]+)*$',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
overrides: [],
|
|
1
|
+
module.exports = {
|
|
2
|
+
parser: '@typescript-eslint/parser',
|
|
3
|
+
parserOptions: {
|
|
4
|
+
project: 'tsconfig.json',
|
|
5
|
+
tsconfigRootDir: __dirname,
|
|
6
|
+
sourceType: 'module',
|
|
7
|
+
},
|
|
8
|
+
plugins: ['@typescript-eslint/eslint-plugin', 'filenames-simple'],
|
|
9
|
+
extends: [
|
|
10
|
+
'plugin:@typescript-eslint/recommended',
|
|
11
|
+
'plugin:prettier/recommended',
|
|
12
|
+
],
|
|
13
|
+
root: true,
|
|
14
|
+
env: {
|
|
15
|
+
node: true,
|
|
16
|
+
jest: true,
|
|
17
|
+
},
|
|
18
|
+
ignorePatterns: ['.eslintrc.js'],
|
|
19
|
+
rules: {
|
|
20
|
+
'@typescript-eslint/interface-name-prefix': 'off',
|
|
21
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
22
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
23
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
24
|
+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
|
|
25
|
+
'filenames-simple/naming-convention': [
|
|
26
|
+
'error',
|
|
27
|
+
{
|
|
28
|
+
// Use custom regexp to match migration file
|
|
29
|
+
rule: '^([a-z0-9]*)(-[a-z0-9]+)*$',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
overrides: [],
|
|
34
34
|
};
|
package/README.md
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
<img src="https://docs.abyss-project.fr/img/services/AbyssMonitor.svg" align="right" width="96" alt="" />
|
|
2
|
-
|
|
3
|
-
# Abyss Monitor
|
|
4
|
-
|
|
5
|
-
`@abyss-project/monitor`
|
|
6
|
-
|
|
7
|
-
Supervision applicative : logs, événements, alertes, Sentinels et Cron Tasks.
|
|
8
|
-
|
|
9
|
-
_Application monitoring: logs, events, alerts, Sentinels and Cron Tasks._
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm install @abyss-project/monitor
|
|
15
|
-
# or
|
|
16
|
-
pnpm add @abyss-project/monitor
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Liens
|
|
20
|
-
|
|
21
|
-
- **Documentation** : [https://docs.abyss-project.fr/monitor](https://docs.abyss-project.fr/monitor)
|
|
22
|
-
- **NPM** : [@abyss-project/monitor](https://www.npmjs.com/package/@abyss-project/monitor)
|
|
23
|
-
- **Swagger** : [https://monitor-api.abyss-project.fr/swagger](https://monitor-api.abyss-project.fr/swagger)
|
|
24
|
-
- **Application Abyss** : [app.abyss-project.fr](https://app.abyss-project.fr)
|
|
25
|
-
- **Statut des services** : [status.abyss-project.fr](https://status.abyss-project.fr)
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
|
|
29
|
-
Voir la [documentation produit](https://docs.abyss-project.fr/monitor) pour les guides d'utilisation, la configuration du Core, les exemples d'appel et la référence des permissions.
|
|
30
|
-
|
|
31
|
-
## Support
|
|
32
|
-
|
|
33
|
-
Pour toute demande, ouvrir un ticket depuis [l'application Abyss](https://app.abyss-project.fr/dashboard/my-account/ticket/create).
|
|
1
|
+
<img src="https://docs.abyss-project.fr/img/services/AbyssMonitor.svg" align="right" width="96" alt="" />
|
|
2
|
+
|
|
3
|
+
# Abyss Monitor
|
|
4
|
+
|
|
5
|
+
`@abyss-project/monitor`
|
|
6
|
+
|
|
7
|
+
Supervision applicative : logs, événements, alertes, Sentinels et Cron Tasks.
|
|
8
|
+
|
|
9
|
+
_Application monitoring: logs, events, alerts, Sentinels and Cron Tasks._
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @abyss-project/monitor
|
|
15
|
+
# or
|
|
16
|
+
pnpm add @abyss-project/monitor
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Liens
|
|
20
|
+
|
|
21
|
+
- **Documentation** : [https://docs.abyss-project.fr/monitor](https://docs.abyss-project.fr/monitor)
|
|
22
|
+
- **NPM** : [@abyss-project/monitor](https://www.npmjs.com/package/@abyss-project/monitor)
|
|
23
|
+
- **Swagger** : [https://monitor-api.abyss-project.fr/swagger](https://monitor-api.abyss-project.fr/swagger)
|
|
24
|
+
- **Application Abyss** : [app.abyss-project.fr](https://app.abyss-project.fr)
|
|
25
|
+
- **Statut des services** : [status.abyss-project.fr](https://status.abyss-project.fr)
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
Voir la [documentation produit](https://docs.abyss-project.fr/monitor) pour les guides d'utilisation, la configuration du Core, les exemples d'appel et la référence des permissions.
|
|
30
|
+
|
|
31
|
+
## Support
|
|
32
|
+
|
|
33
|
+
Pour toute demande, ouvrir un ticket depuis [l'application Abyss](https://app.abyss-project.fr/dashboard/my-account/ticket/create).
|
|
@@ -1,77 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RATE_LIMIT_LUA = void 0;
|
|
4
|
-
exports.RATE_LIMIT_LUA = `
|
|
5
|
-
local function load_bucket(key, capacity, refill, now)
|
|
6
|
-
local data = redis.call('HMGET', key, 'tokens', 'ts')
|
|
7
|
-
local tokens = tonumber(data[1])
|
|
8
|
-
local ts = tonumber(data[2])
|
|
9
|
-
if tokens == nil then tokens = capacity end
|
|
10
|
-
if ts == nil then ts = now end
|
|
11
|
-
local elapsed = (now - ts) / 1000.0
|
|
12
|
-
if elapsed < 0 then elapsed = 0 end
|
|
13
|
-
tokens = math.min(capacity, tokens + elapsed * refill)
|
|
14
|
-
return tokens
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
local function save_bucket(key, tokens, capacity, refill, now)
|
|
18
|
-
redis.call('HSET', key, 'tokens', tokens, 'ts', now)
|
|
19
|
-
local ttl = math.ceil(capacity / refill) * 2
|
|
20
|
-
redis.call('EXPIRE', key, ttl)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
local function reset_sec(tokens, capacity, refill, cost)
|
|
24
|
-
if tokens >= cost then return 0 end
|
|
25
|
-
return math.ceil((cost - tokens) / refill)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
local primary_cap = tonumber(ARGV[1])
|
|
29
|
-
local primary_rate = tonumber(ARGV[2])
|
|
30
|
-
local secondary_cap = tonumber(ARGV[3])
|
|
31
|
-
local secondary_rate = tonumber(ARGV[4])
|
|
32
|
-
local now = tonumber(ARGV[5])
|
|
33
|
-
local cost = tonumber(ARGV[6])
|
|
34
|
-
|
|
35
|
-
local primary_tokens = load_bucket(KEYS[1], primary_cap, primary_rate, now)
|
|
36
|
-
local secondary_tokens = 0
|
|
37
|
-
local has_secondary = KEYS[2] ~= nil and KEYS[2] ~= ''
|
|
38
|
-
if has_secondary then
|
|
39
|
-
secondary_tokens = load_bucket(KEYS[2], secondary_cap, secondary_rate, now)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
local allowed = 1
|
|
43
|
-
if primary_tokens < cost then allowed = 0 end
|
|
44
|
-
if has_secondary and secondary_tokens < cost then allowed = 0 end
|
|
45
|
-
|
|
46
|
-
if allowed == 1 then
|
|
47
|
-
primary_tokens = primary_tokens - cost
|
|
48
|
-
save_bucket(KEYS[1], primary_tokens, primary_cap, primary_rate, now)
|
|
49
|
-
if has_secondary then
|
|
50
|
-
secondary_tokens = secondary_tokens - cost
|
|
51
|
-
save_bucket(KEYS[2], secondary_tokens, secondary_cap, secondary_rate, now)
|
|
52
|
-
end
|
|
53
|
-
else
|
|
54
|
-
-- Refresh ts so refill math stays correct on next call without consuming tokens.
|
|
55
|
-
save_bucket(KEYS[1], primary_tokens, primary_cap, primary_rate, now)
|
|
56
|
-
if has_secondary then
|
|
57
|
-
save_bucket(KEYS[2], secondary_tokens, secondary_cap, secondary_rate, now)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
local primary_reset = reset_sec(primary_tokens, primary_cap, primary_rate, cost)
|
|
62
|
-
local secondary_reset = 0
|
|
63
|
-
if has_secondary then
|
|
64
|
-
secondary_reset = reset_sec(secondary_tokens, secondary_cap, secondary_rate, cost)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
allowed,
|
|
69
|
-
math.floor(primary_tokens),
|
|
70
|
-
primary_cap,
|
|
71
|
-
primary_reset,
|
|
72
|
-
math.floor(secondary_tokens),
|
|
73
|
-
secondary_cap,
|
|
74
|
-
secondary_reset,
|
|
75
|
-
}
|
|
4
|
+
exports.RATE_LIMIT_LUA = `
|
|
5
|
+
local function load_bucket(key, capacity, refill, now)
|
|
6
|
+
local data = redis.call('HMGET', key, 'tokens', 'ts')
|
|
7
|
+
local tokens = tonumber(data[1])
|
|
8
|
+
local ts = tonumber(data[2])
|
|
9
|
+
if tokens == nil then tokens = capacity end
|
|
10
|
+
if ts == nil then ts = now end
|
|
11
|
+
local elapsed = (now - ts) / 1000.0
|
|
12
|
+
if elapsed < 0 then elapsed = 0 end
|
|
13
|
+
tokens = math.min(capacity, tokens + elapsed * refill)
|
|
14
|
+
return tokens
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
local function save_bucket(key, tokens, capacity, refill, now)
|
|
18
|
+
redis.call('HSET', key, 'tokens', tokens, 'ts', now)
|
|
19
|
+
local ttl = math.ceil(capacity / refill) * 2
|
|
20
|
+
redis.call('EXPIRE', key, ttl)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
local function reset_sec(tokens, capacity, refill, cost)
|
|
24
|
+
if tokens >= cost then return 0 end
|
|
25
|
+
return math.ceil((cost - tokens) / refill)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
local primary_cap = tonumber(ARGV[1])
|
|
29
|
+
local primary_rate = tonumber(ARGV[2])
|
|
30
|
+
local secondary_cap = tonumber(ARGV[3])
|
|
31
|
+
local secondary_rate = tonumber(ARGV[4])
|
|
32
|
+
local now = tonumber(ARGV[5])
|
|
33
|
+
local cost = tonumber(ARGV[6])
|
|
34
|
+
|
|
35
|
+
local primary_tokens = load_bucket(KEYS[1], primary_cap, primary_rate, now)
|
|
36
|
+
local secondary_tokens = 0
|
|
37
|
+
local has_secondary = KEYS[2] ~= nil and KEYS[2] ~= ''
|
|
38
|
+
if has_secondary then
|
|
39
|
+
secondary_tokens = load_bucket(KEYS[2], secondary_cap, secondary_rate, now)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
local allowed = 1
|
|
43
|
+
if primary_tokens < cost then allowed = 0 end
|
|
44
|
+
if has_secondary and secondary_tokens < cost then allowed = 0 end
|
|
45
|
+
|
|
46
|
+
if allowed == 1 then
|
|
47
|
+
primary_tokens = primary_tokens - cost
|
|
48
|
+
save_bucket(KEYS[1], primary_tokens, primary_cap, primary_rate, now)
|
|
49
|
+
if has_secondary then
|
|
50
|
+
secondary_tokens = secondary_tokens - cost
|
|
51
|
+
save_bucket(KEYS[2], secondary_tokens, secondary_cap, secondary_rate, now)
|
|
52
|
+
end
|
|
53
|
+
else
|
|
54
|
+
-- Refresh ts so refill math stays correct on next call without consuming tokens.
|
|
55
|
+
save_bucket(KEYS[1], primary_tokens, primary_cap, primary_rate, now)
|
|
56
|
+
if has_secondary then
|
|
57
|
+
save_bucket(KEYS[2], secondary_tokens, secondary_cap, secondary_rate, now)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
local primary_reset = reset_sec(primary_tokens, primary_cap, primary_rate, cost)
|
|
62
|
+
local secondary_reset = 0
|
|
63
|
+
if has_secondary then
|
|
64
|
+
secondary_reset = reset_sec(secondary_tokens, secondary_cap, secondary_rate, cost)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
allowed,
|
|
69
|
+
math.floor(primary_tokens),
|
|
70
|
+
primary_cap,
|
|
71
|
+
primary_reset,
|
|
72
|
+
math.floor(secondary_tokens),
|
|
73
|
+
secondary_cap,
|
|
74
|
+
secondary_reset,
|
|
75
|
+
}
|
|
76
76
|
`;
|
|
77
77
|
//# sourceMappingURL=rate-limit.lua.js.map
|
package/jest.config.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { Config } from '@jest/types';
|
|
2
|
-
|
|
3
|
-
const config: Config.InitialOptions = {
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
testTimeout: 10000,
|
|
6
|
-
verbose: true,
|
|
7
|
-
transform: {
|
|
8
|
-
'^.+\\.tsx?$': ['ts-jest', { isolatedModules: true }],
|
|
9
|
-
},
|
|
10
|
-
testMatch: ['<rootDir>/src/**/__tests__/**/*.test.ts'],
|
|
11
|
-
modulePathIgnorePatterns: ['dist'],
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default config;
|
|
1
|
+
import type { Config } from '@jest/types';
|
|
2
|
+
|
|
3
|
+
const config: Config.InitialOptions = {
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
testTimeout: 10000,
|
|
6
|
+
verbose: true,
|
|
7
|
+
transform: {
|
|
8
|
+
'^.+\\.tsx?$': ['ts-jest', { isolatedModules: true }],
|
|
9
|
+
},
|
|
10
|
+
testMatch: ['<rootDir>/src/**/__tests__/**/*.test.ts'],
|
|
11
|
+
modulePathIgnorePatterns: ['dist'],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default config;
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"incremental": false,
|
|
4
|
-
"target": "es2021",
|
|
5
|
-
"lib": [
|
|
6
|
-
"dom",
|
|
7
|
-
"es2021"
|
|
8
|
-
],
|
|
9
|
-
"experimentalDecorators": true,
|
|
10
|
-
"emitDecoratorMetadata": true,
|
|
11
|
-
"module": "commonjs",
|
|
12
|
-
"rootDir": "src",
|
|
13
|
-
"moduleResolution": "node",
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
"allowJs": true,
|
|
16
|
-
"declaration": true,
|
|
17
|
-
"sourceMap": true,
|
|
18
|
-
"outDir": "./dist",
|
|
19
|
-
"removeComments": true,
|
|
20
|
-
"allowSyntheticDefaultImports": true,
|
|
21
|
-
"esModuleInterop": true,
|
|
22
|
-
"forceConsistentCasingInFileNames": true,
|
|
23
|
-
"strict": true,
|
|
24
|
-
"strictNullChecks": true,
|
|
25
|
-
"strictFunctionTypes": true,
|
|
26
|
-
"strictPropertyInitialization": false,
|
|
27
|
-
"skipLibCheck": true
|
|
28
|
-
},
|
|
29
|
-
"include": [
|
|
30
|
-
"./src"
|
|
31
|
-
],
|
|
32
|
-
"exclude": [
|
|
33
|
-
"./dist/**/*"
|
|
34
|
-
]
|
|
35
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"incremental": false,
|
|
4
|
+
"target": "es2021",
|
|
5
|
+
"lib": [
|
|
6
|
+
"dom",
|
|
7
|
+
"es2021"
|
|
8
|
+
],
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"emitDecoratorMetadata": true,
|
|
11
|
+
"module": "commonjs",
|
|
12
|
+
"rootDir": "src",
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"allowJs": true,
|
|
16
|
+
"declaration": true,
|
|
17
|
+
"sourceMap": true,
|
|
18
|
+
"outDir": "./dist",
|
|
19
|
+
"removeComments": true,
|
|
20
|
+
"allowSyntheticDefaultImports": true,
|
|
21
|
+
"esModuleInterop": true,
|
|
22
|
+
"forceConsistentCasingInFileNames": true,
|
|
23
|
+
"strict": true,
|
|
24
|
+
"strictNullChecks": true,
|
|
25
|
+
"strictFunctionTypes": true,
|
|
26
|
+
"strictPropertyInitialization": false,
|
|
27
|
+
"skipLibCheck": true
|
|
28
|
+
},
|
|
29
|
+
"include": [
|
|
30
|
+
"./src"
|
|
31
|
+
],
|
|
32
|
+
"exclude": [
|
|
33
|
+
"./dist/**/*"
|
|
34
|
+
]
|
|
35
|
+
}
|