whatap 0.4.98 → 0.5.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/lib/conf/config-default.js +8 -3
- package/lib/conf/configure.js +12 -3
- package/lib/conf/log-config-default.js +37 -0
- package/lib/control/control-handler.js +19 -6
- package/lib/core/agent.js +10 -8
- package/lib/core/shimmer.js +98 -0
- package/lib/counter/task/agentinfo.js +1 -1
- package/lib/data/datapack-sender.js +17 -0
- package/lib/data/zipprofile.js +2 -2
- package/lib/logger.js +25 -1
- package/lib/logsink/line-log-util.js +87 -0
- package/lib/logsink/line-log.js +12 -0
- package/lib/logsink/log-sender.js +78 -0
- package/lib/logsink/log-tracer.js +40 -0
- package/lib/logsink/sender-util.js +51 -0
- package/lib/logsink/zip/zip-send.js +177 -0
- package/lib/net/paramdef.js +1 -0
- package/lib/observers/global-observer.js +140 -0
- package/lib/observers/grpc-observer.js +339 -0
- package/lib/observers/http-observer.js +7 -7
- package/lib/observers/process-observer.js +57 -8
- package/lib/observers/redis-observer.js +69 -11
- package/lib/pack/event-pack.js +1 -1
- package/lib/pack/log-sink-pack.js +139 -0
- package/lib/pack/packenum.js +3 -1
- package/lib/pack/zip-pack.js +0 -1
- package/lib/topology/link.js +63 -0
- package/lib/topology/nodeinfo.js +123 -0
- package/lib/topology/status-detector.js +111 -0
- package/lib/util/compare-util.js +131 -0
- package/lib/util/linkedset.js +278 -0
- package/package.json +2 -2
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
const CompareUtil = require('./compare-util');
|
|
2
|
+
|
|
3
|
+
const DEFAULT_CAPACITY = 101;
|
|
4
|
+
const DEFAULT_LOAD_FACTOR = 0.75;
|
|
5
|
+
|
|
6
|
+
function LinkedSetEntry(key, next = null) {
|
|
7
|
+
this.key = key;
|
|
8
|
+
this.next = next;
|
|
9
|
+
this.link_next = null;
|
|
10
|
+
this.link_prev = null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
LinkedSetEntry.prototype.clone = function () {
|
|
14
|
+
return new LinkedSetEntry(this.key, this.next ? this.next.clone() : null);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
LinkedSetEntry.prototype.equals = function (other) {
|
|
18
|
+
return other instanceof LinkedSetEntry && CompareUtil.equals(this.key, other.key);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
LinkedSetEntry.prototype.hashCode = function () {
|
|
22
|
+
return this.key.hashCode();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
LinkedSetEntry.prototype.toString = function () {
|
|
26
|
+
return this.key.toString();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function LinkedSet(initCapacity = DEFAULT_CAPACITY, loadFactor = DEFAULT_LOAD_FACTOR) {
|
|
30
|
+
if (initCapacity < 0) throw new Error(`Capacity Error: ${initCapacity}`);
|
|
31
|
+
if (loadFactor <= 0) throw new Error(`Load Count Error: ${loadFactor}`);
|
|
32
|
+
if (initCapacity === 0) initCapacity = 1;
|
|
33
|
+
|
|
34
|
+
this.loadFactor = loadFactor;
|
|
35
|
+
this.table = new Array(initCapacity).fill(null);
|
|
36
|
+
this.header = new LinkedSetEntry(null);
|
|
37
|
+
this.header.link_next = this.header.link_prev = this.header;
|
|
38
|
+
this.count = 0;
|
|
39
|
+
this.threshold = Math.floor(initCapacity * loadFactor);
|
|
40
|
+
this.max = 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
LinkedSet.prototype.size = function () {
|
|
44
|
+
return this.count;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
LinkedSet.prototype.getArray = function (out) {
|
|
48
|
+
if (out.length !== this.size()) {
|
|
49
|
+
out = new Array(this.size());
|
|
50
|
+
}
|
|
51
|
+
let en = this.elements();
|
|
52
|
+
for (let i = 0; en.hasMoreElements(); i++) {
|
|
53
|
+
out[i] = en.nextElement();
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
LinkedSet.prototype.elements = function () {
|
|
59
|
+
return new LinkedSetEnumerator(this.header);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
LinkedSet.prototype.contains = function (key) {
|
|
63
|
+
if (key === null) return false;
|
|
64
|
+
let index = this.hash(key) % this.table.length;
|
|
65
|
+
for (let e = this.table[index]; e !== null; e = e.next) {
|
|
66
|
+
if (CompareUtil.equals(e.key, key)) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
LinkedSet.prototype.getFirst = function () {
|
|
74
|
+
return this.header.link_next.key;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
LinkedSet.prototype.getLast = function () {
|
|
78
|
+
return this.header.link_prev.key;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
LinkedSet.prototype.hash = function (key) {
|
|
82
|
+
return (key.hashCode() & 0x7FFFFFFF);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
LinkedSet.prototype.rehash = function () {
|
|
86
|
+
let oldCapacity = this.table.length;
|
|
87
|
+
let oldMap = this.table;
|
|
88
|
+
let newCapacity = oldCapacity * 2 + 1;
|
|
89
|
+
let newMap = new Array(newCapacity).fill(null);
|
|
90
|
+
this.threshold = Math.floor(newCapacity * this.loadFactor);
|
|
91
|
+
this.table = newMap;
|
|
92
|
+
for (let i = oldCapacity; i-- > 0;) {
|
|
93
|
+
for (let old = oldMap[i]; old !== null;) {
|
|
94
|
+
let e = old;
|
|
95
|
+
old = old.next;
|
|
96
|
+
let index = this.hash(e.key) % newCapacity;
|
|
97
|
+
e.next = newMap[index];
|
|
98
|
+
newMap[index] = e;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
LinkedSet.prototype.setMax = function (max) {
|
|
104
|
+
this.max = max;
|
|
105
|
+
return this;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
LinkedSet.prototype.put = function (key) {
|
|
109
|
+
return this._put(key, LinkedSet.MODE.LAST);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
LinkedSet.prototype.putLast = function (key) {
|
|
113
|
+
return this._put(key, LinkedSet.MODE.FORCE_LAST);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
LinkedSet.prototype.putFirst = function (key) {
|
|
117
|
+
return this._put(key, LinkedSet.MODE.FORCE_FIRST);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
LinkedSet.prototype._put = function (key, mode) {
|
|
121
|
+
if (key === null) return null;
|
|
122
|
+
let index = this.hash(key) % this.table.length;
|
|
123
|
+
for (let e = this.table[index]; e !== null; e = e.next) {
|
|
124
|
+
if (CompareUtil.equals(e.key, key)) {
|
|
125
|
+
switch (mode) {
|
|
126
|
+
case LinkedSet.MODE.FORCE_FIRST:
|
|
127
|
+
if (this.header.link_next !== e) {
|
|
128
|
+
this.unchain(e);
|
|
129
|
+
this.chain(this.header, this.header.link_next, e);
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
case LinkedSet.MODE.FORCE_LAST:
|
|
133
|
+
if (this.header.link_prev !== e) {
|
|
134
|
+
this.unchain(e);
|
|
135
|
+
this.chain(this.header.link_prev, this.header, e);
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
return e.key;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (this.max > 0) {
|
|
144
|
+
switch (mode) {
|
|
145
|
+
case LinkedSet.MODE.FORCE_FIRST:
|
|
146
|
+
case LinkedSet.MODE.FIRST:
|
|
147
|
+
while (this.count >= this.max) {
|
|
148
|
+
let v = this.header.link_prev.key;
|
|
149
|
+
this.remove(v);
|
|
150
|
+
this.overflowed(v);
|
|
151
|
+
}
|
|
152
|
+
break;
|
|
153
|
+
case LinkedSet.MODE.FORCE_LAST:
|
|
154
|
+
case LinkedSet.MODE.LAST:
|
|
155
|
+
while (this.count >= this.max) {
|
|
156
|
+
let v = this.header.link_next.key;
|
|
157
|
+
this.remove(v);
|
|
158
|
+
this.overflowed(v);
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (this.count >= this.threshold) {
|
|
165
|
+
this.rehash();
|
|
166
|
+
index = this.hash(key) % this.table.length;
|
|
167
|
+
}
|
|
168
|
+
let e = new LinkedSetEntry(key, this.table[index]);
|
|
169
|
+
this.table[index] = e;
|
|
170
|
+
|
|
171
|
+
switch (mode) {
|
|
172
|
+
case LinkedSet.MODE.FORCE_FIRST:
|
|
173
|
+
case LinkedSet.MODE.FIRST:
|
|
174
|
+
this.chain(this.header, this.header.link_next, e);
|
|
175
|
+
break;
|
|
176
|
+
case LinkedSet.MODE.FORCE_LAST:
|
|
177
|
+
case LinkedSet.MODE.LAST:
|
|
178
|
+
this.chain(this.header.link_prev, this.header, e);
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
this.count++;
|
|
183
|
+
return key;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
LinkedSet.prototype.overflowed = function (value) {
|
|
187
|
+
// Custom logic for handling overflow can be added here
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
LinkedSet.prototype.remove = function (key) {
|
|
191
|
+
if (key === null) return false;
|
|
192
|
+
|
|
193
|
+
let index = this.hash(key) % this.table.length;
|
|
194
|
+
for (let e = this.table[index], prev = null; e !== null; prev = e, e = e.next) {
|
|
195
|
+
if (CompareUtil.equals(e.key, key)) {
|
|
196
|
+
if (prev !== null) {
|
|
197
|
+
prev.next = e.next;
|
|
198
|
+
} else {
|
|
199
|
+
this.table[index] = e.next;
|
|
200
|
+
}
|
|
201
|
+
this.count--;
|
|
202
|
+
this.unchain(e);
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return false;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
LinkedSet.prototype.removeFirst = function () {
|
|
210
|
+
if (this.isEmpty()) return false;
|
|
211
|
+
return this.remove(this.header.link_next.key);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
LinkedSet.prototype.removeLast = function () {
|
|
215
|
+
if (this.isEmpty()) return false;
|
|
216
|
+
return this.remove(this.header.link_prev.key);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
LinkedSet.prototype.isEmpty = function () {
|
|
220
|
+
return this.size() === 0;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
LinkedSet.prototype.clear = function () {
|
|
224
|
+
this.table.fill(null);
|
|
225
|
+
this.header.link_next = this.header.link_prev = this.header;
|
|
226
|
+
this.count = 0;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
LinkedSet.prototype.toString = function () {
|
|
230
|
+
let buf = '{';
|
|
231
|
+
let it = this.elements();
|
|
232
|
+
while (it.hasMoreElements()) {
|
|
233
|
+
if (buf.length > 1) buf += ',';
|
|
234
|
+
buf += it.nextElement();
|
|
235
|
+
}
|
|
236
|
+
buf += '}';
|
|
237
|
+
return buf;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
LinkedSet.prototype.chain = function (link_prev, link_next, e) {
|
|
241
|
+
e.link_prev = link_prev;
|
|
242
|
+
e.link_next = link_next;
|
|
243
|
+
link_prev.link_next = e;
|
|
244
|
+
link_next.link_prev = e;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
LinkedSet.prototype.unchain = function (e) {
|
|
248
|
+
e.link_prev.link_next = e.link_next;
|
|
249
|
+
e.link_next.link_prev = e.link_prev;
|
|
250
|
+
e.link_prev = null;
|
|
251
|
+
e.link_next = null;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
function LinkedSetEnumerator(header) {
|
|
255
|
+
this.entry = header.link_next;
|
|
256
|
+
this.header = header;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
LinkedSetEnumerator.prototype.hasMoreElements = function () {
|
|
260
|
+
return this.header !== this.entry && this.entry !== null;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
LinkedSetEnumerator.prototype.nextElement = function () {
|
|
264
|
+
if (this.hasMoreElements()) {
|
|
265
|
+
let e = this.entry;
|
|
266
|
+
this.entry = e.link_next;
|
|
267
|
+
return e.key;
|
|
268
|
+
}
|
|
269
|
+
throw new Error('No more elements');
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
LinkedSet.MODE = {
|
|
273
|
+
LAST: 0,
|
|
274
|
+
FORCE_LAST: 1,
|
|
275
|
+
FORCE_FIRST: 2,
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
module.exports = LinkedSet;
|
package/package.json
CHANGED