@midwayjs/prometheus 3.0.0-alpha.9 → 3.0.0-beta.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * node v16 typings ([#1269](https://github.com/midwayjs/midway/issues/1269)) ([e3443b5](https://github.com/midwayjs/midway/commit/e3443b58fc1faddadf1e95dd03a2f319410941bb))
12
+
13
+
14
+ ### Features
15
+
16
+ * add setDiff ([#1263](https://github.com/midwayjs/midway/issues/1263)) ([9dd1a08](https://github.com/midwayjs/midway/commit/9dd1a08326540da52abf79cf31182d4e63b7f4d9))
17
+
18
+
19
+
20
+
21
+
6
22
  ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
7
23
 
8
24
  **Note:** Version bump only for package @midwayjs/prometheus
@@ -1,8 +1,8 @@
1
- export declare class AutoConfiguration {
1
+ export declare class PrometheusConfiguration {
2
2
  prometheusConfig: any;
3
3
  app: any;
4
4
  http_server: any;
5
- onReady(contanier: any): Promise<void>;
5
+ onReady(): Promise<void>;
6
6
  onStop(): Promise<void>;
7
7
  }
8
8
  //# sourceMappingURL=configuration.d.ts.map
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AutoConfiguration = void 0;
12
+ exports.PrometheusConfiguration = void 0;
13
13
  const decorator_1 = require("@midwayjs/decorator");
14
14
  const path_1 = require("path");
15
15
  const PromClient = require("prom-client");
@@ -20,10 +20,10 @@ const fs = require("fs");
20
20
  const http = require("http");
21
21
  const qs = require("querystring");
22
22
  const dataService_1 = require("./service/dataService");
23
- let AutoConfiguration = class AutoConfiguration {
24
- async onReady(contanier) {
23
+ let PrometheusConfiguration = class PrometheusConfiguration {
24
+ async onReady() {
25
25
  PromClient.collectDefaultMetrics(this.prometheusConfig);
26
- const modules = decorator_1.listModule('prometheus:master');
26
+ const modules = (0, decorator_1.listModule)('prometheus:master');
27
27
  const handlers = {};
28
28
  let sockFile = path.join(os.tmpdir(), 'midway-master.sock');
29
29
  if (process.platform === 'win32') {
@@ -31,7 +31,7 @@ let AutoConfiguration = class AutoConfiguration {
31
31
  '\\\\.\\pipe\\' + sockFile.replace(/^\//, '').replace(/\//g, '-');
32
32
  }
33
33
  if (modules.length > 0 && process.platform !== 'win32') {
34
- if (utils_1.isMaster()) {
34
+ if ((0, utils_1.isMaster)()) {
35
35
  if (fs.existsSync(sockFile)) {
36
36
  fs.unlinkSync(sockFile);
37
37
  }
@@ -47,9 +47,9 @@ let AutoConfiguration = class AutoConfiguration {
47
47
  }
48
48
  }
49
49
  for (const module of modules) {
50
- const rules = decorator_1.getClassMetadata('prometheus:master:options', module);
50
+ const rules = (0, decorator_1.getClassMetadata)('prometheus:master:options', module);
51
51
  for (const rule of rules) {
52
- if (utils_1.isMaster()) {
52
+ if ((0, utils_1.isMaster)()) {
53
53
  handlers[rule.name] = async (...args) => {
54
54
  const service = await this.app
55
55
  .createAnonymousContext()
@@ -85,25 +85,25 @@ let AutoConfiguration = class AutoConfiguration {
85
85
  });
86
86
  }
87
87
  async onStop() {
88
- if (utils_1.isMaster()) {
89
- utils_1.closeLock();
88
+ if ((0, utils_1.isMaster)()) {
89
+ (0, utils_1.closeLock)();
90
90
  this.http_server && this.http_server.close();
91
91
  }
92
92
  }
93
93
  };
94
94
  __decorate([
95
- decorator_1.Config('prometheus'),
95
+ (0, decorator_1.Config)('prometheus'),
96
96
  __metadata("design:type", Object)
97
- ], AutoConfiguration.prototype, "prometheusConfig", void 0);
97
+ ], PrometheusConfiguration.prototype, "prometheusConfig", void 0);
98
98
  __decorate([
99
- decorator_1.App(),
99
+ (0, decorator_1.App)(),
100
100
  __metadata("design:type", Object)
101
- ], AutoConfiguration.prototype, "app", void 0);
102
- AutoConfiguration = __decorate([
103
- decorator_1.Configuration({
101
+ ], PrometheusConfiguration.prototype, "app", void 0);
102
+ PrometheusConfiguration = __decorate([
103
+ (0, decorator_1.Configuration)({
104
104
  namespace: 'prometheus',
105
- importConfigs: [path_1.join(__dirname, 'config')],
105
+ importConfigs: [(0, path_1.join)(__dirname, 'config')],
106
106
  })
107
- ], AutoConfiguration);
108
- exports.AutoConfiguration = AutoConfiguration;
107
+ ], PrometheusConfiguration);
108
+ exports.PrometheusConfiguration = PrometheusConfiguration;
109
109
  //# sourceMappingURL=configuration.js.map
@@ -9,9 +9,9 @@ const utils_1 = require("../utils/utils");
9
9
  const qs = require("querystring");
10
10
  function Master() {
11
11
  return function (target, propertyKey, descriptor) {
12
- decorator_1.saveModule('prometheus:master', target.constructor);
12
+ (0, decorator_1.saveModule)('prometheus:master', target.constructor);
13
13
  const sockFile = path.join(os.tmpdir(), 'midway-master.sock');
14
- if (!utils_1.isMaster()) {
14
+ if (!(0, utils_1.isMaster)()) {
15
15
  descriptor.value = (...args) => {
16
16
  const params = {
17
17
  path: `${target.constructor.name}_${propertyKey}`,
@@ -26,7 +26,7 @@ function Master() {
26
26
  });
27
27
  };
28
28
  }
29
- decorator_1.attachClassMetadata('prometheus:master:options', {
29
+ (0, decorator_1.attachClassMetadata)('prometheus:master:options', {
30
30
  name: `${target.constructor.name}_${propertyKey}`,
31
31
  value: descriptor.value,
32
32
  }, target.constructor);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AutoConfiguration as Configuration } from './configuration';
1
+ export { PrometheusConfiguration as Configuration } from './configuration';
2
2
  export { DefaultMetricsCollectorConfiguration as DefaultConfig } from 'prom-client';
3
3
  export { DataService } from './service/dataService';
4
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataService = exports.Configuration = void 0;
4
4
  var configuration_1 = require("./configuration");
5
- Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.AutoConfiguration; } });
5
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.PrometheusConfiguration; } });
6
6
  var dataService_1 = require("./service/dataService");
7
7
  Object.defineProperty(exports, "DataService", { enumerable: true, get: function () { return dataService_1.DataService; } });
8
8
  //# sourceMappingURL=index.js.map
@@ -8,9 +8,10 @@ export declare class DataService {
8
8
  bInit: boolean;
9
9
  init(): Promise<void>;
10
10
  getUser(method: any, status: any, path: any, time: any): Promise<void>;
11
- define(name: any, type: any, options: any): Promise<void>;
11
+ define(name: any, type: any, options: any): void;
12
12
  inc(name: any, labels: any, value?: number): Promise<void>;
13
13
  set(name: any, value: any): Promise<void>;
14
+ setDiff(name: any, diff: any): Promise<void>;
14
15
  getData(): Promise<string>;
15
16
  }
16
17
  //# sourceMappingURL=dataService.d.ts.map
@@ -54,7 +54,7 @@ let DataService = class DataService {
54
54
  .labels(method, status, path, ...Object.values(this.prometheusConfig.labels))
55
55
  .observe(time);
56
56
  }
57
- async define(name, type, options) {
57
+ define(name, type, options) {
58
58
  options.labelNames = options.labelNames
59
59
  ? [...options.labelNames, ...Object.keys(this.prometheusConfig.labels)]
60
60
  : Object.keys(this.prometheusConfig.labels);
@@ -66,42 +66,56 @@ let DataService = class DataService {
66
66
  async set(name, value) {
67
67
  this.userDefinedMetrics[name].set({ ...this.prometheusConfig.labels }, value);
68
68
  }
69
+ async setDiff(name, diff) {
70
+ const current = await this.userDefinedMetrics[name].get();
71
+ let value = diff;
72
+ if (current.values.length !== 0) {
73
+ value = current.values[0].value + diff;
74
+ }
75
+ this.userDefinedMetrics[name].set({ ...this.prometheusConfig.labels }, value);
76
+ }
69
77
  async getData() {
70
78
  const Register = PromClient.register;
71
79
  return Register.metrics();
72
80
  }
73
81
  };
74
82
  __decorate([
75
- decorator_1.Config('prometheus'),
83
+ (0, decorator_1.Config)('prometheus'),
76
84
  __metadata("design:type", Object)
77
85
  ], DataService.prototype, "prometheusConfig", void 0);
78
86
  __decorate([
79
- master_1.Master(),
87
+ (0, master_1.Master)(),
80
88
  __metadata("design:type", Function),
81
89
  __metadata("design:paramtypes", [Object, Object, Object, Object]),
82
90
  __metadata("design:returntype", Promise)
83
91
  ], DataService.prototype, "getUser", null);
84
92
  __decorate([
85
- master_1.Master(),
93
+ (0, master_1.Master)(),
86
94
  __metadata("design:type", Function),
87
95
  __metadata("design:paramtypes", [Object, Object, Object]),
88
96
  __metadata("design:returntype", Promise)
89
97
  ], DataService.prototype, "inc", null);
90
98
  __decorate([
91
- master_1.Master(),
99
+ (0, master_1.Master)(),
92
100
  __metadata("design:type", Function),
93
101
  __metadata("design:paramtypes", [Object, Object]),
94
102
  __metadata("design:returntype", Promise)
95
103
  ], DataService.prototype, "set", null);
96
104
  __decorate([
97
- master_1.Master(),
105
+ (0, master_1.Master)(),
106
+ __metadata("design:type", Function),
107
+ __metadata("design:paramtypes", [Object, Object]),
108
+ __metadata("design:returntype", Promise)
109
+ ], DataService.prototype, "setDiff", null);
110
+ __decorate([
111
+ (0, master_1.Master)(),
98
112
  __metadata("design:type", Function),
99
113
  __metadata("design:paramtypes", []),
100
114
  __metadata("design:returntype", Promise)
101
115
  ], DataService.prototype, "getData", null);
102
116
  DataService = __decorate([
103
- decorator_1.Provide(),
104
- decorator_1.Scope(decorator_1.ScopeEnum.Singleton)
117
+ (0, decorator_1.Provide)(),
118
+ (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
105
119
  ], DataService);
106
120
  exports.DataService = DataService;
107
121
  //# sourceMappingURL=dataService.js.map
@@ -11,7 +11,8 @@ const ppid = process.ppid;
11
11
  const now = new Date();
12
12
  const lockFile = path.join(os.tmpdir(), `midway-master-${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}-${ppid}.lock`);
13
13
  function isMaster() {
14
- if (cluster.isMaster) {
14
+ // fix for node v16
15
+ if (cluster['isPrimary'] || cluster['isMaster']) {
15
16
  return true;
16
17
  }
17
18
  if (process.argv[1].indexOf('egg-cluster') >= 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/prometheus",
3
- "version": "3.0.0-alpha.9+d5acc750",
3
+ "version": "3.0.0-beta.1",
4
4
  "description": "midway component for prometheus",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -22,10 +22,10 @@
22
22
  ],
23
23
  "license": "MIT",
24
24
  "devDependencies": {
25
- "@midwayjs/core": "^3.0.0-alpha.9+d5acc750",
26
- "@midwayjs/decorator": "^3.0.0-alpha.2",
27
- "@midwayjs/koa": "^3.0.0-alpha.9+d5acc750",
28
- "@midwayjs/mock": "^3.0.0-alpha.9+d5acc750",
25
+ "@midwayjs/core": "^3.0.0-beta.1",
26
+ "@midwayjs/decorator": "^3.0.0-beta.1",
27
+ "@midwayjs/koa": "^3.0.0-beta.1",
28
+ "@midwayjs/mock": "^3.0.0-beta.1",
29
29
  "@types/request": "^2.48.5"
30
30
  },
31
31
  "dependencies": {
@@ -33,7 +33,7 @@
33
33
  "request": "^2.88.2"
34
34
  },
35
35
  "engines": {
36
- "node": ">= 12.0.0"
36
+ "node": ">=12"
37
37
  },
38
- "gitHead": "d5acc7505275ea9d566edd38e5e0377141e0abc1"
38
+ "gitHead": "72e4d20c678e65a5440c4e9a6d3b70046daa497c"
39
39
  }