@netlify/build 29.4.88-test → 29.4.89-test
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/lib/report/statsd.js +15 -20
- package/lib/time/report.js +10 -7
- package/package.json +2 -3
package/lib/report/statsd.js
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
import { promisify } from 'util';
|
|
2
2
|
import slugify from '@sindresorhus/slugify';
|
|
3
|
-
import
|
|
4
|
-
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
|
|
5
|
-
const pSetTimeout = promisify(setTimeout);
|
|
6
|
-
// See https://github.com/msiebuhr/node-statsd-client/blob/45a93ee4c94ca72f244a40b06cb542d4bd7c3766/lib/EphemeralSocket.js#L81
|
|
7
|
-
const CLOSE_TIMEOUT = 11;
|
|
8
|
-
// The socket creation is delayed until the first packet is sent. In our
|
|
9
|
-
// case, this happens just before `client.close()` is called, which is too
|
|
10
|
-
// late and make it not send anything. We need to manually create it using
|
|
11
|
-
// the internal API.
|
|
3
|
+
import { StatsD } from 'hot-shots';
|
|
12
4
|
export const startClient = async function (host, port) {
|
|
13
|
-
|
|
14
|
-
// @ts-expect-error using internals :D
|
|
15
|
-
await promisify(client._socket._createSocket.bind(client._socket))();
|
|
16
|
-
return client;
|
|
5
|
+
return new StatsD({ host, port, cacheDns: true });
|
|
17
6
|
};
|
|
18
|
-
// UDP packets are buffered and flushed at regular intervals by statsd-client.
|
|
19
|
-
// Closing force flushing all of them.
|
|
20
7
|
export const closeClient = async function (client) {
|
|
21
|
-
client.close();
|
|
22
|
-
// statsd-client does not provide a way of knowing when the socket is done
|
|
23
|
-
// closing, so we need to use the following hack.
|
|
24
|
-
await pSetTimeout(CLOSE_TIMEOUT);
|
|
25
|
-
await pSetTimeout(CLOSE_TIMEOUT);
|
|
8
|
+
await promisify(client.close.bind(client))();
|
|
26
9
|
};
|
|
27
10
|
// Make sure the timer name does not include special characters.
|
|
28
11
|
// For example, the `packageName` of local plugins includes dots.
|
|
29
12
|
export const normalizeTagName = function (name) {
|
|
30
13
|
return slugify(name, { separator: '_' });
|
|
31
14
|
};
|
|
15
|
+
export const formatTags = function (tags) {
|
|
16
|
+
return Object.entries(tags)
|
|
17
|
+
.map(([key, value]) => {
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
return value.map((subValue) => `${key}:${subValue}`);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return `${key}:${value}`;
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
.flat();
|
|
26
|
+
};
|
package/lib/time/report.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
import { closeClient, startClient } from '../report/statsd.js';
|
|
1
|
+
import { closeClient, formatTags, startClient } from '../report/statsd.js';
|
|
2
2
|
import { addAggregatedTimers } from './aggregate.js';
|
|
3
3
|
import { roundTimerToMillisecs } from './measure.js';
|
|
4
4
|
// Record the duration of a build phase, for monitoring.
|
|
5
5
|
// Sends to statsd daemon.
|
|
6
|
-
export const reportTimers = async function ({ timers, statsdOpts: { host, port }, framework }) {
|
|
6
|
+
export const reportTimers = async function ({ timers, statsdOpts: { host, port }, framework, }) {
|
|
7
7
|
if (host === undefined) {
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
10
|
const timersA = addAggregatedTimers(timers);
|
|
11
|
-
await sendTimers({ timers: timersA, host, port, framework });
|
|
11
|
+
await sendTimers({ timers: timersA, statsdOpts: { host, port }, framework });
|
|
12
12
|
};
|
|
13
|
-
const sendTimers = async function ({ timers, host, port, framework }) {
|
|
13
|
+
const sendTimers = async function ({ timers, statsdOpts: { host, port }, framework, }) {
|
|
14
14
|
const client = await startClient(host, port);
|
|
15
15
|
timers.forEach((timer) => {
|
|
16
16
|
sendTimer({ timer, client, framework });
|
|
17
17
|
});
|
|
18
18
|
await closeClient(client);
|
|
19
19
|
};
|
|
20
|
-
const sendTimer = function ({ timer: { metricName, stageTag, parentTag, durationNs, tags }, client, framework }) {
|
|
20
|
+
const sendTimer = function ({ timer: { metricName, stageTag, parentTag, durationNs, tags }, client, framework, }) {
|
|
21
21
|
const durationMs = roundTimerToMillisecs(durationNs);
|
|
22
|
-
const
|
|
23
|
-
|
|
22
|
+
const statsdTags = { stage: stageTag, parent: parentTag, ...tags };
|
|
23
|
+
if (framework != undefined) {
|
|
24
|
+
statsdTags.framework = framework;
|
|
25
|
+
}
|
|
26
|
+
client.distribution(metricName, durationMs, formatTags(statsdTags));
|
|
24
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/build",
|
|
3
|
-
"version": "29.4.
|
|
3
|
+
"version": "29.4.89-test",
|
|
4
4
|
"description": "Netlify build module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/core/main.js",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"figures": "^4.0.0",
|
|
81
81
|
"filter-obj": "^3.0.0",
|
|
82
82
|
"got": "^10.0.0",
|
|
83
|
+
"hot-shots": "9.3.0",
|
|
83
84
|
"indent-string": "^5.0.0",
|
|
84
85
|
"is-plain-obj": "^4.0.0",
|
|
85
86
|
"js-yaml": "^4.0.0",
|
|
@@ -105,7 +106,6 @@
|
|
|
105
106
|
"rfdc": "^1.3.0",
|
|
106
107
|
"safe-json-stringify": "^1.2.0",
|
|
107
108
|
"semver": "^7.0.0",
|
|
108
|
-
"statsd-client": "0.4.7",
|
|
109
109
|
"string-width": "^5.0.0",
|
|
110
110
|
"strip-ansi": "^7.0.0",
|
|
111
111
|
"supports-color": "^9.0.0",
|
|
@@ -120,7 +120,6 @@
|
|
|
120
120
|
"devDependencies": {
|
|
121
121
|
"@netlify/nock-udp": "^3.1.0",
|
|
122
122
|
"@types/node": "^14.18.31",
|
|
123
|
-
"@types/statsd-client": "^0.4.3",
|
|
124
123
|
"atob": "^2.1.2",
|
|
125
124
|
"ava": "^4.0.0",
|
|
126
125
|
"c8": "^7.12.0",
|