@promster/metrics 4.1.13 → 6.0.2

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.
Files changed (93) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/{modules → declarations/src}/client/client.d.ts +4 -4
  3. package/dist/{modules → declarations/src}/client/index.d.ts +2 -2
  4. package/dist/{modules → declarations/src}/create-gc-observer/create-gc-observer.d.ts +2 -2
  5. package/dist/{modules → declarations/src}/create-gc-observer/index.d.ts +2 -2
  6. package/dist/{modules → declarations/src}/create-metric-types/create-metric-types.d.ts +25 -25
  7. package/dist/{modules → declarations/src}/create-metric-types/index.d.ts +2 -2
  8. package/dist/{modules → declarations/src}/create-request-recorder/create-request-recorder.d.ts +23 -23
  9. package/dist/{modules → declarations/src}/create-request-recorder/index.d.ts +3 -3
  10. package/dist/{modules → declarations/src}/index.d.ts +9 -10
  11. package/dist/{modules → declarations/src}/kubernetes/index.d.ts +2 -2
  12. package/dist/{modules → declarations/src}/kubernetes/kubernetes.d.ts +2 -2
  13. package/dist/{modules → declarations/src}/normalizers/index.d.ts +9 -9
  14. package/dist/{modules → declarations/src}/normalizers/method/index.d.ts +2 -2
  15. package/dist/{modules → declarations/src}/normalizers/method/method.d.ts +2 -2
  16. package/dist/{modules → declarations/src}/normalizers/path/index.d.ts +2 -2
  17. package/dist/{modules → declarations/src}/normalizers/path/path.d.ts +2 -2
  18. package/dist/{modules → declarations/src}/normalizers/status-code/index.d.ts +2 -2
  19. package/dist/{modules → declarations/src}/normalizers/status-code/status-code.d.ts +2 -2
  20. package/dist/{modules → declarations/src}/summary/index.d.ts +2 -2
  21. package/dist/{modules → declarations/src}/summary/summary.d.ts +3 -3
  22. package/dist/promster-metrics.cjs.d.ts +1 -0
  23. package/dist/promster-metrics.cjs.dev.js +315 -0
  24. package/dist/promster-metrics.cjs.js +7 -0
  25. package/dist/promster-metrics.cjs.prod.js +315 -0
  26. package/package.json +13 -15
  27. package/dist/modules/client/client.js +0 -18
  28. package/dist/modules/client/client.js.map +0 -1
  29. package/dist/modules/client/index.js +0 -8
  30. package/dist/modules/client/index.js.map +0 -1
  31. package/dist/modules/create-gc-observer/create-gc-observer.js +0 -31
  32. package/dist/modules/create-gc-observer/create-gc-observer.js.map +0 -1
  33. package/dist/modules/create-gc-observer/index.js +0 -6
  34. package/dist/modules/create-gc-observer/index.js.map +0 -1
  35. package/dist/modules/create-metric-types/create-metric-types.js +0 -154
  36. package/dist/modules/create-metric-types/create-metric-types.js.map +0 -1
  37. package/dist/modules/create-metric-types/index.js +0 -6
  38. package/dist/modules/create-metric-types/index.js.map +0 -1
  39. package/dist/modules/create-request-recorder/create-request-recorder.js +0 -79
  40. package/dist/modules/create-request-recorder/create-request-recorder.js.map +0 -1
  41. package/dist/modules/create-request-recorder/index.js +0 -6
  42. package/dist/modules/create-request-recorder/index.js.map +0 -1
  43. package/dist/modules/index.js +0 -25
  44. package/dist/modules/index.js.map +0 -1
  45. package/dist/modules/kubernetes/index.js +0 -6
  46. package/dist/modules/kubernetes/index.js.map +0 -1
  47. package/dist/modules/kubernetes/kubernetes.js +0 -6
  48. package/dist/modules/kubernetes/kubernetes.js.map +0 -1
  49. package/dist/modules/normalizers/index.js +0 -16
  50. package/dist/modules/normalizers/index.js.map +0 -1
  51. package/dist/modules/normalizers/method/index.js +0 -6
  52. package/dist/modules/normalizers/method/index.js.map +0 -1
  53. package/dist/modules/normalizers/method/method.js +0 -6
  54. package/dist/modules/normalizers/method/method.js.map +0 -1
  55. package/dist/modules/normalizers/path/index.js +0 -6
  56. package/dist/modules/normalizers/path/index.js.map +0 -1
  57. package/dist/modules/normalizers/path/path.js +0 -10
  58. package/dist/modules/normalizers/path/path.js.map +0 -1
  59. package/dist/modules/normalizers/status-code/index.js +0 -6
  60. package/dist/modules/normalizers/status-code/index.js.map +0 -1
  61. package/dist/modules/normalizers/status-code/status-code.js +0 -6
  62. package/dist/modules/normalizers/status-code/status-code.js.map +0 -1
  63. package/dist/modules/summary/index.js +0 -7
  64. package/dist/modules/summary/index.js.map +0 -1
  65. package/dist/modules/summary/summary.js +0 -9
  66. package/dist/modules/summary/summary.js.map +0 -1
  67. package/dist/package.json +0 -61
  68. package/modules/client/client.ts +0 -24
  69. package/modules/client/index.ts +0 -3
  70. package/modules/create-gc-observer/create-gc-observer.ts +0 -50
  71. package/modules/create-gc-observer/index.ts +0 -3
  72. package/modules/create-metric-types/create-metric-types.spec.js +0 -146
  73. package/modules/create-metric-types/create-metric-types.ts +0 -229
  74. package/modules/create-metric-types/index.ts +0 -3
  75. package/modules/create-request-recorder/create-request-recorder.spec.js +0 -205
  76. package/modules/create-request-recorder/create-request-recorder.ts +0 -160
  77. package/modules/create-request-recorder/index.ts +0 -4
  78. package/modules/index.ts +0 -31
  79. package/modules/kubernetes/index.ts +0 -3
  80. package/modules/kubernetes/kubernetes.ts +0 -4
  81. package/modules/normalizers/index.ts +0 -16
  82. package/modules/normalizers/method/index.ts +0 -3
  83. package/modules/normalizers/method/method.spec.js +0 -13
  84. package/modules/normalizers/method/method.ts +0 -3
  85. package/modules/normalizers/path/index.ts +0 -3
  86. package/modules/normalizers/path/path.spec.js +0 -35
  87. package/modules/normalizers/path/path.ts +0 -9
  88. package/modules/normalizers/status-code/index.ts +0 -3
  89. package/modules/normalizers/status-code/status-code.spec.js +0 -12
  90. package/modules/normalizers/status-code/status-code.ts +0 -3
  91. package/modules/summary/index.ts +0 -3
  92. package/modules/summary/summary.spec.js +0 -37
  93. package/modules/summary/summary.ts +0 -6
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.endMeasurmentFrom = exports.sortLabels = exports.createRequestRecorder = void 0;
4
- const tslib_1 = require("tslib");
5
- const merge_options_1 = tslib_1.__importDefault(require("merge-options"));
6
- const kubernetes_1 = require("../kubernetes");
7
- const NS_PER_SEC = 1e9;
8
- const NS_PER_MS = 1e6;
9
- const sortLabels = (unsortedLabels) => {
10
- return Object.keys(unsortedLabels)
11
- .sort((a, b) => {
12
- if (a < b) {
13
- return -1;
14
- }
15
- if (a > b) {
16
- return 1;
17
- }
18
- return 0;
19
- })
20
- .reduce((sortedLabels, labelName) => {
21
- sortedLabels[labelName] = unsortedLabels[labelName];
22
- return sortedLabels;
23
- }, {});
24
- };
25
- exports.sortLabels = sortLabels;
26
- const endMeasurmentFrom = (start) => {
27
- const [seconds, nanoseconds] = process.hrtime(start);
28
- return {
29
- durationMs: Math.round((seconds * NS_PER_SEC + nanoseconds) / NS_PER_MS),
30
- durationS: (seconds * NS_PER_SEC + nanoseconds) / NS_PER_SEC,
31
- };
32
- };
33
- exports.endMeasurmentFrom = endMeasurmentFrom;
34
- const shouldObserveMetricType = (metricType) => (options) => options.metricTypes.includes(metricType);
35
- const shouldObserveMetricAccuracy = (accuracy) => (options) => options.accuracies.includes(accuracy);
36
- const defaultOptions = {
37
- accuracies: ['s'],
38
- metricTypes: ['httpRequestsTotal', 'httpRequestsHistogram'],
39
- skip: () => false,
40
- };
41
- const createRequestRecorder = (metricTypes, options = defaultOptions) => {
42
- const defaultedRecorderOptions = merge_options_1.default(defaultOptions, options);
43
- const shouldSkipMetricsByEnvironment = defaultedRecorderOptions.detectKubernetes && !kubernetes_1.isRunningInKubernetes();
44
- const shouldObserveInSeconds = shouldObserveMetricAccuracy('s')(defaultedRecorderOptions);
45
- const shouldObserveInMilliseconds = shouldObserveMetricAccuracy('ms')(defaultedRecorderOptions);
46
- const shouldObserveInSummary = shouldObserveMetricType('httpRequestsSummary')(defaultedRecorderOptions);
47
- const shouldObserveInHistogram = shouldObserveMetricType('httpRequestsHistogram')(defaultedRecorderOptions);
48
- const shouldObserveInCounter = shouldObserveMetricType('httpRequestsTotal')(defaultedRecorderOptions);
49
- return (start, recordingOptions) => {
50
- const { durationMs, durationS } = endMeasurmentFrom(start);
51
- const labels = sortLabels(recordingOptions.labels);
52
- if (shouldObserveInMilliseconds &&
53
- shouldObserveInHistogram &&
54
- !shouldSkipMetricsByEnvironment) {
55
- metricTypes.httpRequestDurationInMilliseconds.forEach((httpRequestDurationInMillisecondsMetricType) => httpRequestDurationInMillisecondsMetricType.observe(labels, durationMs));
56
- }
57
- if (shouldObserveInMilliseconds &&
58
- shouldObserveInSummary &&
59
- !shouldSkipMetricsByEnvironment) {
60
- metricTypes.httpRequestDurationPerPercentileInMilliseconds.forEach((httpRequestDurationPerPercentileInMillisecondsMetricType) => httpRequestDurationPerPercentileInMillisecondsMetricType.observe(labels, durationMs));
61
- }
62
- if (shouldObserveInSeconds &&
63
- shouldObserveInHistogram &&
64
- !shouldSkipMetricsByEnvironment) {
65
- metricTypes.httpRequestDurationInSeconds.forEach((httpRequestDurationInSecondsMetricType) => httpRequestDurationInSecondsMetricType.observe(labels, durationS));
66
- }
67
- if (shouldObserveInSeconds &&
68
- shouldObserveInSummary &&
69
- !shouldSkipMetricsByEnvironment) {
70
- metricTypes.httpRequestDurationPerPercentileInSeconds.forEach((httpRequestDurationPerPercentileInSecondsMetricType) => httpRequestDurationPerPercentileInSecondsMetricType.observe(labels, durationS));
71
- }
72
- if (shouldObserveInCounter && !shouldSkipMetricsByEnvironment) {
73
- metricTypes.httpRequestsTotal.forEach((httpRequestsTotalMetricType) => httpRequestsTotalMetricType.inc(labels));
74
- }
75
- };
76
- };
77
- exports.createRequestRecorder = createRequestRecorder;
78
- createRequestRecorder.defaultOptions = defaultOptions;
79
- //# sourceMappingURL=create-request-recorder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-request-recorder.js","sourceRoot":"","sources":["../../../modules/create-request-recorder/create-request-recorder.ts"],"names":[],"mappings":";;;;AAEA,0EAAkC;AAClC,8CAAsD;AAqBtD,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,MAAM,UAAU,GAAG,CAAC,cAA4B,EAAgB,EAAE;IAChE,OAAO,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC;SAC/B,IAAI,CAAC,CAAC,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EACN,UAAU,CACX,CACJ,CAAC;SACH;QAED,IACE,sBAAsB;YACtB,wBAAwB;YACxB,CAAC,8BAA8B,EAC/B;YACA,WAAW,CAAC,4BAA4B,CAAC,OAAO,CAC9C,CAAC,sCAAsC,EAAE,EAAE,CACzC,sCAAsC,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,CACpE,CAAC;SACH;QAED,IACE,sBAAsB;YACtB,sBAAsB;YACtB,CAAC,8BAA8B,EAC/B;YACA,WAAW,CAAC,yCAAyC,CAAC,OAAO,CAC3D,CAAC,mDAAmD,EAAE,EAAE,CACtD,mDAAmD,CAAC,OAAO,CACzD,MAAM,EACN,SAAS,CACV,CACJ,CAAC;SACH;QAED,IAAI,sBAAsB,IAAI,CAAC,8BAA8B,EAAE;YAC7D,WAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,2BAA2B,EAAE,EAAE,CACpE,2BAA2B,CAAC,GAAG,CAAC,MAAM,CAAC,CACxC,CAAC;SACH;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAIO,sDAAqB;AAF9B,qBAAqB,CAAC,cAAc,GAAG,cAAc,CAAC"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRequestRecorder = void 0;
4
- const create_request_recorder_1 = require("./create-request-recorder");
5
- Object.defineProperty(exports, "createRequestRecorder", { enumerable: true, get: function () { return create_request_recorder_1.createRequestRecorder; } });
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../modules/create-request-recorder/index.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAGzD,sGAHA,+CAAqB,OAGA"}
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRunningInKubernetes = exports.normalizeMethod = exports.normalizePath = exports.normalizeStatusCode = exports.defaultNormalizers = exports.createGcObserver = exports.createRequestRecorder = exports.getContentType = exports.getSummary = exports.createMetricTypes = exports.defaultRegister = exports.Prometheus = exports.version = void 0;
4
- const package_json_1 = require("../package.json");
5
- Object.defineProperty(exports, "version", { enumerable: true, get: function () { return package_json_1.version; } });
6
- const client_1 = require("./client");
7
- Object.defineProperty(exports, "Prometheus", { enumerable: true, get: function () { return client_1.Prometheus; } });
8
- Object.defineProperty(exports, "defaultRegister", { enumerable: true, get: function () { return client_1.defaultRegister; } });
9
- const create_metric_types_1 = require("./create-metric-types");
10
- Object.defineProperty(exports, "createMetricTypes", { enumerable: true, get: function () { return create_metric_types_1.createMetricTypes; } });
11
- const summary_1 = require("./summary");
12
- Object.defineProperty(exports, "getSummary", { enumerable: true, get: function () { return summary_1.getSummary; } });
13
- Object.defineProperty(exports, "getContentType", { enumerable: true, get: function () { return summary_1.getContentType; } });
14
- const create_request_recorder_1 = require("./create-request-recorder");
15
- Object.defineProperty(exports, "createRequestRecorder", { enumerable: true, get: function () { return create_request_recorder_1.createRequestRecorder; } });
16
- const create_gc_observer_1 = require("./create-gc-observer");
17
- Object.defineProperty(exports, "createGcObserver", { enumerable: true, get: function () { return create_gc_observer_1.createGcObserver; } });
18
- const normalizers_1 = require("./normalizers");
19
- Object.defineProperty(exports, "defaultNormalizers", { enumerable: true, get: function () { return normalizers_1.defaultNormalizers; } });
20
- Object.defineProperty(exports, "normalizeStatusCode", { enumerable: true, get: function () { return normalizers_1.normalizeStatusCode; } });
21
- Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return normalizers_1.normalizePath; } });
22
- Object.defineProperty(exports, "normalizeMethod", { enumerable: true, get: function () { return normalizers_1.normalizeMethod; } });
23
- const kubernetes_1 = require("./kubernetes");
24
- Object.defineProperty(exports, "isRunningInKubernetes", { enumerable: true, get: function () { return kubernetes_1.isRunningInKubernetes; } });
25
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../modules/index.ts"],"names":[],"mappings":";;;AAAA,kDAA0C;AAiBxC,wFAjBO,sBAAO,OAiBP;AAhBT,qCAAuD;AAiBrD,2FAjBO,mBAAU,OAiBP;AACV,gGAlBmB,wBAAe,OAkBnB;AAjBjB,+DAA0D;AAkBxD,kGAlBO,uCAAiB,OAkBP;AAjBnB,uCAAuD;AAkBrD,2FAlBO,oBAAU,OAkBP;AACV,+FAnBmB,wBAAc,OAmBnB;AAlBhB,uEAAkE;AAmBhE,sGAnBO,+CAAqB,OAmBP;AAlBvB,6DAAwD;AAmBtD,iGAnBO,qCAAgB,OAmBP;AAlBlB,+CAKuB;AAcrB,mGAlBA,gCAAkB,OAkBA;AAClB,oGAlBA,iCAAmB,OAkBA;AACnB,8FAlBA,2BAAa,OAkBA;AACb,gGAlBA,6BAAe,OAkBA;AAhBjB,6CAAqD;AAiBnD,sGAjBO,kCAAqB,OAiBP"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRunningInKubernetes = void 0;
4
- const kubernetes_1 = require("./kubernetes");
5
- Object.defineProperty(exports, "isRunningInKubernetes", { enumerable: true, get: function () { return kubernetes_1.isRunningInKubernetes; } });
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../modules/kubernetes/index.ts"],"names":[],"mappings":";;;AAAA,6CAAqD;AAE5C,sGAFA,kCAAqB,OAEA"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isRunningInKubernetes = void 0;
4
- const isRunningInKubernetes = () => Boolean(process.env.KUBERNETES_SERVICE_HOST);
5
- exports.isRunningInKubernetes = isRunningInKubernetes;
6
- //# sourceMappingURL=kubernetes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kubernetes.js","sourceRoot":"","sources":["../../../modules/kubernetes/kubernetes.ts"],"names":[],"mappings":";;;AAAA,MAAM,qBAAqB,GAAG,GAAG,EAAE,CACjC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAEtC,sDAAqB"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultNormalizers = exports.normalizeMethod = exports.normalizePath = exports.normalizeStatusCode = void 0;
4
- const status_code_1 = require("./status-code");
5
- Object.defineProperty(exports, "normalizeStatusCode", { enumerable: true, get: function () { return status_code_1.normalizeStatusCode; } });
6
- const path_1 = require("./path");
7
- Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return path_1.normalizePath; } });
8
- const method_1 = require("./method");
9
- Object.defineProperty(exports, "normalizeMethod", { enumerable: true, get: function () { return method_1.normalizeMethod; } });
10
- const defaultNormalizers = {
11
- normalizeStatusCode: status_code_1.normalizeStatusCode,
12
- normalizePath: path_1.normalizePath,
13
- normalizeMethod: method_1.normalizeMethod,
14
- };
15
- exports.defaultNormalizers = defaultNormalizers;
16
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../modules/normalizers/index.ts"],"names":[],"mappings":";;;AAAA,+CAAoD;AAWlD,oGAXO,iCAAmB,OAWP;AAVrB,iCAAuC;AAWrC,8FAXO,oBAAa,OAWP;AAVf,qCAA2C;AAWzC,gGAXO,wBAAe,OAWP;AATjB,MAAM,kBAAkB,GAAG;IACzB,mBAAmB,EAAnB,iCAAmB;IACnB,aAAa,EAAb,oBAAa;IACb,eAAe,EAAf,wBAAe;CAChB,CAAC;AAMA,gDAAkB"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeMethod = void 0;
4
- const method_1 = require("./method");
5
- Object.defineProperty(exports, "normalizeMethod", { enumerable: true, get: function () { return method_1.normalizeMethod; } });
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../modules/normalizers/method/index.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAElC,gGAFA,wBAAe,OAEA"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeMethod = void 0;
4
- const normalizeMethod = (method) => method.toLowerCase();
5
- exports.normalizeMethod = normalizeMethod;
6
- //# sourceMappingURL=method.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"method.js","sourceRoot":"","sources":["../../../../modules/normalizers/method/method.ts"],"names":[],"mappings":";;;AAAA,MAAM,eAAe,GAAG,CAAC,MAAc,EAAU,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;AAEhE,0CAAe"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizePath = void 0;
4
- const path_1 = require("./path");
5
- Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return path_1.normalizePath; } });
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../modules/normalizers/path/index.ts"],"names":[],"mappings":";;;AAAA,iCAAuC;AAE9B,8FAFA,oBAAa,OAEA"}
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizePath = void 0;
4
- const tslib_1 = require("tslib");
5
- const url_1 = tslib_1.__importDefault(require("url"));
6
- const url_value_parser_1 = tslib_1.__importDefault(require("url-value-parser"));
7
- const urlValueParser = new url_value_parser_1.default();
8
- const normalizePath = (path) => urlValueParser.replacePathValues(url_1.default.parse(path).pathname);
9
- exports.normalizePath = normalizePath;
10
- //# sourceMappingURL=path.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path.js","sourceRoot":"","sources":["../../../../modules/normalizers/path/path.ts"],"names":[],"mappings":";;;;AAAA,sDAAsB;AACtB,gFAA8C;AAE9C,MAAM,cAAc,GAAG,IAAI,0BAAc,EAAE,CAAC;AAE5C,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CAC7C,cAAc,CAAC,iBAAiB,CAAC,aAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEpD,sCAAa"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeStatusCode = void 0;
4
- const status_code_1 = require("./status-code");
5
- Object.defineProperty(exports, "normalizeStatusCode", { enumerable: true, get: function () { return status_code_1.normalizeStatusCode; } });
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../modules/normalizers/status-code/index.ts"],"names":[],"mappings":";;;AAAA,+CAAoD;AAE3C,oGAFA,iCAAmB,OAEA"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeStatusCode = void 0;
4
- const normalizeStatusCode = (statusCode) => statusCode;
5
- exports.normalizeStatusCode = normalizeStatusCode;
6
- //# sourceMappingURL=status-code.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"status-code.js","sourceRoot":"","sources":["../../../../modules/normalizers/status-code/status-code.ts"],"names":[],"mappings":";;;AAAA,MAAM,mBAAmB,GAAG,CAAC,UAAkB,EAAU,EAAE,CAAC,UAAU,CAAC;AAE9D,kDAAmB"}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getContentType = exports.getSummary = void 0;
4
- const summary_1 = require("./summary");
5
- Object.defineProperty(exports, "getSummary", { enumerable: true, get: function () { return summary_1.getSummary; } });
6
- Object.defineProperty(exports, "getContentType", { enumerable: true, get: function () { return summary_1.getContentType; } });
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../modules/summary/index.ts"],"names":[],"mappings":";;;AAAA,uCAAuD;AAE9C,2FAFA,oBAAU,OAEA;AAAE,+FAFA,wBAAc,OAEA"}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getContentType = exports.getSummary = void 0;
4
- const client_1 = require("../client");
5
- const getSummary = () => client_1.defaultRegister.metrics();
6
- exports.getSummary = getSummary;
7
- const getContentType = () => client_1.defaultRegister.contentType;
8
- exports.getContentType = getContentType;
9
- //# sourceMappingURL=summary.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"summary.js","sourceRoot":"","sources":["../../../modules/summary/summary.ts"],"names":[],"mappings":";;;AAAA,sCAA4C;AAE5C,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,wBAAe,CAAC,OAAO,EAAE,CAAC;AAG1C,gCAAU;AAFnB,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,wBAAe,CAAC,WAAW,CAAC;AAEpC,wCAAc"}
package/dist/package.json DELETED
@@ -1,61 +0,0 @@
1
- {
2
- "name": "@promster/metrics",
3
- "version": "4.1.13",
4
- "description": "Metrics utilities used by all other server integrations",
5
- "main": "dist/modules/index.js",
6
- "typings": "dist/modules/index.d.ts",
7
- "scripts": {
8
- "prebuild": "rimraf dist/**",
9
- "build": "cross-env tsc -p tsconfig.json --outDir dist --declarationDir dist"
10
- },
11
- "files": [
12
- "readme.md",
13
- "package.json",
14
- "LICENSE",
15
- "dist/**",
16
- "modules/**"
17
- ],
18
- "publishConfig": {
19
- "access": "public"
20
- },
21
- "engines": {
22
- "node": ">=9",
23
- "npm": ">=3"
24
- },
25
- "repository": {
26
- "type": "git",
27
- "url": "git+https://github.com/tdeekens/promster.git"
28
- },
29
- "author": "Tobias Deekens <nerd@tdeekens.name>",
30
- "license": "MIT",
31
- "bugs": {
32
- "url": "https://github.com/tdeekens/promster/issues"
33
- },
34
- "homepage": "https://github.com/tdeekens/promster#readme",
35
- "keywords": [
36
- "metrics",
37
- "continousdelivery",
38
- "prometheus"
39
- ],
40
- "dependencies": {
41
- "lodash.memoize": "4.1.2",
42
- "lodash.once": "4.1.1",
43
- "merge-options": "3.0.3",
44
- "optional": "0.1.4",
45
- "ts-essentials": "7.0.0",
46
- "tslib": "2.0.3",
47
- "url": "0.11.0",
48
- "url-value-parser": "2.0.1"
49
- },
50
- "devDependencies": {
51
- "@promster/types": "^1.0.8",
52
- "@types/lodash": "4.14.162",
53
- "prom-client": "12.0.0"
54
- },
55
- "optionalDependencies": {
56
- "gc-stats": "1.4.0"
57
- },
58
- "peerDependencies": {
59
- "prom-client": "12.x.x"
60
- }
61
- }
@@ -1,24 +0,0 @@
1
- import once from 'lodash.once';
2
- import * as Prometheus from 'prom-client';
3
- import { isRunningInKubernetes } from '../kubernetes';
4
-
5
- // NOTE:
6
- // This is the `globalRegistry` provided by the `prom-client`
7
- // We could create multiple registries with `new Prometheus.registry()`.
8
- const defaultRegister = Prometheus.register;
9
-
10
- interface TClientOptions
11
- extends Prometheus.DefaultMetricsCollectorConfiguration {
12
- detectKubernetes?: boolean;
13
- }
14
-
15
- const configure = once((options: TClientOptions) => {
16
- const shouldSkipMetricsByEnvironment =
17
- options.detectKubernetes === true && !isRunningInKubernetes();
18
-
19
- if (!shouldSkipMetricsByEnvironment) {
20
- Prometheus.collectDefaultMetrics(options);
21
- }
22
- });
23
-
24
- export { Prometheus, defaultRegister, configure };
@@ -1,3 +0,0 @@
1
- import { Prometheus, defaultRegister, configure } from './client';
2
-
3
- export { Prometheus, defaultRegister, configure };
@@ -1,50 +0,0 @@
1
- import type { TMetricTypes, TValueOf } from '@promster/types';
2
-
3
- import once from 'lodash.once';
4
- import requireOptional from 'optional';
5
-
6
- const gc = requireOptional('gc-stats');
7
-
8
- const gcTypes = {
9
- 0: 'unknown',
10
- 1: 'scavenge',
11
- 2: 'mark_sweep_compact',
12
- 3: 'scavenge_and_mark_sweep_compact',
13
- 4: 'incremental_marking',
14
- 8: 'weak_phantom',
15
- 15: 'all',
16
- };
17
-
18
- type TGcTypes = TValueOf<typeof gcTypes>;
19
- type TStats = {
20
- gctype: TGcTypes;
21
- pause: number;
22
- diff: {
23
- usedHeapSize: number;
24
- };
25
- };
26
-
27
- const createGcObserver = once((metricTypes: TMetricTypes) => () => {
28
- if (typeof gc !== 'function') {
29
- return;
30
- }
31
-
32
- gc().on('stats', (stats: TStats) => {
33
- const gcType = gcTypes[stats.gctype];
34
-
35
- metricTypes.countOfGcs.forEach((countOfGcMetricType) =>
36
- countOfGcMetricType.labels(gcType).inc()
37
- );
38
- metricTypes.durationOfGc.forEach((durationOfGcMetricType) =>
39
- durationOfGcMetricType.labels(gcType).inc(stats.pause / 1e9)
40
- );
41
-
42
- if (stats.diff.usedHeapSize < 0) {
43
- metricTypes.reclaimedInGc.forEach((reclaimedInGcMetricType) =>
44
- reclaimedInGcMetricType.labels(gcType).inc(stats.diff.usedHeapSize * -1)
45
- );
46
- }
47
- });
48
- });
49
-
50
- export { createGcObserver };
@@ -1,3 +0,0 @@
1
- import { createGcObserver } from './create-gc-observer';
2
-
3
- export { createGcObserver };
@@ -1,146 +0,0 @@
1
- jest.mock('../client', () => ({
2
- configure: jest.fn(),
3
- Prometheus: {
4
- Gauge: jest.fn(),
5
- Counter: jest.fn(),
6
- Summary: jest.fn(),
7
- Histogram: jest.fn(),
8
- },
9
- }));
10
-
11
- const { createMetricTypes } = require('./create-metric-types');
12
-
13
- describe('createMetricTypes', () => {
14
- let metricTypes;
15
- describe('without accuracy', () => {
16
- beforeEach(() => {
17
- metricTypes = createMetricTypes();
18
- });
19
-
20
- it('should have `up` metric', () => {
21
- expect(metricTypes).toHaveProperty('up');
22
- });
23
-
24
- it('should have `countOfGcs` metric', () => {
25
- expect(metricTypes).toHaveProperty('countOfGcs');
26
- });
27
-
28
- it('should have `durationOfGc` metric', () => {
29
- expect(metricTypes).toHaveProperty('durationOfGc');
30
- });
31
-
32
- it('should have `reclaimedInGc` metric', () => {
33
- expect(metricTypes).toHaveProperty('reclaimedInGc');
34
- });
35
-
36
- describe('with summary enabled', () => {
37
- beforeEach(() => {
38
- metricTypes = createMetricTypes({
39
- metricTypes: ['httpRequestsSummary'],
40
- });
41
- });
42
-
43
- it('should have `httpRequestDurationPerPercentileInSeconds` metric', () => {
44
- expect(metricTypes).toHaveProperty(
45
- 'httpRequestDurationPerPercentileInSeconds'
46
- );
47
- });
48
- });
49
-
50
- it('should have `httpRequestDurationInSeconds` metric', () => {
51
- expect(metricTypes).toHaveProperty('httpRequestDurationInSeconds');
52
- });
53
- });
54
-
55
- describe('with millisecond accuracy', () => {
56
- beforeEach(() => {
57
- metricTypes = createMetricTypes({ accuracies: ['ms'] });
58
- });
59
-
60
- it('should have `httpRequestDurationInMilliseconds` metric', () => {
61
- expect(metricTypes).toHaveProperty('httpRequestDurationInMilliseconds');
62
- });
63
-
64
- describe('with summary enabled', () => {
65
- beforeEach(() => {
66
- metricTypes = createMetricTypes({
67
- metricTypes: ['httpRequestsSummary'],
68
- accuracies: ['ms'],
69
- });
70
- });
71
-
72
- it('should have `httpRequestDurationPerPercentileInMilliseconds` metric', () => {
73
- expect(metricTypes).toHaveProperty(
74
- 'httpRequestDurationPerPercentileInMilliseconds'
75
- );
76
- });
77
- });
78
- });
79
-
80
- describe('with both second and millisecond accuracy', () => {
81
- beforeEach(() => {
82
- metricTypes = createMetricTypes({ accuracies: ['s', 'ms'] });
83
- });
84
-
85
- it('should have `httpRequestDurationPerPercentileInMilliseconds` metric', () => {
86
- expect(metricTypes).toHaveProperty(
87
- 'httpRequestDurationPerPercentileInMilliseconds'
88
- );
89
- });
90
-
91
- it('should have `httpRequestDurationInMilliseconds` metric', () => {
92
- expect(metricTypes).toHaveProperty('httpRequestDurationInMilliseconds');
93
- });
94
-
95
- it('should have `httpRequestDurationPerPercentileInSeconds` metric', () => {
96
- expect(metricTypes).toHaveProperty(
97
- 'httpRequestDurationPerPercentileInSeconds'
98
- );
99
- });
100
- });
101
-
102
- describe('with histogram metric type', () => {
103
- beforeEach(() => {
104
- metricTypes = createMetricTypes({
105
- metricTypes: ['httpRequestsHistogram'],
106
- });
107
- });
108
-
109
- it('should have `httpRequestDurationInSeconds` metric', () => {
110
- expect(metricTypes).toHaveProperty('httpRequestDurationInSeconds');
111
- });
112
-
113
- it('should not have `httpRequestDurationPerPercentileInSeconds` metric', () => {
114
- expect(metricTypes).toHaveProperty(
115
- 'httpRequestDurationPerPercentileInSeconds',
116
- false
117
- );
118
- });
119
- });
120
-
121
- describe('with summary metric type', () => {
122
- beforeEach(() => {
123
- metricTypes = createMetricTypes({ metricTypes: ['httpRequestsSummary'] });
124
- });
125
-
126
- it('should have `httpRequestDurationPerPercentileInSeconds` metric', () => {
127
- expect(metricTypes).toHaveProperty(
128
- 'httpRequestDurationPerPercentileInSeconds'
129
- );
130
- });
131
-
132
- it('should not have `httpRequestDurationInSeconds` metric', () => {
133
- expect(metricTypes).toHaveProperty('httpRequestDurationInSeconds', false);
134
- });
135
- });
136
-
137
- describe('with count metric type', () => {
138
- beforeEach(() => {
139
- metricTypes = createMetricTypes({ metricTypes: ['httpRequestsTotal'] });
140
- });
141
-
142
- it('should have `httpRequestsTotal` metric', () => {
143
- expect(metricTypes).toHaveProperty('httpRequestsTotal');
144
- });
145
- });
146
- });