@tramvai/module-metrics 4.24.1 → 4.26.0
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/README.md +2 -0
- package/lib/request/MetricsServicesRegistry.d.ts +1 -1
- package/lib/request/MetricsServicesRegistry.es.js +16 -1
- package/lib/request/MetricsServicesRegistry.js +16 -1
- package/lib/request/createRequestWithMetrics.es.js +1 -1
- package/lib/request/createRequestWithMetrics.js +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -18,6 +18,8 @@ Next labels are added to metrics:
|
|
|
18
18
|
|
|
19
19
|
Name of the service calculates by comparing request urls with values in `MetricsServicesRegistry`. Initially the register is bootstrapped with the inverted content of env variables, e.g. if some url from env is a substring of the request url, then the name of the env become the service name. If several envs matches this logic then the env with the longest url is used.
|
|
20
20
|
|
|
21
|
+
If you need to customize the service name you can provide HTTP header to the request via `x-tramvai-service-name` header.
|
|
22
|
+
|
|
21
23
|
### Event Loop Lag
|
|
22
24
|
|
|
23
25
|
This module has their own implementation of Event Loop Lag metric - `nodejs_eventloop_setinterval_lag_seconds` histogram, this metric implemented with `setTimeout`.
|
|
@@ -3,7 +3,7 @@ declare class MetricsServicesRegistry implements MetricsServicesRegistryInterfac
|
|
|
3
3
|
private registryPrefixTree;
|
|
4
4
|
registerEnv(env: any): void;
|
|
5
5
|
register(url: any, serviceName: any): void;
|
|
6
|
-
getServiceName(url: any):
|
|
6
|
+
getServiceName(url: string, options?: Record<string, any>): any;
|
|
7
7
|
}
|
|
8
8
|
export { MetricsServicesRegistry };
|
|
9
9
|
//# sourceMappingURL=MetricsServicesRegistry.d.ts.map
|
|
@@ -3,6 +3,7 @@ import { PrefixTree } from './PrefixTree.es.js';
|
|
|
3
3
|
|
|
4
4
|
const NO_PROTOCOL = 'NO PROTOCOL';
|
|
5
5
|
const PROTOCOL_REGEX = /^([a-z0-9.+-]+:)/i;
|
|
6
|
+
const SERVICE_NAME_HEADER = 'x-tramvai-service-name';
|
|
6
7
|
const splitProtocolAndUrl = (url) => {
|
|
7
8
|
// Регулярка используется потому что протокол обязателен и класс URL не распарсит такую строку
|
|
8
9
|
const urlMatches = url.match(PROTOCOL_REGEX);
|
|
@@ -38,10 +39,24 @@ class MetricsServicesRegistry {
|
|
|
38
39
|
[protocol || NO_PROTOCOL]: serviceName,
|
|
39
40
|
}));
|
|
40
41
|
}
|
|
41
|
-
getServiceName(url) {
|
|
42
|
+
getServiceName(url, options) {
|
|
43
|
+
var _a, _b, _c;
|
|
42
44
|
if (!url) {
|
|
43
45
|
return undefined;
|
|
44
46
|
}
|
|
47
|
+
const serviceFromHeaders = typeof ((_a = options === null || options === void 0 ? void 0 : options.headers) === null || _a === void 0 ? void 0 : _a.get) === 'function'
|
|
48
|
+
? options.headers.get(SERVICE_NAME_HEADER)
|
|
49
|
+
: (_b = options === null || options === void 0 ? void 0 : options.headers) === null || _b === void 0 ? void 0 : _b[SERVICE_NAME_HEADER];
|
|
50
|
+
if (serviceFromHeaders) {
|
|
51
|
+
if (typeof options.headers.delete === 'function') {
|
|
52
|
+
options.headers.delete(SERVICE_NAME_HEADER);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// eslint-disable-next-line no-param-reassign
|
|
56
|
+
(_c = options === null || options === void 0 ? void 0 : options.headers) === null || _c === void 0 ? true : delete _c[SERVICE_NAME_HEADER];
|
|
57
|
+
}
|
|
58
|
+
return serviceFromHeaders;
|
|
59
|
+
}
|
|
45
60
|
const [protocol, urlWOProtocol] = splitProtocolAndUrl(url);
|
|
46
61
|
const treeValue = this.registryPrefixTree.get(urlWOProtocol);
|
|
47
62
|
if (!treeValue) {
|
|
@@ -11,6 +11,7 @@ var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
|
|
|
11
11
|
|
|
12
12
|
const NO_PROTOCOL = 'NO PROTOCOL';
|
|
13
13
|
const PROTOCOL_REGEX = /^([a-z0-9.+-]+:)/i;
|
|
14
|
+
const SERVICE_NAME_HEADER = 'x-tramvai-service-name';
|
|
14
15
|
const splitProtocolAndUrl = (url) => {
|
|
15
16
|
// Регулярка используется потому что протокол обязателен и класс URL не распарсит такую строку
|
|
16
17
|
const urlMatches = url.match(PROTOCOL_REGEX);
|
|
@@ -46,10 +47,24 @@ class MetricsServicesRegistry {
|
|
|
46
47
|
[protocol || NO_PROTOCOL]: serviceName,
|
|
47
48
|
}));
|
|
48
49
|
}
|
|
49
|
-
getServiceName(url) {
|
|
50
|
+
getServiceName(url, options) {
|
|
51
|
+
var _a, _b, _c;
|
|
50
52
|
if (!url) {
|
|
51
53
|
return undefined;
|
|
52
54
|
}
|
|
55
|
+
const serviceFromHeaders = typeof ((_a = options === null || options === void 0 ? void 0 : options.headers) === null || _a === void 0 ? void 0 : _a.get) === 'function'
|
|
56
|
+
? options.headers.get(SERVICE_NAME_HEADER)
|
|
57
|
+
: (_b = options === null || options === void 0 ? void 0 : options.headers) === null || _b === void 0 ? void 0 : _b[SERVICE_NAME_HEADER];
|
|
58
|
+
if (serviceFromHeaders) {
|
|
59
|
+
if (typeof options.headers.delete === 'function') {
|
|
60
|
+
options.headers.delete(SERVICE_NAME_HEADER);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// eslint-disable-next-line no-param-reassign
|
|
64
|
+
(_c = options === null || options === void 0 ? void 0 : options.headers) === null || _c === void 0 ? true : delete _c[SERVICE_NAME_HEADER];
|
|
65
|
+
}
|
|
66
|
+
return serviceFromHeaders;
|
|
67
|
+
}
|
|
53
68
|
const [protocol, urlWOProtocol] = splitProtocolAndUrl(url);
|
|
54
69
|
const treeValue = this.registryPrefixTree.get(urlWOProtocol);
|
|
55
70
|
if (!treeValue) {
|
|
@@ -61,7 +61,7 @@ const createRequestWithMetrics = ({ metricsInstances: { requestsTotal, requestsE
|
|
|
61
61
|
const socketSet = new WeakSet();
|
|
62
62
|
return function requestWithMetrics(originalRequest, ...args) {
|
|
63
63
|
const [url, options] = getUrlAndOptions(args);
|
|
64
|
-
const serviceName = getServiceName(url);
|
|
64
|
+
const serviceName = getServiceName(url, options);
|
|
65
65
|
const req = originalRequest.apply(this, args);
|
|
66
66
|
const timerDone = requestsDuration.startTimer();
|
|
67
67
|
const labelsValues = {
|
|
@@ -65,7 +65,7 @@ const createRequestWithMetrics = ({ metricsInstances: { requestsTotal, requestsE
|
|
|
65
65
|
const socketSet = new WeakSet();
|
|
66
66
|
return function requestWithMetrics(originalRequest, ...args) {
|
|
67
67
|
const [url, options] = getUrlAndOptions(args);
|
|
68
|
-
const serviceName = getServiceName(url);
|
|
68
|
+
const serviceName = getServiceName(url, options);
|
|
69
69
|
const req = originalRequest.apply(this, args);
|
|
70
70
|
const timerDone = requestsDuration.startTimer();
|
|
71
71
|
const labelsValues = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-metrics",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.26.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"browser": "lib/browser.js",
|
|
6
6
|
"main": "lib/server.js",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
"watch": "tsc -w"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@tramvai/core": "4.
|
|
22
|
-
"@tramvai/tokens-common": "4.
|
|
23
|
-
"@tramvai/tokens-core-private": "4.
|
|
24
|
-
"@tramvai/tokens-server": "4.
|
|
25
|
-
"@tramvai/tokens-server-private": "4.
|
|
26
|
-
"@tramvai/tokens-metrics": "4.
|
|
27
|
-
"@tramvai/tokens-router": "4.
|
|
28
|
-
"@tramvai/tokens-http-client": "4.
|
|
29
|
-
"@tramvai/state": "4.
|
|
30
|
-
"@tramvai/papi": "4.
|
|
21
|
+
"@tramvai/core": "4.26.0",
|
|
22
|
+
"@tramvai/tokens-common": "4.26.0",
|
|
23
|
+
"@tramvai/tokens-core-private": "4.26.0",
|
|
24
|
+
"@tramvai/tokens-server": "4.26.0",
|
|
25
|
+
"@tramvai/tokens-server-private": "4.26.0",
|
|
26
|
+
"@tramvai/tokens-metrics": "4.26.0",
|
|
27
|
+
"@tramvai/tokens-router": "4.26.0",
|
|
28
|
+
"@tramvai/tokens-http-client": "4.26.0",
|
|
29
|
+
"@tramvai/state": "4.26.0",
|
|
30
|
+
"@tramvai/papi": "4.26.0",
|
|
31
31
|
"@tinkoff/measure-fastify-requests": "0.3.1",
|
|
32
32
|
"@tinkoff/monkeypatch": "4.0.1",
|
|
33
33
|
"@tinkoff/url": "0.10.1",
|
|
34
34
|
"@tinkoff/utils": "^2.1.2",
|
|
35
35
|
"prom-client": "^14.2.0",
|
|
36
|
-
"@tinkoff/logger": "0.10.
|
|
36
|
+
"@tinkoff/logger": "0.10.276",
|
|
37
37
|
"@tinkoff/metrics-noop": "4.0.1",
|
|
38
38
|
"@tinkoff/browser-timings": "0.12.1"
|
|
39
39
|
},
|