whatap 0.4.79 → 0.4.80

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.
Files changed (216) hide show
  1. package/.vscode/keep-context.json +3 -3
  2. package/README.md +51 -51
  3. package/bindings/darwin/x64/whatap.node +0 -0
  4. package/bindings/linux/ia32/whatap.node +0 -0
  5. package/bindings/linux/x64/whatap.node +0 -0
  6. package/help.txt +10 -10
  7. package/index.js +8 -8
  8. package/lib/conf/conf-sys-mon.js +100 -100
  9. package/lib/conf/config-default.js +238 -238
  10. package/lib/conf/configure.js +423 -423
  11. package/lib/conf/license.js +41 -41
  12. package/lib/control/cmd-config.js +23 -23
  13. package/lib/control/control-handler.js +344 -344
  14. package/lib/control/packagectr-helper.js +149 -149
  15. package/lib/core/agent.js +329 -328
  16. package/lib/core/interceptor.js +142 -142
  17. package/lib/core/request-agent.js +26 -26
  18. package/lib/counter/counter-manager.js +127 -127
  19. package/lib/counter/meter/meter-activex.js +66 -66
  20. package/lib/counter/meter/meter-httpc.js +57 -57
  21. package/lib/counter/meter/meter-resource.js +9 -9
  22. package/lib/counter/meter/meter-service.js +167 -167
  23. package/lib/counter/meter/meter-socket.io.js +50 -50
  24. package/lib/counter/meter/meter-sql.js +70 -70
  25. package/lib/counter/meter/meter-users.js +57 -57
  26. package/lib/counter/meter.js +183 -183
  27. package/lib/counter/task/activetransaction.js +93 -93
  28. package/lib/counter/task/agentinfo.js +105 -105
  29. package/lib/counter/task/counter-task.js +9 -9
  30. package/lib/counter/task/gcstat.js +34 -34
  31. package/lib/counter/task/heapmem.js +24 -24
  32. package/lib/counter/task/httpc.js +75 -75
  33. package/lib/counter/task/proc-cpu.js +28 -28
  34. package/lib/counter/task/realtimeuser.js +30 -30
  35. package/lib/counter/task/res/systemECSTask.js +54 -54
  36. package/lib/counter/task/res/systemKubeTask.js +52 -52
  37. package/lib/counter/task/res/util/awsEcsClientThread.js +166 -166
  38. package/lib/counter/task/res/util/linuxProcStatUtil.js +13 -13
  39. package/lib/counter/task/res-sys-cpu.js +61 -61
  40. package/lib/counter/task/service.js +201 -201
  41. package/lib/counter/task/socketio.js +29 -29
  42. package/lib/counter/task/sql.js +104 -104
  43. package/lib/counter/task/systemperf.js +42 -42
  44. package/lib/data/datapack-sender.js +256 -256
  45. package/lib/data/dataprofile-agent.js +136 -136
  46. package/lib/data/datatext-agent.js +135 -135
  47. package/lib/data/event-level.js +15 -15
  48. package/lib/data/test.js +48 -48
  49. package/lib/env/constants.js +20 -20
  50. package/lib/kube/kube-client.js +143 -143
  51. package/lib/lang/text-types.js +58 -58
  52. package/lib/logger.js +319 -319
  53. package/lib/net/netflag.js +54 -54
  54. package/lib/net/paramdef.js +40 -40
  55. package/lib/net/receiver.js +65 -65
  56. package/lib/net/security-master.js +182 -173
  57. package/lib/net/sender.js +140 -140
  58. package/lib/net/tcp-return.js +17 -17
  59. package/lib/net/tcp-session.js +285 -285
  60. package/lib/net/tcpreq-client-proxy.js +69 -69
  61. package/lib/net/tcprequest-mgr.js +57 -57
  62. package/lib/observers/cluster-observer.js +21 -21
  63. package/lib/observers/express-observer.js +214 -214
  64. package/lib/observers/file-observer.js +184 -184
  65. package/lib/observers/global-observer.js +30 -30
  66. package/lib/observers/http-observer.js +704 -704
  67. package/lib/observers/maria-observer.js +382 -382
  68. package/lib/observers/memcached-observer.js +55 -55
  69. package/lib/observers/mongo-observer.js +262 -265
  70. package/lib/observers/mongodb-observer.js +197 -197
  71. package/lib/observers/mongoose-observer.js +83 -83
  72. package/lib/observers/mssql-observer.js +205 -205
  73. package/lib/observers/mysql-observer.js +436 -394
  74. package/lib/observers/net-observer.js +72 -72
  75. package/lib/observers/pgsql-observer.js +295 -295
  76. package/lib/observers/process-observer.js +25 -25
  77. package/lib/observers/promise-observer.js +31 -31
  78. package/lib/observers/redis-observer.js +156 -109
  79. package/lib/observers/schedule-observer.js +66 -66
  80. package/lib/observers/socket.io-observer.js +54 -54
  81. package/lib/observers/stream-observer.js +19 -19
  82. package/lib/observers/thrift-observer.js +196 -196
  83. package/lib/pack/activestack-pack.js +54 -54
  84. package/lib/pack/counter-pack.js +649 -649
  85. package/lib/pack/errorsnap-pack.js +68 -68
  86. package/lib/pack/event-pack.js +53 -53
  87. package/lib/pack/hitmap-pack.js +62 -62
  88. package/lib/pack/hitmap-pack1.js +146 -146
  89. package/lib/pack/netstat.js +14 -14
  90. package/lib/pack/pack.js +49 -49
  91. package/lib/pack/packenum.js +60 -60
  92. package/lib/pack/param-pack.js +213 -213
  93. package/lib/pack/profile-pack.js +48 -48
  94. package/lib/pack/realtimeuser-pack.js +40 -40
  95. package/lib/pack/stat-general-pack.js +95 -95
  96. package/lib/pack/staterror-pack.js +119 -119
  97. package/lib/pack/stathttpc-pack.js +66 -66
  98. package/lib/pack/stathttpc-rec.js +78 -78
  99. package/lib/pack/statremote-pack.js +45 -45
  100. package/lib/pack/statservice-pack.js +62 -62
  101. package/lib/pack/statservice-pack1.js +87 -87
  102. package/lib/pack/statservice-rec.js +292 -292
  103. package/lib/pack/statservice-rec_dep.js +151 -151
  104. package/lib/pack/statsql-pack.js +69 -69
  105. package/lib/pack/statsql-rec.js +100 -100
  106. package/lib/pack/statuseragent-pack.js +43 -43
  107. package/lib/pack/tagcount-pack.js +398 -398
  108. package/lib/pack/tagctr.js +14 -14
  109. package/lib/pack/text-pack.js +49 -49
  110. package/lib/pack/time-count.js +25 -25
  111. package/lib/pack/websocket.js +14 -14
  112. package/lib/plugin/plugin-loadermanager.js +56 -56
  113. package/lib/plugin/plugin.js +75 -75
  114. package/lib/requestlog.js +326 -326
  115. package/lib/service/tx-record.js +288 -288
  116. package/lib/stat/stat-error.js +116 -116
  117. package/lib/stat/stat-httpc.js +97 -97
  118. package/lib/stat/stat-remoteip.js +46 -46
  119. package/lib/stat/stat-sql.js +112 -112
  120. package/lib/stat/stat-tranx.js +57 -57
  121. package/lib/stat/stat-tx-caller.js +159 -159
  122. package/lib/stat/stat-tx-domain.js +110 -110
  123. package/lib/stat/stat-tx-referer.js +111 -111
  124. package/lib/stat/stat-useragent.js +48 -48
  125. package/lib/stat/timingsender.js +72 -72
  126. package/lib/step/activestack-step.js +37 -37
  127. package/lib/step/dbc-step.js +35 -35
  128. package/lib/step/http-stepx.js +66 -66
  129. package/lib/step/message-step.js +39 -39
  130. package/lib/step/method-stepx.js +46 -46
  131. package/lib/step/resultset-step.js +39 -39
  132. package/lib/step/securemsg-step.js +43 -43
  133. package/lib/step/socket-step.js +46 -46
  134. package/lib/step/sql-stepx.js +67 -67
  135. package/lib/step/sqlxtype.js +15 -15
  136. package/lib/step/step.js +65 -65
  137. package/lib/step/stepenum.js +53 -53
  138. package/lib/trace/local-context.js +13 -13
  139. package/lib/trace/parsed-sql.js +13 -13
  140. package/lib/trace/profile-collector.js +70 -70
  141. package/lib/trace/serviceurl-pattern-detector.js +117 -117
  142. package/lib/trace/trace-context-manager.js +195 -195
  143. package/lib/trace/trace-context.js +134 -134
  144. package/lib/util/anylist.js +102 -102
  145. package/lib/util/array-util.js +100 -100
  146. package/lib/util/bitutil.js +27 -27
  147. package/lib/util/cardinality/hyperloglog.js +105 -105
  148. package/lib/util/cardinality/murmurhash.js +31 -31
  149. package/lib/util/cardinality/registerset.js +74 -74
  150. package/lib/util/config-util.js +17 -17
  151. package/lib/util/cypher.js +89 -89
  152. package/lib/util/datetimehelper.js +237 -229
  153. package/lib/util/dateutil.js +110 -106
  154. package/lib/util/errordata.js +20 -20
  155. package/lib/util/escape-literal-sql.js +342 -342
  156. package/lib/util/hashutil2.js +126 -126
  157. package/lib/util/hexa32.js +57 -57
  158. package/lib/util/index.js +78 -78
  159. package/lib/util/intint-map.js +47 -47
  160. package/lib/util/intkey-linkedmap.js +26 -26
  161. package/lib/util/intkey-map.js +25 -25
  162. package/lib/util/intset.js +82 -82
  163. package/lib/util/iputil.js +119 -119
  164. package/lib/util/iputil_x.js +526 -526
  165. package/lib/util/keygen.js +17 -17
  166. package/lib/util/kube-util.js +72 -72
  167. package/lib/util/longint-linkedmap.js +35 -35
  168. package/lib/util/longkey-linkedmap.js +25 -25
  169. package/lib/util/longlong-linkedmap.js +37 -37
  170. package/lib/util/nodeutil.js +67 -67
  171. package/lib/util/oidutil.js +96 -93
  172. package/lib/util/paramsecurity.js +78 -78
  173. package/lib/util/pathtree.js +172 -172
  174. package/lib/util/pre-process.js +13 -13
  175. package/lib/util/process-seq.js +165 -165
  176. package/lib/util/property-util.js +35 -35
  177. package/lib/util/request-queue.js +42 -42
  178. package/lib/util/requestdouble-queue.js +72 -72
  179. package/lib/util/resourceprofile.js +156 -156
  180. package/lib/util/seedrandom.js +242 -242
  181. package/lib/util/stop-watch.js +29 -29
  182. package/lib/util/string-util.js +9 -9
  183. package/lib/util/stringkey-linkedmap.js +28 -28
  184. package/lib/util/stringnum-linkedmap.js +31 -31
  185. package/lib/util/stringset.js +65 -65
  186. package/lib/util/system-util.js +9 -9
  187. package/lib/util/userid-util.js +57 -57
  188. package/lib/util/utils.js +67 -67
  189. package/lib/value/blob-value.js +61 -61
  190. package/lib/value/boolean-value.js +51 -51
  191. package/lib/value/decimal-value.js +71 -71
  192. package/lib/value/double-summary.js +105 -105
  193. package/lib/value/double-value.js +50 -50
  194. package/lib/value/float-array.js +59 -59
  195. package/lib/value/float-value.js +64 -64
  196. package/lib/value/int-array.js +59 -59
  197. package/lib/value/int-map-value.js +151 -151
  198. package/lib/value/int-value.js +64 -64
  199. package/lib/value/ip4-value.js +83 -83
  200. package/lib/value/list-value.js +136 -136
  201. package/lib/value/long-array.js +59 -59
  202. package/lib/value/long-summary.js +105 -105
  203. package/lib/value/map-value.js +175 -175
  204. package/lib/value/metric-value.js +157 -157
  205. package/lib/value/null-value.js +42 -42
  206. package/lib/value/number-value.js +34 -34
  207. package/lib/value/summary-value.js +29 -29
  208. package/lib/value/text-array.js +117 -117
  209. package/lib/value/text-value.js +59 -59
  210. package/lib/value/texthash-value.js +49 -49
  211. package/lib/value/value.js +14 -14
  212. package/lib/value/valueenum.js +99 -99
  213. package/logs/whatap-20230906.log +54 -0
  214. package/package.json +28 -28
  215. package/whatap.conf +1 -1
  216. package/logs/whatap-20230616.log +0 -13
@@ -1,424 +1,424 @@
1
- /**
2
- * Copyright 2016 the WHATAP project authors. All rights reserved.
3
- * Use of this source code is governed by a license that
4
- * can be found in the LICENSE file.
5
- */
6
-
7
- var WHATAP_CONF = process.env.WHATAP_CONF || 'whatap';
8
-
9
- var fs = require('fs'),
10
- path = require('path'),
11
- EventEmitter = require('events').EventEmitter;
12
-
13
- var DataInputX = require('./../io/data-inputx'),
14
- secu = require('./../net/security-master'),
15
- NodeUtil = require('./../util/nodeutil'),
16
- HashUtil = require('./../util/hashutil'),
17
- StringUtil = require('./../util/string-util'),
18
- Cypher = require('./../util/cypher'),
19
- ConfigDefault = require("./config-default"),
20
- ConfSysMon = require('./conf-sys-mon'),
21
- MapValue = require('./../value/map-value'),
22
- IntKeyLinkedMap = require('./../util/intkey-linkedmap'),
23
- lastModifiedTime = 0;
24
-
25
- //Object.assign(ConfigDefault, require('./config-default'));
26
- var Configuration = function() {
27
- var self = this;
28
- EventEmitter.call(this);
29
- this.apply(ConfigDefault);
30
-
31
- this.inx = 0;
32
- this._customProps = {};
33
- this._propertyFilePath = undefined;
34
- this._log_ignore_set = new Set();
35
- this.socketChk = new IntKeyLinkedMap(500,1).setMax(500);
36
- // this._profile_position_sql = new Set();
37
- // this._profile_position_httpc = new Set();
38
- // this._profile_position_method = new Set();
39
-
40
- setInterval(function(){
41
- self.reload();
42
- }, 10000);
43
- };
44
-
45
- Configuration.prototype = new EventEmitter();
46
- Configuration.prototype.constructor = Configuration;
47
- Configuration.prototype.init = function(userOpt, cb) {
48
- this.reload(cb);
49
- };
50
-
51
- var applyEmptyConf=false;
52
- Configuration.prototype.reload = function(cb) {
53
- var self = this;
54
-
55
- this.getPropertyFilePath( function(err, propertyFile) {
56
- if(err) {
57
- if(applyEmptyConf==false){
58
- applyEmptyConf=true;
59
- require('../logger').print("WHATAP-001", "No Configure file '"+propertyFile+"'", true);
60
-
61
- var defKeys = Object.keys(ConfigDefault);
62
- var p = {};
63
- defKeys.forEach(function (key) {
64
- if(ConfigDefault[key]) {
65
- p[key] = ConfigDefault[key];
66
- }
67
- });
68
- if(process.env.WHATAP_SERVER_HOST){
69
- p['whatap.server.host']=process.env.WHATAP_SERVER_HOST;
70
- }
71
- if(process.env.WHATAP_LICENSE){
72
- p['license']=process.env.WHATAP_LICENSE;
73
- }
74
- self.apply(p);
75
- updatePrivate(self);
76
- if(cb) cb();
77
- }
78
- } else {
79
- if(propertyFile == null) { return; }
80
- applyEmptyConf=false;
81
- var propStats = fs.lstatSync(propertyFile);
82
- if(lastModifiedTime >= propStats.mtime) { return; }
83
- lastModifiedTime = propStats.mtime;
84
-
85
- var props = fs.readFileSync(propertyFile, 'utf8');
86
- if(props.constructor == String){
87
- var rowProps = props.split('\n');
88
- var oldCustom = self._customProps || {};
89
- self._customProps = {};
90
- for(var i = 0 ; i < rowProps.length; i++) {
91
- var p = rowProps[i].split('=');
92
- if(p.length > 1) {
93
-
94
- var boolValue = toBoolean(p[1]);
95
- if(boolValue != null) {
96
- self._customProps[p[0]] = toBoolean(p[1]);
97
- continue;
98
- }
99
-
100
- var numberValue = toNumber(p[1]);
101
- if(numberValue != null) {
102
- self._customProps[p[0]] = numberValue;
103
- continue;
104
- }
105
- self._customProps[p[0]] = p[1];
106
- }
107
- }
108
-
109
- var oldKeys = Object.keys(oldCustom);
110
- var newKeys = Object.keys(self._customProps);
111
-
112
- oldKeys.forEach(function (key) {
113
- if(newKeys.indexOf(key) < 0) {
114
- if(ConfigDefault[key] != null) {
115
- self[key] = ConfigDefault[key];
116
- } else {
117
- delete self[key];
118
- }
119
- }
120
- });
121
- require('../logger').print("WHATAP-203", "Config file reloaded", false);
122
- }
123
-
124
- self.apply( self._customProps );
125
- updatePrivate(self);
126
- if(cb) cb();
127
- }
128
- });
129
-
130
- };
131
- function updatePrivate(self){
132
- if(self.trace_user_using_ip) {
133
- self.trace_user_using_type = 1;
134
- } else {
135
- self.trace_user_using_type = 3;
136
- }
137
-
138
- self._log_ignore_set = self.getStringSet('log_ignore_set', null, ',');
139
- // self._profile_position_sql = self.getStringSet('profile_position_sql', null, ',');
140
- // self._profile_position_httpc = self.getStringSet('profile_position_httpc', null, ',');
141
- // self._profile_position_method = self.getStringSet('profile_position_method', null, ',');
142
- }
143
-
144
- Configuration.prototype.apply = function(properties) {
145
- for(var k in properties) {
146
- this.setProperty(k, properties[k]);
147
- }
148
-
149
- var set = this.getStringSet("whatap.server.host", "127.0.0.1", "/");
150
- var ips = Array.from(set);
151
- this.whatap_server_host = ips;
152
-
153
- if( this.getProperty('whatap_micro_enabled') === true){
154
- this.kubeNodeName(properties);
155
- }
156
-
157
- ConfSysMon.apply(properties);
158
- };
159
-
160
- Configuration.prototype.kubeNodeName = function(properties){
161
- var POD_NAME = process.env['POD_NAME'] || process.env['PODNAME'];
162
- this.OKIND_NAME = this.getProperty('whatap.okind');
163
- if(!this.OKIND_NAME || this.OKIND_NAME.length < 1){
164
- this.OKIND_NAME = POD_NAME ? cutOut(POD_NAME, '-') : '';
165
- this.setProperty('whatap.okind', this.OKIND_NAME);
166
- }
167
- this.OKIND = StringUtil.isEmpty(this.OKIND_NAME) ? 0 : HashUtil.hash(this.OKIND_NAME);
168
- secu.OKIND = this.OKIND;
169
- secu.OKIND_NAME = this.OKIND_NAME;
170
-
171
- this.ONODE_NAME = this.getProperty("whatap.onode");
172
- if (this.ONODE_NAME === undefined) {
173
- this.ONODE_NAME = process.env['NODE_NAME'];
174
- }
175
- if (this.ONODE_NAME === undefined) {
176
- this.ONODE_NAME = process.env["NODE_IP"];
177
- }
178
- this.ONODE = StringUtil.isEmpty(this.ONODE_NAME) ? 0 : HashUtil.hash(this.ONODE_NAME);
179
- secu.ONODE = this.ONODE;
180
- secu.ONODE_NAME = this.ONODE_NAME;
181
- }
182
-
183
- Configuration.prototype.getPropertyFilePath = function(cb) {
184
- var self = this;
185
- if(self._propertyFilePath) {
186
- if(cb) {
187
- cb(null, self._propertyFilePath);
188
- }
189
- }
190
-
191
- var confDir= '.';
192
- if(process.env.WHATAP_CONF_DIR){
193
- confDir= process.env.WHATAP_CONF_DIR;
194
- }else{
195
- confDir =this.getProperty('app.root', process.cwd());
196
- }
197
-
198
- var default_conf = WHATAP_CONF+".conf";
199
- var configFile = this.getProperty('whatap.config', default_conf);
200
-
201
- var confFullPathFile=path.join(confDir, configFile);
202
- fs.access(confFullPathFile, function (err) {
203
- if (err) {
204
- self._propertyFilePath = null;
205
- if (cb) cb(err, confFullPathFile);
206
- } else {
207
- self._propertyFilePath = confFullPathFile;
208
- if (cb) cb(null, confFullPathFile);
209
- }
210
- });
211
- };
212
- Configuration.prototype.getCustomProps = function(){
213
- var props = {};
214
- for(var k in this._customProps){
215
- props[k] = this._customProps[k];
216
- }
217
- return props;
218
- };
219
- Configuration.prototype.saveProperty = function(keyValues){
220
- var self = this;
221
- this.getPropertyFilePath(function(err, propertyFile){
222
- for(var k in keyValues){
223
- var v = keyValues[k];
224
- if(!v || v.length < 1){
225
- delete self._customProps[k];
226
- }else{
227
- self._customProps[k] = v;
228
- }
229
- }
230
-
231
- if(!self._customProps['whatap.server.host'] && process.env.WHATAP_SERVER_HOST){
232
- self._customProps['whatap.server.host']=process.env.WHATAP_SERVER_HOST;
233
- }
234
- if(!self._customProps['license'] && process.env.WHATAP_LICENSE){
235
- self._customProps['license']=process.env.WHATAP_LICENSE;
236
- }
237
- var writeContents = '';
238
- for(var k in self._customProps){
239
- var v = self._customProps[k];
240
- writeContents += k +'=' + v +'\n';
241
- }
242
- fs.writeFile(propertyFile, writeContents , 'utf-8', function(err, data){
243
- if(err){
244
- return console.error(err);
245
- }
246
- })
247
- for(var k in self._customProps){
248
- var v = self._customProps[k];
249
- self.setProperty(k, v);
250
- }
251
- });
252
- };
253
- Configuration.prototype.setProperty = function(key, value) {
254
- if(this[key] == value) { return; }
255
- this[key] = value;
256
- this.emit(key, value);
257
- };
258
- Configuration.prototype.getProperty = function(key, defaultValue) {
259
- if(!this[key]){
260
- return defaultValue;
261
- } else{
262
- return this[key];
263
- }
264
- };
265
-
266
- Configuration.prototype.getWhatapServerHost = function () {
267
- var _len = this.whatap_server_host.length;
268
- switch (_len) {
269
- case 0:
270
- return '127.0.0.1';
271
- case 1:
272
- return this.whatap_server_host[0];
273
- }
274
- var _inx = this.inx;
275
- var out = this.whatap_server_host[_inx];
276
- this.inx = (_inx + 1) % _len;
277
- return out;
278
- };
279
- Configuration.prototype.updateNetCypherKey = function(data /* byte[] */) {
280
- try{
281
- var data = secu.cypher.decrypt(data);
282
- var inD = new DataInputX(data);
283
- this.TRANSFER_KEY = inD.readInt();
284
- this.SECURE_KEY = inD.readBlob();
285
- this.HIDE_KEY = inD.readInt();
286
- this.cypher = new Cypher(this.SECURE_KEY, this.HIDE_KEY);
287
- } catch(e) {
288
-
289
- }
290
- };
291
- Configuration.prototype.readCustomConfig = function(){
292
- var props = this.getCustomProps();
293
- var mv = new MapValue();
294
- for(var k in props){
295
- mv.putString(k, props[k]);
296
- }
297
- return mv;
298
- };
299
- Configuration.prototype.isIgnoreLog = function (id) {
300
- return this._log_ignore_set.has(id);
301
- };
302
- Configuration.prototype.setSocketChk = function (socket) {
303
- if(socket.whatapId == undefined) {
304
- socket.whatapId = (new Date()).getTime().toString(36) + Math.random().toString(36).slice(2);
305
- //require('../logger').print("WHATAP-TEST", 'Socket whatapId : ' + socket.whatapId, false);
306
- }
307
- //else {
308
- // require('../logger').print("WHATAP-TEST", '[REUSE] Socket whatapId : ' + socket.whatapId, false);
309
- //}
310
- if(this.socketChk.get(socket.whatapId) == null) {
311
- this.socketChk.put(socket.whatapId , socket.whatapId);
312
- return false;
313
- } else return true;
314
- }
315
- Configuration.prototype.getStringSet = function (key, defaultValue, deli) {
316
- var set = new Set();
317
- var value = this[key] || defaultValue;
318
- if(value == null) { return set; }
319
-
320
- var arr = value.split(deli);
321
- for(var i=0; i<arr.length; i++) {
322
- var x = arr[i].trim();
323
- if(x)set.add(replaceCarriageReturns(x));
324
- }
325
- return set;
326
- };
327
-
328
- function toNumber(value) {
329
- if(typeof value == 'number') {
330
- return value;
331
- }
332
-
333
- var number = Number(value);
334
- if(isNaN(number)) {
335
- return null;
336
- } else {
337
- return number;
338
- }
339
- }
340
- function toBoolean(value) {
341
- if(typeof value == 'boolean') {
342
- return value;
343
- }
344
-
345
- if(typeof value == 'string') {
346
- if(value == 'true') {
347
- return true;
348
- } else if(value == 'false') {
349
- return false;
350
- }
351
- }
352
- return null;
353
- }
354
-
355
- function replaceCarriageReturns(str) {
356
- let regxp = /\r/g;
357
- str = str.replace(regxp, "");
358
- return str;
359
- }
360
-
361
- function cutOut(val, delim) {
362
- if (val === undefined)
363
- return val;
364
- try {
365
- var x = val.lastIndexOf(delim);
366
- if (x <= 0)
367
- return;
368
- return val.substring(0, x);
369
- } catch (e) {
370
- return val;
371
- }
372
- }
373
-
374
- const conf = new Configuration();
375
-
376
- conf.on('trace_ignore_url_set', function(props){
377
- if(!props || props.constructor !== String){
378
- return;
379
- }
380
-
381
- var ignoreUrls = props.split(',');
382
- conf._trace_ignore_url_set = {};
383
- for(var i = 0; i < ignoreUrls.length; i++){
384
- var ignoreUrl = ignoreUrls[i];
385
- var serviceHash = HashUtil.hashFromString(ignoreUrl);
386
- conf._trace_ignore_url_set[serviceHash] = true;
387
- }
388
- });
389
-
390
- conf.on('trace_ignore_url_prefix', function(props){
391
- if(props && props.constructor === String && props.length > 0 ){
392
- conf._is_trace_ignore_url_prefix = true;
393
- }else{
394
- conf._is_trace_ignore_url_prefix = false;
395
- }
396
- });
397
-
398
- conf.on('trace_ignore_err_cls_contains', function(props){
399
- if(props && props.constructor === String && props.length > 0 ){
400
- conf._is_trace_ignore_err_cls_contains = true;
401
- }else{
402
- conf._is_trace_ignore_err_cls_contains = false;
403
- }
404
- });
405
-
406
- conf.on('trace_ignore_err_msg_contains', function(props){
407
- if(props && props.constructor === String && props.length > 0 ){
408
- conf._is_trace_ignore_err_msg_contains = true;
409
- }else{
410
- conf._is_trace_ignore_err_msg_contains = false;
411
- }
412
- });
413
-
414
-
415
- conf.on('mtrace_spec', function(props){
416
- if (!props || props.length == 0) {
417
- conf.mtrace_spec_hash = 0;
418
- } else {
419
- props = props.replace(',', '_');
420
- conf.mtrace_spec_hash = HashUtil.hash(props);
421
- }
422
- })
423
-
1
+ /**
2
+ * Copyright 2016 the WHATAP project authors. All rights reserved.
3
+ * Use of this source code is governed by a license that
4
+ * can be found in the LICENSE file.
5
+ */
6
+
7
+ var WHATAP_CONF = process.env.WHATAP_CONF || 'whatap';
8
+
9
+ var fs = require('fs'),
10
+ path = require('path'),
11
+ EventEmitter = require('events').EventEmitter;
12
+
13
+ var DataInputX = require('./../io/data-inputx'),
14
+ secu = require('./../net/security-master'),
15
+ NodeUtil = require('./../util/nodeutil'),
16
+ HashUtil = require('./../util/hashutil'),
17
+ StringUtil = require('./../util/string-util'),
18
+ Cypher = require('./../util/cypher'),
19
+ ConfigDefault = require("./config-default"),
20
+ ConfSysMon = require('./conf-sys-mon'),
21
+ MapValue = require('./../value/map-value'),
22
+ IntKeyLinkedMap = require('./../util/intkey-linkedmap'),
23
+ lastModifiedTime = 0;
24
+
25
+ //Object.assign(ConfigDefault, require('./config-default'));
26
+ var Configuration = function() {
27
+ var self = this;
28
+ EventEmitter.call(this);
29
+ this.apply(ConfigDefault);
30
+
31
+ this.inx = 0;
32
+ this._customProps = {};
33
+ this._propertyFilePath = undefined;
34
+ this._log_ignore_set = new Set();
35
+ this.socketChk = new IntKeyLinkedMap(500,1).setMax(500);
36
+ // this._profile_position_sql = new Set();
37
+ // this._profile_position_httpc = new Set();
38
+ // this._profile_position_method = new Set();
39
+
40
+ setInterval(function(){
41
+ self.reload();
42
+ }, 10000);
43
+ };
44
+
45
+ Configuration.prototype = new EventEmitter();
46
+ Configuration.prototype.constructor = Configuration;
47
+ Configuration.prototype.init = function(userOpt, cb) {
48
+ this.reload(cb);
49
+ };
50
+
51
+ var applyEmptyConf=false;
52
+ Configuration.prototype.reload = function(cb) {
53
+ var self = this;
54
+
55
+ this.getPropertyFilePath( function(err, propertyFile) {
56
+ if(err) {
57
+ if(applyEmptyConf==false){
58
+ applyEmptyConf=true;
59
+ require('../logger').print("WHATAP-001", "No Configure file '"+propertyFile+"'", true);
60
+
61
+ var defKeys = Object.keys(ConfigDefault);
62
+ var p = {};
63
+ defKeys.forEach(function (key) {
64
+ if(ConfigDefault[key]) {
65
+ p[key] = ConfigDefault[key];
66
+ }
67
+ });
68
+ if(process.env.WHATAP_SERVER_HOST){
69
+ p['whatap.server.host']=process.env.WHATAP_SERVER_HOST;
70
+ }
71
+ if(process.env.WHATAP_LICENSE){
72
+ p['license']=process.env.WHATAP_LICENSE;
73
+ }
74
+ self.apply(p);
75
+ updatePrivate(self);
76
+ if(cb) cb();
77
+ }
78
+ } else {
79
+ if(propertyFile == null) { return; }
80
+ applyEmptyConf=false;
81
+ var propStats = fs.lstatSync(propertyFile);
82
+ if(lastModifiedTime >= propStats.mtime) { return; }
83
+ lastModifiedTime = propStats.mtime;
84
+
85
+ var props = fs.readFileSync(propertyFile, 'utf8');
86
+ if(props.constructor == String){
87
+ var rowProps = props.split('\n');
88
+ var oldCustom = self._customProps || {};
89
+ self._customProps = {};
90
+ for(var i = 0 ; i < rowProps.length; i++) {
91
+ var p = rowProps[i].split('=');
92
+ if(p.length > 1) {
93
+
94
+ var boolValue = toBoolean(p[1]);
95
+ if(boolValue != null) {
96
+ self._customProps[p[0]] = toBoolean(p[1]);
97
+ continue;
98
+ }
99
+
100
+ var numberValue = toNumber(p[1]);
101
+ if(numberValue != null) {
102
+ self._customProps[p[0]] = numberValue;
103
+ continue;
104
+ }
105
+ self._customProps[p[0]] = p[1];
106
+ }
107
+ }
108
+
109
+ var oldKeys = Object.keys(oldCustom);
110
+ var newKeys = Object.keys(self._customProps);
111
+
112
+ oldKeys.forEach(function (key) {
113
+ if(newKeys.indexOf(key) < 0) {
114
+ if(ConfigDefault[key] != null) {
115
+ self[key] = ConfigDefault[key];
116
+ } else {
117
+ delete self[key];
118
+ }
119
+ }
120
+ });
121
+ require('../logger').print("WHATAP-203", "Config file reloaded", false);
122
+ }
123
+
124
+ self.apply( self._customProps );
125
+ updatePrivate(self);
126
+ if(cb) cb();
127
+ }
128
+ });
129
+
130
+ };
131
+ function updatePrivate(self){
132
+ if(self.trace_user_using_ip) {
133
+ self.trace_user_using_type = 1;
134
+ } else {
135
+ self.trace_user_using_type = 3;
136
+ }
137
+
138
+ self._log_ignore_set = self.getStringSet('log_ignore_set', null, ',');
139
+ // self._profile_position_sql = self.getStringSet('profile_position_sql', null, ',');
140
+ // self._profile_position_httpc = self.getStringSet('profile_position_httpc', null, ',');
141
+ // self._profile_position_method = self.getStringSet('profile_position_method', null, ',');
142
+ }
143
+
144
+ Configuration.prototype.apply = function(properties) {
145
+ for(var k in properties) {
146
+ this.setProperty(k, properties[k]);
147
+ }
148
+
149
+ var set = this.getStringSet("whatap.server.host", "127.0.0.1", "/");
150
+ var ips = Array.from(set);
151
+ this.whatap_server_host = ips;
152
+
153
+ if( this.getProperty('whatap_micro_enabled') === true){
154
+ this.kubeNodeName(properties);
155
+ }
156
+
157
+ ConfSysMon.apply(properties);
158
+ };
159
+
160
+ Configuration.prototype.kubeNodeName = function(properties){
161
+ var POD_NAME = process.env['POD_NAME'] || process.env['PODNAME'];
162
+ this.OKIND_NAME = this.getProperty('whatap.okind');
163
+ if(!this.OKIND_NAME || this.OKIND_NAME.length < 1){
164
+ this.OKIND_NAME = POD_NAME ? cutOut(POD_NAME, '-') : '';
165
+ this.setProperty('whatap.okind', this.OKIND_NAME);
166
+ }
167
+ this.OKIND = StringUtil.isEmpty(this.OKIND_NAME) ? 0 : HashUtil.hash(this.OKIND_NAME);
168
+ secu.OKIND = this.OKIND;
169
+ secu.OKIND_NAME = this.OKIND_NAME;
170
+
171
+ this.ONODE_NAME = this.getProperty("whatap.onode");
172
+ if (!this.ONODE_NAME || (this.ONODE_NAME && this.ONODE_NAME.length < 1)) {
173
+ this.ONODE_NAME = process.env['NODE_NAME'];
174
+ }
175
+ if (!this.ONODE_NAME || (this.ONODE_NAME && this.ONODE_NAME.length < 1)) {
176
+ this.ONODE_NAME = process.env["NODE_IP"];
177
+ }
178
+ this.ONODE = StringUtil.isEmpty(this.ONODE_NAME) ? 0 : HashUtil.hash(this.ONODE_NAME);
179
+ secu.ONODE = this.ONODE;
180
+ secu.ONODE_NAME = this.ONODE_NAME;
181
+ }
182
+
183
+ Configuration.prototype.getPropertyFilePath = function(cb) {
184
+ var self = this;
185
+ if(self._propertyFilePath) {
186
+ if(cb) {
187
+ cb(null, self._propertyFilePath);
188
+ }
189
+ }
190
+
191
+ var confDir= '.';
192
+ if(process.env.WHATAP_CONF_DIR){
193
+ confDir= process.env.WHATAP_CONF_DIR;
194
+ }else{
195
+ confDir =this.getProperty('app.root', process.cwd());
196
+ }
197
+
198
+ var default_conf = WHATAP_CONF+".conf";
199
+ var configFile = this.getProperty('whatap.config', default_conf);
200
+
201
+ var confFullPathFile=path.join(confDir, configFile);
202
+ fs.access(confFullPathFile, function (err) {
203
+ if (err) {
204
+ self._propertyFilePath = null;
205
+ if (cb) cb(err, confFullPathFile);
206
+ } else {
207
+ self._propertyFilePath = confFullPathFile;
208
+ if (cb) cb(null, confFullPathFile);
209
+ }
210
+ });
211
+ };
212
+ Configuration.prototype.getCustomProps = function(){
213
+ var props = {};
214
+ for(var k in this._customProps){
215
+ props[k] = this._customProps[k];
216
+ }
217
+ return props;
218
+ };
219
+ Configuration.prototype.saveProperty = function(keyValues){
220
+ var self = this;
221
+ this.getPropertyFilePath(function(err, propertyFile){
222
+ for(var k in keyValues){
223
+ var v = keyValues[k];
224
+ if(!v || v.length < 1){
225
+ delete self._customProps[k];
226
+ }else{
227
+ self._customProps[k] = v;
228
+ }
229
+ }
230
+
231
+ if(!self._customProps['whatap.server.host'] && process.env.WHATAP_SERVER_HOST){
232
+ self._customProps['whatap.server.host']=process.env.WHATAP_SERVER_HOST;
233
+ }
234
+ if(!self._customProps['license'] && process.env.WHATAP_LICENSE){
235
+ self._customProps['license']=process.env.WHATAP_LICENSE;
236
+ }
237
+ var writeContents = '';
238
+ for(var k in self._customProps){
239
+ var v = self._customProps[k];
240
+ writeContents += k +'=' + v +'\n';
241
+ }
242
+ fs.writeFile(propertyFile, writeContents , 'utf-8', function(err, data){
243
+ if(err){
244
+ return console.error(err);
245
+ }
246
+ })
247
+ for(var k in self._customProps){
248
+ var v = self._customProps[k];
249
+ self.setProperty(k, v);
250
+ }
251
+ });
252
+ };
253
+ Configuration.prototype.setProperty = function(key, value) {
254
+ if(this[key] == value) { return; }
255
+ this[key] = value;
256
+ this.emit(key, value);
257
+ };
258
+ Configuration.prototype.getProperty = function(key, defaultValue) {
259
+ if(!this[key]){
260
+ return defaultValue;
261
+ } else{
262
+ return this[key];
263
+ }
264
+ };
265
+
266
+ Configuration.prototype.getWhatapServerHost = function () {
267
+ var _len = this.whatap_server_host.length;
268
+ switch (_len) {
269
+ case 0:
270
+ return '127.0.0.1';
271
+ case 1:
272
+ return this.whatap_server_host[0];
273
+ }
274
+ var _inx = this.inx;
275
+ var out = this.whatap_server_host[_inx];
276
+ this.inx = (_inx + 1) % _len;
277
+ return out;
278
+ };
279
+ Configuration.prototype.updateNetCypherKey = function(data /* byte[] */) {
280
+ try{
281
+ var data = secu.cypher.decrypt(data);
282
+ var inD = new DataInputX(data);
283
+ this.TRANSFER_KEY = inD.readInt();
284
+ this.SECURE_KEY = inD.readBlob();
285
+ this.HIDE_KEY = inD.readInt();
286
+ this.cypher = new Cypher(this.SECURE_KEY, this.HIDE_KEY);
287
+ } catch(e) {
288
+
289
+ }
290
+ };
291
+ Configuration.prototype.readCustomConfig = function(){
292
+ var props = this.getCustomProps();
293
+ var mv = new MapValue();
294
+ for(var k in props){
295
+ mv.putString(k, props[k]);
296
+ }
297
+ return mv;
298
+ };
299
+ Configuration.prototype.isIgnoreLog = function (id) {
300
+ return this._log_ignore_set.has(id);
301
+ };
302
+ Configuration.prototype.setSocketChk = function (socket) {
303
+ if(socket.whatapId == undefined) {
304
+ socket.whatapId = (new Date()).getTime().toString(36) + Math.random().toString(36).slice(2);
305
+ //require('../logger').print("WHATAP-TEST", 'Socket whatapId : ' + socket.whatapId, false);
306
+ }
307
+ //else {
308
+ // require('../logger').print("WHATAP-TEST", '[REUSE] Socket whatapId : ' + socket.whatapId, false);
309
+ //}
310
+ if(this.socketChk.get(socket.whatapId) == null) {
311
+ this.socketChk.put(socket.whatapId , socket.whatapId);
312
+ return false;
313
+ } else return true;
314
+ }
315
+ Configuration.prototype.getStringSet = function (key, defaultValue, deli) {
316
+ var set = new Set();
317
+ var value = this[key] || defaultValue;
318
+ if(value == null) { return set; }
319
+
320
+ var arr = value.split(deli);
321
+ for(var i=0; i<arr.length; i++) {
322
+ var x = arr[i].trim();
323
+ if(x)set.add(replaceCarriageReturns(x));
324
+ }
325
+ return set;
326
+ };
327
+
328
+ function toNumber(value) {
329
+ if(typeof value == 'number') {
330
+ return value;
331
+ }
332
+
333
+ var number = Number(value);
334
+ if(isNaN(number)) {
335
+ return null;
336
+ } else {
337
+ return number;
338
+ }
339
+ }
340
+ function toBoolean(value) {
341
+ if(typeof value == 'boolean') {
342
+ return value;
343
+ }
344
+
345
+ if(typeof value == 'string') {
346
+ if(value == 'true') {
347
+ return true;
348
+ } else if(value == 'false') {
349
+ return false;
350
+ }
351
+ }
352
+ return null;
353
+ }
354
+
355
+ function replaceCarriageReturns(str) {
356
+ let regxp = /\r/g;
357
+ str = str.replace(regxp, "");
358
+ return str;
359
+ }
360
+
361
+ function cutOut(val, delim) {
362
+ if (val === undefined)
363
+ return val;
364
+ try {
365
+ var x = val.lastIndexOf(delim);
366
+ if (x <= 0)
367
+ return;
368
+ return val.substring(0, x);
369
+ } catch (e) {
370
+ return val;
371
+ }
372
+ }
373
+
374
+ const conf = new Configuration();
375
+
376
+ conf.on('trace_ignore_url_set', function(props){
377
+ if(!props || props.constructor !== String){
378
+ return;
379
+ }
380
+
381
+ var ignoreUrls = props.split(',');
382
+ conf._trace_ignore_url_set = {};
383
+ for(var i = 0; i < ignoreUrls.length; i++){
384
+ var ignoreUrl = ignoreUrls[i];
385
+ var serviceHash = HashUtil.hashFromString(ignoreUrl);
386
+ conf._trace_ignore_url_set[serviceHash] = true;
387
+ }
388
+ });
389
+
390
+ conf.on('trace_ignore_url_prefix', function(props){
391
+ if(props && props.constructor === String && props.length > 0 ){
392
+ conf._is_trace_ignore_url_prefix = true;
393
+ }else{
394
+ conf._is_trace_ignore_url_prefix = false;
395
+ }
396
+ });
397
+
398
+ conf.on('trace_ignore_err_cls_contains', function(props){
399
+ if(props && props.constructor === String && props.length > 0 ){
400
+ conf._is_trace_ignore_err_cls_contains = true;
401
+ }else{
402
+ conf._is_trace_ignore_err_cls_contains = false;
403
+ }
404
+ });
405
+
406
+ conf.on('trace_ignore_err_msg_contains', function(props){
407
+ if(props && props.constructor === String && props.length > 0 ){
408
+ conf._is_trace_ignore_err_msg_contains = true;
409
+ }else{
410
+ conf._is_trace_ignore_err_msg_contains = false;
411
+ }
412
+ });
413
+
414
+
415
+ conf.on('mtrace_spec', function(props){
416
+ if (!props || props.length == 0) {
417
+ conf.mtrace_spec_hash = 0;
418
+ } else {
419
+ props = props.replace(',', '_');
420
+ conf.mtrace_spec_hash = HashUtil.hash(props);
421
+ }
422
+ })
423
+
424
424
  module.exports = conf;