whatap 0.5.26 → 1.0.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.
Files changed (196) hide show
  1. package/agent/darwin/arm64/whatap_nodejs +0 -0
  2. package/agent/linux/amd64/whatap_nodejs +0 -0
  3. package/agent/linux/arm64/whatap_nodejs +0 -0
  4. package/build.txt +4 -0
  5. package/lib/conf/config-default.js +3 -10
  6. package/lib/conf/configure.js +349 -369
  7. package/lib/conf/license.js +1 -1
  8. package/lib/control/packagectr-helper.js +3 -34
  9. package/lib/core/agent.js +882 -176
  10. package/lib/core/interceptor.js +6 -6
  11. package/lib/core/shimmer.js +36 -82
  12. package/lib/counter/counter-manager.js +8 -79
  13. package/lib/counter/task/activetransaction.js +17 -68
  14. package/lib/io/data-inputx.js +3 -13
  15. package/lib/io/data-outputx.js +206 -268
  16. package/lib/logger.js +6 -6
  17. package/lib/net/security-master.js +20 -139
  18. package/lib/observers/apollo-server-observer.js +27 -33
  19. package/lib/observers/global-observer.js +80 -155
  20. package/lib/observers/http-observer.js +236 -666
  21. package/lib/observers/ioredis-observer.js +294 -0
  22. package/lib/observers/maria-observer.js +362 -204
  23. package/lib/observers/mongodb-observer.js +226 -169
  24. package/lib/observers/mongoose-observer.js +323 -518
  25. package/lib/observers/mssql-observer.js +418 -177
  26. package/lib/observers/mysql-observer.js +449 -342
  27. package/lib/observers/mysql2-observer.js +358 -396
  28. package/lib/observers/oracle-observer.js +384 -559
  29. package/lib/observers/pgsql-observer.js +489 -231
  30. package/lib/observers/prisma-observer.js +92 -303
  31. package/lib/observers/process-observer.js +35 -79
  32. package/lib/observers/redis-observer.js +331 -166
  33. package/lib/observers/socket.io-observer.js +187 -226
  34. package/lib/observers/websocket-observer.js +301 -175
  35. package/lib/pack/counter-pack.js +0 -3
  36. package/lib/pack/log-sink-pack.js +52 -14
  37. package/lib/pack/tagcount-pack.js +4 -4
  38. package/lib/{counter/task → system}/gc-action.js +74 -27
  39. package/lib/trace/trace-context-manager.js +25 -113
  40. package/lib/trace/trace-context.js +7 -21
  41. package/lib/trace/trace-httpc.js +11 -17
  42. package/lib/trace/trace-sql.js +21 -29
  43. package/lib/udp/async_sender.js +119 -0
  44. package/lib/udp/index.js +17 -0
  45. package/lib/udp/packet_enum.js +52 -0
  46. package/lib/udp/packet_queue.js +69 -0
  47. package/lib/udp/packet_type_enum.js +33 -0
  48. package/lib/udp/param_def.js +72 -0
  49. package/lib/udp/udp_session.js +336 -0
  50. package/lib/util/escape-literal-sql.js +5 -5
  51. package/lib/util/hashutil.js +18 -18
  52. package/lib/util/keygen.js +3 -0
  53. package/lib/util/linkedset.js +2 -1
  54. package/lib/util/nodeutil.js +1 -2
  55. package/lib/util/sql-util.js +178 -0
  56. package/lib/util/trace-helper.js +91 -0
  57. package/lib/util/transfer.js +58 -0
  58. package/lib/value/map-value.js +2 -3
  59. package/package.json +5 -10
  60. package/lib/conf/conf-sys-mon.js +0 -101
  61. package/lib/control/cmd-config.js +0 -24
  62. package/lib/control/control-handler.js +0 -367
  63. package/lib/core/request-agent.js +0 -27
  64. package/lib/counter/meter/meter-activex.js +0 -67
  65. package/lib/counter/meter/meter-httpc.js +0 -57
  66. package/lib/counter/meter/meter-resource.js +0 -9
  67. package/lib/counter/meter/meter-service.js +0 -168
  68. package/lib/counter/meter/meter-socket.io.js +0 -51
  69. package/lib/counter/meter/meter-sql.js +0 -71
  70. package/lib/counter/meter/meter-users.js +0 -58
  71. package/lib/counter/meter.js +0 -183
  72. package/lib/counter/task/agentinfo.js +0 -107
  73. package/lib/counter/task/gcstat.js +0 -34
  74. package/lib/counter/task/heapmem.js +0 -25
  75. package/lib/counter/task/httpc.js +0 -76
  76. package/lib/counter/task/metering-info.js +0 -125
  77. package/lib/counter/task/proc-cpu.js +0 -29
  78. package/lib/counter/task/realtimeuser.js +0 -31
  79. package/lib/counter/task/res/systemECSTask.js +0 -39
  80. package/lib/counter/task/res/systemKubeTask.js +0 -53
  81. package/lib/counter/task/res/util/awsEcsClientThread.js +0 -218
  82. package/lib/counter/task/res/util/linuxProcStatUtil.js +0 -14
  83. package/lib/counter/task/res-sys-cpu.js +0 -62
  84. package/lib/counter/task/service.js +0 -202
  85. package/lib/counter/task/socketio.js +0 -30
  86. package/lib/counter/task/sql.js +0 -105
  87. package/lib/counter/task/systemperf.js +0 -43
  88. package/lib/data/datapack-sender.js +0 -289
  89. package/lib/data/dataprofile-agent.js +0 -162
  90. package/lib/data/datatext-agent.js +0 -135
  91. package/lib/data/event-level.js +0 -15
  92. package/lib/data/test.js +0 -49
  93. package/lib/data/zipprofile.js +0 -197
  94. package/lib/env/constants.js +0 -21
  95. package/lib/error/error-handler.js +0 -437
  96. package/lib/kube/kube-client.js +0 -144
  97. package/lib/lang/text-types.js +0 -58
  98. package/lib/logsink/line-log-util.js +0 -87
  99. package/lib/logsink/line-log.js +0 -12
  100. package/lib/logsink/log-sender.js +0 -78
  101. package/lib/logsink/log-tracer.js +0 -40
  102. package/lib/logsink/sender-util.js +0 -56
  103. package/lib/logsink/zip/zip-send.js +0 -177
  104. package/lib/net/netflag.js +0 -55
  105. package/lib/net/receiver.js +0 -66
  106. package/lib/net/sender.js +0 -141
  107. package/lib/net/tcp-return.js +0 -18
  108. package/lib/net/tcp-session.js +0 -286
  109. package/lib/net/tcpreq-client-proxy.js +0 -70
  110. package/lib/net/tcprequest-mgr.js +0 -58
  111. package/lib/observers/cluster-observer.js +0 -22
  112. package/lib/observers/express-observer.js +0 -215
  113. package/lib/observers/file-observer.js +0 -184
  114. package/lib/observers/grpc-observer.js +0 -336
  115. package/lib/observers/memcached-observer.js +0 -56
  116. package/lib/observers/mongo-observer.js +0 -317
  117. package/lib/observers/net-observer.js +0 -77
  118. package/lib/observers/promise-observer.js +0 -31
  119. package/lib/observers/schedule-observer.js +0 -67
  120. package/lib/observers/stream-observer.js +0 -19
  121. package/lib/observers/thrift-observer.js +0 -197
  122. package/lib/pack/activestack-pack.js +0 -55
  123. package/lib/pack/apenum.js +0 -8
  124. package/lib/pack/errorsnap-pack.js +0 -69
  125. package/lib/pack/event-pack.js +0 -54
  126. package/lib/pack/hitmap-pack.js +0 -63
  127. package/lib/pack/hitmap-pack1.js +0 -152
  128. package/lib/pack/netstat.js +0 -15
  129. package/lib/pack/otype.js +0 -7
  130. package/lib/pack/profile-pack.js +0 -49
  131. package/lib/pack/realtimeuser-pack.js +0 -41
  132. package/lib/pack/stat-general-pack.js +0 -96
  133. package/lib/pack/staterror-pack.js +0 -120
  134. package/lib/pack/stathttpc-pack.js +0 -66
  135. package/lib/pack/stathttpc-rec.js +0 -78
  136. package/lib/pack/statremote-pack.js +0 -46
  137. package/lib/pack/statservice-pack.js +0 -63
  138. package/lib/pack/statservice-pack1.js +0 -88
  139. package/lib/pack/statservice-rec.js +0 -292
  140. package/lib/pack/statservice-rec_dep.js +0 -151
  141. package/lib/pack/statsql-pack.js +0 -69
  142. package/lib/pack/statsql-rec.js +0 -100
  143. package/lib/pack/statuseragent-pack.js +0 -44
  144. package/lib/pack/tagctr.js +0 -15
  145. package/lib/pack/text-pack.js +0 -50
  146. package/lib/pack/time-count.js +0 -25
  147. package/lib/pack/websocket.js +0 -15
  148. package/lib/pack/zip-pack.js +0 -70
  149. package/lib/pii/pii-item.js +0 -31
  150. package/lib/pii/pii-mask.js +0 -174
  151. package/lib/plugin/plugin-loadermanager.js +0 -57
  152. package/lib/plugin/plugin.js +0 -75
  153. package/lib/service/tx-record.js +0 -332
  154. package/lib/stat/stat-error.js +0 -116
  155. package/lib/stat/stat-httpc.js +0 -98
  156. package/lib/stat/stat-remote-ip.js +0 -46
  157. package/lib/stat/stat-remote-ipurl.js +0 -88
  158. package/lib/stat/stat-sql.js +0 -113
  159. package/lib/stat/stat-tranx.js +0 -58
  160. package/lib/stat/stat-tx-caller.js +0 -160
  161. package/lib/stat/stat-tx-domain.js +0 -111
  162. package/lib/stat/stat-tx-referer.js +0 -112
  163. package/lib/stat/stat-useragent.js +0 -48
  164. package/lib/stat/timingsender.js +0 -76
  165. package/lib/step/activestack-step.js +0 -38
  166. package/lib/step/dbc-step.js +0 -36
  167. package/lib/step/http-stepx.js +0 -67
  168. package/lib/step/message-step.js +0 -40
  169. package/lib/step/method-stepx.js +0 -45
  170. package/lib/step/resultset-step.js +0 -40
  171. package/lib/step/securemsg-step.js +0 -44
  172. package/lib/step/socket-step.js +0 -46
  173. package/lib/step/sql-stepx.js +0 -68
  174. package/lib/step/sqlxtype.js +0 -16
  175. package/lib/step/step.js +0 -66
  176. package/lib/step/stepenum.js +0 -54
  177. package/lib/topology/link.js +0 -63
  178. package/lib/topology/nodeinfo.js +0 -123
  179. package/lib/topology/status-detector.js +0 -111
  180. package/lib/util/anylist.js +0 -103
  181. package/lib/util/cardinality/hyperloglog.js +0 -106
  182. package/lib/util/cardinality/murmurhash.js +0 -31
  183. package/lib/util/cardinality/registerset.js +0 -75
  184. package/lib/util/errordata.js +0 -21
  185. package/lib/util/iputil_x.js +0 -527
  186. package/lib/util/kube-util.js +0 -73
  187. package/lib/util/paramsecurity.js +0 -80
  188. package/lib/util/pre-process.js +0 -13
  189. package/lib/util/process-seq.js +0 -166
  190. package/lib/util/property-util.js +0 -36
  191. package/lib/util/request-queue.js +0 -70
  192. package/lib/util/requestdouble-queue.js +0 -72
  193. package/lib/util/resourceprofile.js +0 -157
  194. package/lib/util/stop-watch.js +0 -30
  195. package/lib/util/system-util.js +0 -10
  196. package/lib/util/userid-util.js +0 -57
@@ -1,50 +0,0 @@
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 Pack = require('./pack'),
8
- PackEnum = require('./packenum');
9
-
10
- function TextRec(type, hash, text){
11
- this.type = type || 0;
12
- this.hash = hash || 0;
13
- this.text = text || '';
14
- }
15
-
16
- function TextPack(){
17
- Pack.call(this);
18
- this.records = []; /*List<TextRec>*/
19
- }
20
-
21
- TextPack.prototype = new Pack();
22
- TextPack.prototype.constructor = TextPack;
23
- TextPack.prototype.getPackType = function () {
24
- return PackEnum.TEXT;
25
- };
26
- TextPack.prototype.write = function(dout){
27
- Pack.prototype.write.call(this, dout);
28
- dout.writeDecimal(this.records.length);
29
- this.records.forEach(function(r) {
30
- dout.writeByte(r.type);
31
- dout.writeInt(r.hash);
32
- dout.writeText(r.text);
33
- });
34
- };
35
- TextPack.prototype.read = function(din) {
36
- Pack.prototype.read.call(this, din);
37
-
38
- var size = din.readDecNumber();
39
- for (var i = 0; i < size; i++) {
40
- var r = new TextRec();
41
- r.type = din.readByte();
42
- r.hash = din.readInt();
43
- r.text = din.readText();
44
- this.records.push(r);
45
- }
46
- return this;
47
- };
48
-
49
- exports.TextRec = TextRec;
50
- exports.TextPack = TextPack;
@@ -1,25 +0,0 @@
1
- function TimeCount(count, error, time){
2
- this.count = count || 0;
3
- this.error = error || 0;
4
- this.time = time || 0;
5
- }
6
-
7
- TimeCount.prototype.add = function(time, error){
8
- this.count++;
9
- this.time += time;
10
- if(error){
11
- this.error++;
12
- }
13
- };
14
-
15
- TimeCount.prototype.merge = function(o){
16
- this.count += o.count;
17
- this.time +=o.time;
18
- this.error += o.error;
19
- };
20
-
21
- TimeCount.prototype.copy = function(){
22
- return new TimeCount(this.count, this.error, this.time);
23
- };
24
-
25
- module.exports = TimeCount;
@@ -1,15 +0,0 @@
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 Long = require('long');
8
-
9
- function WEBSOCKET() {
10
- this.count = 0;
11
- this.in = 0;
12
- this.out = 0;
13
- }
14
-
15
- module.exports = WEBSOCKET;
@@ -1,70 +0,0 @@
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 PackEnum = require('./packenum'),
8
- Pack = require('./pack'),
9
- TxRecord = require('../service/tx-record'),
10
- Step = require('../step/step'),
11
- DataOutputX = require('../io/data-outputx'),
12
- DataInputX = require('../io/data-inputx');
13
-
14
- function ZipPack() {
15
- Pack.call(this);
16
- this.records = [];
17
- this.recordCount = null;
18
- this.status = 0;
19
- }
20
- ZipPack.prototype = new Pack();
21
- ZipPack.prototype.constructor = ZipPack;
22
- ZipPack.prototype.toString = function() {
23
- var text = 'ZipPack ' + Pack.prototype.toString.call(this);
24
- return text;
25
- };
26
- ZipPack.prototype.getPackType = function () {
27
- return PackEnum.ZIP;
28
- };
29
- ZipPack.prototype.write = function (dout) {
30
- Pack.prototype.write.call(this, dout);
31
- dout.writeByte(this.status);
32
- dout.writeDecimal(this.recordCount);
33
- dout.writeBlob(this.records);
34
- }
35
- ZipPack.prototype.read = function (din) {
36
- Pack.prototype.read.call(this, din);
37
- this.status = din.readByte();
38
- this.recordCount = din.readDecimal();
39
- this.records = din.readBlob();
40
- return this;
41
- }
42
- ZipPack.prototype.setRecords = function (items, size) {
43
- if(size) this.recordCount = size;
44
- else this.recordCount = items.length;
45
-
46
- var o = new DataOutputX();
47
- for(let i = 0; i < items.length; i++){
48
- o.writePack(items[i]);
49
- }
50
- this.records = o.toByteArray();
51
- return this;
52
- }
53
- ZipPack.prototype.getRecords = function () {
54
- var items = [];
55
- if(!this.records) {
56
- return null;
57
- }
58
- var dataInputX = new DataInputX(this.records);
59
- for(let i = 0; i < this.recordCount; i++){
60
- var p = dataInputX.readPack();
61
- p.pcode = this.pcode;
62
- p.oid = this.oid;
63
- p.okind = this.okind;
64
- p.onode = this.onode;
65
- items.push(p);
66
- }
67
- return items;
68
- }
69
-
70
- module.exports = ZipPack;
@@ -1,31 +0,0 @@
1
- const conf = require('../conf/configure');
2
-
3
- class PiiItem {
4
- constructor(field, pattern) {
5
- if (pattern === undefined) {
6
- pattern = field;
7
- field = null;
8
- }
9
-
10
- this.field = field;
11
- this.isContent = !field || field === 'content';
12
- this.expr = pattern;
13
- this.pattern = new RegExp(pattern);
14
- }
15
-
16
- mask(pack) {
17
- if(!pack.content){
18
- return;
19
- }
20
- if(this.pattern.test(pack.content)){
21
- this.pattern.lastIndex = 0;
22
- pack.content = pack.content.replace(this.pattern, conf.getProperty('pii_mask_logsink_replace', 'pii-included'));
23
- }
24
- }
25
-
26
- hasMatch(s) {
27
- return this.pattern.test(s);
28
- }
29
- }
30
-
31
- module.exports = PiiItem;
@@ -1,174 +0,0 @@
1
- const conf = require('../conf/configure'),
2
- StringKeyLinkedMap = require('../util/stringkey-linkedmap'),
3
- Logger = require('../logger');
4
- const PiiItem = require('./pii-item');
5
-
6
- class PiiMask {
7
- static instance = null;
8
-
9
- constructor() {
10
- // StringKeyLinkedMap을 직접 생성하고 create 메서드를 구현
11
- this.table = new StringKeyLinkedMap();
12
- this.table.create = function(key) {
13
- return [];
14
- };
15
-
16
- this.sqlMask = [];
17
- this.confLogSink = "";
18
- this.confSql = "";
19
-
20
- // IntLinkedSet 대신 Set 사용 (자바스크립트에서는 Set으로 충분)
21
- this.sql_p1_has = new Set();
22
- this.sql_p1_not = new Set();
23
- this.sql_p2_has = new Set();
24
- this.sql_p2_not = new Set();
25
-
26
- this.MAX_SET_SIZE = 5000;
27
- }
28
-
29
- static getInstance() {
30
- if (!PiiMask.instance) {
31
- PiiMask.instance = new PiiMask();
32
- }
33
- return PiiMask.instance;
34
- }
35
-
36
- static trimToEmpty(str) {
37
- return str ? str.trim() : '';
38
- }
39
-
40
- static isEmpty(str) {
41
- return !str || str.trim().length === 0;
42
- }
43
-
44
- static tokenizer(str, delimiter) {
45
- return str.split(delimiter).map(item => item.trim()).filter(item => item.length > 0);
46
- }
47
-
48
- static update() {
49
- PiiMask.getInstance().update();
50
- }
51
-
52
- static parseLogSink(pack) {
53
- return PiiMask.getInstance().parseLogSink(pack);
54
- }
55
-
56
- static parseSqlP1(sqlHash, param) {
57
- return PiiMask.getInstance().parseSqlP1(sqlHash, param);
58
- }
59
-
60
- static parseSqlP2(sqlHash, param) {
61
- return PiiMask.getInstance().parseSqlP2(sqlHash, param);
62
- }
63
-
64
- update() {
65
- this.updateLogSink();
66
- this.updateSql();
67
- }
68
-
69
- updateLogSink() {
70
- const val = PiiMask.trimToEmpty(conf.getProperty('pii_mask_logsink_items', ''));
71
- if (val === this.confLogSink) {
72
- return;
73
- }
74
-
75
- this.confLogSink = val;
76
- const tmp = new StringKeyLinkedMap();
77
- tmp.create = function(key) {
78
- return [];
79
- };
80
-
81
- const ids = PiiMask.tokenizer(val, ',');
82
- for (const id of ids) {
83
- const category = conf.getLogSinkProperty(id, 'category');
84
- const pattern = conf.getLogSinkProperty(id, 'pattern');
85
- const field = conf.getLogSinkProperty(id, 'field');
86
-
87
- if (PiiMask.isEmpty(category) || PiiMask.isEmpty(pattern)) {
88
- Logger.printError('WHATAP-901', `logsink pii config for [${id}] is empty or invalid`, false);
89
- continue;
90
- }
91
-
92
- var categories = PiiMask.tokenizer(category, ',');
93
- for(let _category of categories){
94
- tmp.intern(_category).push(new PiiItem(field, pattern));
95
- }
96
- }
97
- this.table = tmp;
98
- }
99
-
100
- updateSql() {
101
- const val = PiiMask.trimToEmpty(conf.getProperty('pii_mask_sql_items', ''));
102
- if (val === this.confSql) {
103
- return;
104
- }
105
-
106
- this.confSql = val;
107
- const tmp = [];
108
-
109
- const ids = PiiMask.tokenizer(val, ',');
110
- for (const id of ids) {
111
- const pattern = conf.getSqlProperty(id, 'pattern');
112
- if (PiiMask.isEmpty(pattern)) {
113
- Logger.printError('WHATAP-901', `sql pii config for [${id}] is empty or invalid`, false);
114
- continue;
115
- }
116
- tmp.push(new RegExp(pattern));
117
- }
118
- this.sqlMask = tmp;
119
- }
120
-
121
- parseLogSink(pack) {
122
- const list = this.table.get(pack.category);
123
- if (!list) {
124
- return;
125
- }
126
-
127
- for (const piiItem of list) {
128
- piiItem.mask(pack);
129
- }
130
- }
131
-
132
- parseSqlP1(sqlHash, param) {
133
- if (this.sqlMask.length === 0 || PiiMask.isEmpty(param)) {
134
- return param;
135
- }
136
- return this.exec(sqlHash, param, this.sql_p1_has, this.sql_p1_not);
137
- }
138
-
139
- parseSqlP2(sqlHash, param) {
140
- if (this.sqlMask.length === 0 || PiiMask.isEmpty(param)) {
141
- return param;
142
- }
143
- return this.exec(sqlHash, param, this.sql_p2_has, this.sql_p2_not);
144
- }
145
-
146
- exec(sqlHash, param, sqlHas, sqlNot) {
147
- // Maintain set size limit
148
- if (sqlHas.size > this.MAX_SET_SIZE) {
149
- sqlHas.clear();
150
- }
151
- if (sqlNot.size > this.MAX_SET_SIZE) {
152
- sqlNot.clear();
153
- }
154
-
155
- if (sqlNot.has(sqlHash)) {
156
- return param;
157
- }
158
- if (sqlHas.has(sqlHash)) {
159
- return conf.getProperty('pii_mask_sql_replace', 'pii-included');
160
- }
161
-
162
- for (const pattern of this.sqlMask) {
163
- if (pattern.test(param)) {
164
- sqlHas.add(sqlHash);
165
- return conf.getProperty('pii_mask_sql_replace', 'pii-included');
166
- }
167
- }
168
-
169
- sqlNot.add(sqlHash);
170
- return param;
171
- }
172
- }
173
-
174
- module.exports = PiiMask;
@@ -1,57 +0,0 @@
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 fs = require('fs'),
8
- path = require('path'),
9
- PlugIn = require('./plugin'),
10
- Logger = require('../logger');
11
-
12
- var fileName = ['appservicestart', 'appserviceend', 'httpservicestart', 'httpserviceend', 'httpcall'];
13
-
14
- function PluginLoaderManager() {
15
- this.loaded = false;
16
- this.interval = null;
17
- this.module_holder;
18
- }
19
-
20
- PluginLoaderManager.prototype.start = function () {
21
- var self = this;
22
-
23
- this.module_holder = {};
24
- fileName.forEach(function (name) {
25
- var script = name + '.js';
26
- self.module_holder[name] = new PlugIn(script);
27
- });
28
-
29
- self.run(function () {
30
- self.interval = setInterval(function () {
31
- self.run();
32
- }, 5000);
33
- });
34
- };
35
- PluginLoaderManager.prototype.do = function (moduleName) {
36
- try {
37
- if(this.module_holder && this.module_holder[moduleName]) {
38
- this.module_holder[moduleName]._process(arguments[1], arguments[2], arguments[3]);
39
- }
40
- } catch(e) {
41
- Logger.printError('WHATAP-700', 'Plugin Error', e, false);
42
- }
43
- };
44
- PluginLoaderManager.prototype.run = function (cb) {
45
- var self = this;
46
-
47
- fileName.forEach(function (name) {
48
- self.module_holder[name].create();
49
- });
50
-
51
- if(cb) { cb(); }
52
- };
53
- PluginLoaderManager.prototype.stop = function () {
54
- clearInterval(this.interval);
55
- };
56
-
57
- module.exports = new PluginLoaderManager();
@@ -1,75 +0,0 @@
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 fs = require('fs'),
8
- path = require('path'),
9
- MessageStep = require('../step/message-step'),
10
- HashUtil = require('../util/hashutil'),
11
- DataTextAgent = require('../data/datatext-agent');
12
-
13
- const emptyFunc = function () {};
14
-
15
- function PlugIn(script) {
16
- this.script = script;
17
- this.lastModified = 0;
18
- this.process = emptyFunc;
19
- this.ctx = null;
20
- }
21
-
22
- PlugIn.prototype.create = function () {
23
- var self = this;
24
- var full_path = path.join(self.rootPath(), 'plugin', self.script);
25
- fs.stat(full_path, function (err, stats) {
26
- if(err) {
27
- self.process = emptyFunc();
28
- return;
29
- }
30
- var lastModifiedDate = stats.mtime;
31
- var inMillis = lastModifiedDate.getTime();
32
-
33
- if(self.lastModified < inMillis) {
34
- delete require.cache[require.resolve(full_path)];
35
- self.lastModified = inMillis;
36
- try{
37
- var func = require(full_path);
38
- if(typeof func === 'function') {
39
- self.process = func;
40
- } else {
41
- self.process = emptyFunc;
42
- }
43
- } catch(e) {
44
- self.process = emptyFunc;
45
- }
46
- }
47
- });
48
- };
49
- PlugIn.prototype._process = function () {
50
- var self = this;
51
- self.ctx = arguments[0];
52
- if(typeof self.process === 'function') {
53
- self.process.apply(this, arguments);
54
- }
55
- };
56
- PlugIn.prototype.rootPath = function () {
57
- return process.cwd();
58
- };
59
- PlugIn.prototype.print = function (str) {
60
- console.log(str)
61
- };
62
- PlugIn.prototype.profile = function (msg) {
63
- if(this.ctx == null) {
64
- return;
65
- }
66
- var hash = HashUtil.hashFromString(msg);
67
- DataTextAgent.MESSAGE.add(hash, msg);
68
-
69
- var step = new MessageStep();
70
- step.hash = hash;
71
- step.start_time = this.ctx.getElapsedTime();
72
- this.ctx.profile.add(step);
73
- };
74
-
75
- module.exports = PlugIn;