@alertlogic/al-collector-js 3.0.12 → 3.0.14

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/al_util.js CHANGED
@@ -13,6 +13,7 @@ const http = require('http');
13
13
  const https = require('https');
14
14
 
15
15
  let MAX_CONNS_PER_SERVICE = 128;
16
+ let MAX_FREE_SOCKETS = 10;
16
17
 
17
18
  /**
18
19
  * @default Refer to https://www.npmjs.com/package/retry
@@ -32,9 +33,12 @@ let DEFAULT_RETRY = {
32
33
  */
33
34
  let DEFAULT_HTTP_HTTPS_AGENT_CONFIG = {
34
35
  keepAlive: true,
35
- maxSockets: MAX_CONNS_PER_SERVICE, // Maximum number of sockets to open
36
+ maxSockets: process.env.MAX_CONNS_PER_SERVICE || MAX_CONNS_PER_SERVICE, // Maximum number of sockets to open
37
+ maxFreeSockets: process.env.MAX_FREE_SOCKETS || MAX_FREE_SOCKETS //sets the maximum number of sockets that will be left open in the free state
36
38
  };
37
39
 
40
+ const httpAgent = new http.Agent(DEFAULT_HTTP_HTTPS_AGENT_CONFIG);
41
+ const httpsAgent = new https.Agent(DEFAULT_HTTP_HTTPS_AGENT_CONFIG);
38
42
 
39
43
  /**
40
44
  * @function Default retry callback.
@@ -79,8 +83,8 @@ class RestServiceClient {
79
83
  url: this._url + path,
80
84
  headers: {},
81
85
  json: true,
82
- httpAgent: new http.Agent(DEFAULT_HTTP_HTTPS_AGENT_CONFIG),
83
- httpsAgent: new https.Agent(DEFAULT_HTTP_HTTPS_AGENT_CONFIG)
86
+ httpAgent: httpAgent,
87
+ httpsAgent: httpsAgent
84
88
  };
85
89
  const options = Object.assign({}, defaultOptions, extra);
86
90
  const defaultHeaders = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alertlogic/al-collector-js",
3
- "version": "3.0.12",
3
+ "version": "3.0.14",
4
4
  "license": "MIT",
5
5
  "description": "Alert Logic Collector Common Library",
6
6
  "repository": {
@@ -26,13 +26,13 @@
26
26
  "nock": "^13.5.4",
27
27
  "nyc": "^17.0.0",
28
28
  "rewire": "^7.0.0",
29
- "sinon": "^18.0.0",
29
+ "sinon": "^18.0.1",
30
30
  "timekeeper": "^2.3.1"
31
31
  },
32
32
  "dependencies": {
33
- "async": "3.2.5",
34
- "axios": "^1.7.2",
35
- "debug": "4.3.5",
33
+ "async": "3.2.6",
34
+ "axios": "^1.7.7",
35
+ "debug": "4.3.7",
36
36
  "lodash.clonedeep": "^4.5.0",
37
37
  "lodash.filter": "^4.6.0",
38
38
  "lodash.remove": "^4.7.0",
package/parse.js CHANGED
@@ -15,6 +15,9 @@
15
15
  * For the ISO8601 timestamp, '2018-12-19T08:18:21.1834546Z'
16
16
  */
17
17
  const ISO8601_MICROSEC_OFFSET = 20;
18
+ const MILLISECONDS_SINCE_EPOCH = 1000000000000;
19
+ const MAX_MILLISECONDS_SINCE_EPOCH = 9999999999999;
20
+ const SECONDS_SINCE_EPOCH = 1000000000;
18
21
 
19
22
  var getProp = function(path, obj, defaultVal = null) {
20
23
  var reduceFun = function(xs, x) {
@@ -31,11 +34,27 @@ var defaultTs = function() {
31
34
  };
32
35
 
33
36
  var parseTs = function (ts) {
34
- var milli = typeof ts === 'number' ? ts : Date.parse(ts);
35
- if (isNaN(milli)) {
37
+ // Handle numeric timestamp (seconds or milliseconds)
38
+ if (typeof ts === 'number') {
39
+ if (ts >= MILLISECONDS_SINCE_EPOCH && ts <= MAX_MILLISECONDS_SINCE_EPOCH) {
40
+ return {
41
+ sec: Math.floor(ts / 1000),
42
+ usec: (ts % 1000) * 1000 || null
43
+ };
44
+ }
45
+ if (ts >= SECONDS_SINCE_EPOCH && ts <= MILLISECONDS_SINCE_EPOCH) {
46
+ return {
47
+ sec: ts,
48
+ usec: null
49
+ };
50
+ }
36
51
  return defaultTs();
37
52
  } else {
38
- var micro = parseTsUsec(ts);
53
+ const milli = Date.parse(ts);
54
+ const micro = parseTsUsec(ts);
55
+ if (isNaN(milli)) {
56
+ return defaultTs();
57
+ }
39
58
  return {
40
59
  sec: Math.floor(milli / 1000),
41
60
  usec: micro
@@ -20,7 +20,7 @@ describe('Common parse functions unit tests.', function() {
20
20
  var clock;
21
21
 
22
22
  before(function() {
23
- clock = sinon.useFakeTimers({now: 1234567890});
23
+ clock = sinon.useFakeTimers({now: 1234567890000});
24
24
  });
25
25
  after(function() {
26
26
  clock.restore();
@@ -132,7 +132,7 @@ describe('Common parse functions unit tests.', function() {
132
132
  it('Wrong timestamp input', function (done) {
133
133
  let parseWire1 = rewire('../parse');
134
134
  var privParseTs = parseWire1.__get__('parseTs');
135
- assert.deepEqual(privParseTs('foo'), { sec: 1234567, usec: null });
135
+ assert.deepEqual(privParseTs('foo'), { sec: 1234567890, usec: null });
136
136
  done();
137
137
  });
138
138
 
@@ -143,6 +143,34 @@ describe('Common parse functions unit tests.', function() {
143
143
  done();
144
144
  });
145
145
 
146
+ it('timestamp input in microseconds 1721143248000000', function (done) {
147
+ let parseWire1 = rewire('../parse');
148
+ var privParseTs = parseWire1.__get__('parseTs');
149
+ assert.deepEqual(privParseTs(1721143248000000), { sec: 1234567890, usec: null });
150
+ done();
151
+ });
152
+
153
+ it('timestamp input in seconds', function (done) {
154
+ let parseWire1 = rewire('../parse');
155
+ var privParseTs = parseWire1.__get__('parseTs');
156
+ assert.deepEqual(privParseTs(1721143248), { sec: 1721143248, usec: null });
157
+ done();
158
+ });
159
+
160
+ it('timestamp input in the string form example 2018-12-19T08:18:21.1834546Z', function (done) {
161
+ let parseWire1 = rewire('../parse');
162
+ var privParseTs = parseWire1.__get__('parseTs');
163
+ assert.deepEqual(privParseTs('2018-12-19T08:18:21.1834546Z'), { sec: 1545207501, usec: 183454 });
164
+ done();
165
+ });
166
+
167
+ it('timestamp input in the string form example 2024-09-17T23:56:26.429270+00:00', function (done) {
168
+ let parseWire1 = rewire('../parse');
169
+ var privParseTs = parseWire1.__get__('parseTs');
170
+ assert.deepEqual(privParseTs('2024-09-17T23:56:26.429270+00:00'), { sec: 1726617386, usec: 429270 });
171
+ done();
172
+ });
173
+
146
174
  it('iteratePropPaths zero key', function(done) {
147
175
  const testPaths = [
148
176
  { path: ['time']},