@vtex/api 6.45.13-beta.6 → 6.45.14-beta.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/CHANGELOG.md +2 -0
- package/lib/HttpClient/HttpClient.d.ts +0 -1
- package/lib/HttpClient/HttpClient.js +1 -14
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.d.ts +1 -4
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +6 -13
- package/lib/service/worker/runtime/utils/context.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
|
+
### Changed
|
|
10
|
+
- Remove socket metrics per origin
|
|
9
11
|
|
|
10
12
|
## [6.45.12] - 2022-04-14
|
|
11
13
|
|
|
@@ -6,7 +6,6 @@ import { InstanceOptions, IOResponse, RequestConfig } from './typings';
|
|
|
6
6
|
declare type ClientOptions = IOContext & Partial<InstanceOptions>;
|
|
7
7
|
export declare class HttpClient {
|
|
8
8
|
name: string;
|
|
9
|
-
private logger;
|
|
10
9
|
private runMiddlewares;
|
|
11
10
|
constructor(opts: ClientOptions);
|
|
12
11
|
get: <T = any>(url: string, config?: RequestConfig) => Promise<T>;
|
|
@@ -31,19 +31,7 @@ class HttpClient {
|
|
|
31
31
|
return this.request(cacheableConfig);
|
|
32
32
|
};
|
|
33
33
|
this.getWithBody = (url, data, config = {}) => {
|
|
34
|
-
const
|
|
35
|
-
try {
|
|
36
|
-
return typeof v !== 'object' || v === null || Array.isArray(v) ? v :
|
|
37
|
-
Object.fromEntries(Object.entries(v).sort(([ka], [kb]) => ka < kb ? -1 : ka > kb ? 1 : 0));
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
// I don't believe this will ever happen, but just in case
|
|
41
|
-
// Also, I didn't include error as I am unsure if it would have sensitive information
|
|
42
|
-
this.logger.warn({ message: 'Error while sorting object for cache key' });
|
|
43
|
-
return v;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const bodyHash = crypto_1.createHash('md5').update(JSON.stringify(data, deterministicReplacer)).digest('hex');
|
|
34
|
+
const bodyHash = crypto_1.createHash('md5').update(JSON.stringify(data)).digest('hex');
|
|
47
35
|
const cacheableConfig = this.getConfig(url, {
|
|
48
36
|
...config,
|
|
49
37
|
data,
|
|
@@ -103,7 +91,6 @@ class HttpClient {
|
|
|
103
91
|
});
|
|
104
92
|
const { baseURL, authToken, authType, memoryCache, diskCache, locale, name, metrics, product, serverTiming, recorder, userAgent, timeout = DEFAULT_TIMEOUT_MS, segmentToken, sessionToken, retries, concurrency, headers: defaultHeaders, host, params, operationId, tenant, binding, verbose, cancellation, exponentialTimeoutCoefficient, initialBackoffDelay, exponentialBackoffCoefficient, httpsAgent, tracer, logger, } = opts;
|
|
105
93
|
this.name = name || baseURL || 'unknown';
|
|
106
|
-
this.logger = logger;
|
|
107
94
|
const limit = concurrency && concurrency > 0 && p_limit_1.default(concurrency) || undefined;
|
|
108
95
|
const headers = {
|
|
109
96
|
...defaultHeaders,
|
|
@@ -3,12 +3,9 @@ export declare class HttpAgentSingleton {
|
|
|
3
3
|
static getHttpAgent(): HttpAgent;
|
|
4
4
|
static httpAgentStats(): {
|
|
5
5
|
freeSockets: number;
|
|
6
|
-
freeSocketsPerOrigin: Record<string, number>;
|
|
7
6
|
pendingRequests: number;
|
|
8
|
-
pendingRequestsPerOrigin: Record<string, number>;
|
|
9
7
|
sockets: number;
|
|
10
|
-
socketsPerOrigin: Record<string, number>;
|
|
11
8
|
};
|
|
12
9
|
private static httpAgent;
|
|
13
|
-
private static
|
|
10
|
+
private static count;
|
|
14
11
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ramda_1 = require("ramda");
|
|
4
3
|
const agents_1 = require("../../agents");
|
|
5
4
|
class HttpAgentSingleton {
|
|
6
5
|
static getHttpAgent() {
|
|
@@ -10,27 +9,21 @@ class HttpAgentSingleton {
|
|
|
10
9
|
return HttpAgentSingleton.httpAgent;
|
|
11
10
|
}
|
|
12
11
|
static httpAgentStats() {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const freeSockets = ramda_1.sum(ramda_1.values(freeSocketsPerOrigin));
|
|
17
|
-
const pendingRequestsPerOrigin = HttpAgentSingleton.countPerOrigin(HttpAgentSingleton.httpAgent.requests);
|
|
18
|
-
const pendingRequests = ramda_1.sum(ramda_1.values(pendingRequestsPerOrigin));
|
|
12
|
+
const sockets = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.sockets);
|
|
13
|
+
const freeSockets = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.freeSockets);
|
|
14
|
+
const pendingRequests = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.requests);
|
|
19
15
|
return {
|
|
20
16
|
freeSockets,
|
|
21
|
-
freeSocketsPerOrigin,
|
|
22
17
|
pendingRequests,
|
|
23
|
-
pendingRequestsPerOrigin,
|
|
24
18
|
sockets,
|
|
25
|
-
socketsPerOrigin,
|
|
26
19
|
};
|
|
27
20
|
}
|
|
28
|
-
static
|
|
21
|
+
static count(obj) {
|
|
29
22
|
try {
|
|
30
|
-
return
|
|
23
|
+
return Object.values(obj).reduce((acc, val) => acc += val.length, 0);
|
|
31
24
|
}
|
|
32
25
|
catch (_) {
|
|
33
|
-
return
|
|
26
|
+
return 0;
|
|
34
27
|
}
|
|
35
28
|
}
|
|
36
29
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IOContext, TracingContext } from '../typings';
|
|
2
|
-
export declare const prepareHandlerCtx: (header: any, tracingContext: TracingContext) => Pick<IOContext, "host" | "
|
|
2
|
+
export declare const prepareHandlerCtx: (header: any, tracingContext: TracingContext) => Pick<IOContext, "host" | "logger" | "account" | "workspace" | "requestId" | "operationId" | "production" | "platform" | "authToken" | "adminUserAuthToken" | "storeUserAuthToken" | "locale" | "product" | "recorder" | "region" | "userAgent" | "segmentToken" | "sessionToken" | "janusEnv" | "serverTiming" | "eventInfo" | "tenant" | "binding" | "cancellation" | "settings" | "tracer">;
|