whatap 0.5.3 → 0.5.5

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.
@@ -110,8 +110,9 @@ var ConfigDefault = {
110
110
  "trace_sampling_enabled": bool("trace_sampling_enabled", true),
111
111
  "trace_sampling_tps": bool("trace_sampling_tps", 1000),
112
112
 
113
- "profile_error_sql_time_max": num("profile_error_sql_time_max", 30000),
114
113
  "profile_error_step_enabled": bool('profile_error_step_enabled', true),
114
+ "profile_error_sql_time_max": num("profile_error_sql_time_max", 30000),
115
+ "profile_error_sql_fetch_max": num("profile_error_sql_fetch_max", 10000),
115
116
  "profile_error_httpc_time_max": num("profile_error_httpc_time_max", 10000),
116
117
  "hook_direct_patch_classes": "",
117
118
 
@@ -221,7 +222,6 @@ var ConfigDefault = {
221
222
  "apdex_time_t": num('apdex_time_t', 1200),
222
223
  "apdex_time_4t": num('apdex_time_4t', 1200 * 4),
223
224
  "debug_apdex_enabled": bool('debug_apdex_enabled', false),
224
- "mtid_mtrace_enabled": bool('mtid_mtrace_enabled' , false),
225
225
 
226
226
  // debug add
227
227
  "network_debug_enabled" : bool('network_debug_enabled', false),
@@ -338,6 +338,14 @@ Configuration.prototype.getStringSet = function (key, defaultValue, deli) {
338
338
  return set;
339
339
  };
340
340
 
341
+ Configuration.prototype.getLogSinkProperty = function (id, key) {
342
+ return this.getProperty("pii_mask_logsink_"+id + "_" + key);
343
+ }
344
+
345
+ Configuration.prototype.getSqlProperty = function (id, key) {
346
+ return this.getProperty("pii_mask_sql_"+id + "_" + key)
347
+ }
348
+
341
349
  function toNumber(value) {
342
350
  if(typeof value == 'number') {
343
351
  return value;
@@ -32,6 +32,15 @@ var LogConfigDefault = {
32
32
  "logsink_high_secure_enabled": bool("logsink_high_secure_enabled", false),
33
33
  "debug_logsink_zip_enabled": bool("debug_logsink_zip_enabled", false),
34
34
  "logsink_max_buffer_size": num("logsink_max_buffer_size", 1024*64),
35
- "logsink_max_wait_time": num("logsink_max_wait_time", 2000)
35
+ "logsink_max_wait_time": num("logsink_max_wait_time", 2000),
36
+
37
+ "pii_mask_logsink_enabled": bool("pii_mask_logsink_enabled", false),
38
+ "pii_mask_logsink_items": str("pii_mask_logsink_items", ""),
39
+ "pii_mask_logsink_replace": str("pii_mask_logsink_replace", "***"),
40
+
41
+ "pii_mask_sql_enabled": bool("pii_mask_sql_enabled", false),
42
+ "pii_mask_sql_items": str("pii_mask_sql_items", ""),
43
+ "pii_mask_sql_replace": str("pii_mask_sql_replace", "pii-included"),
44
+
36
45
  };
37
46
  module.exports = LogConfigDefault;
@@ -26,7 +26,7 @@ var CounterTask = require('./counter-task'),
26
26
  KubeUtil = require('../../util/kube-util'),
27
27
  DateUtil = require('../../util/dateutil'),
28
28
  fs = require('fs'),
29
- Long = require('long');
29
+ PiiMask = require('../../pii/pii-mask');
30
30
 
31
31
  function AgentInfo() {
32
32
  CounterTask.call(this);
@@ -38,6 +38,8 @@ function AgentInfo() {
38
38
  AgentInfo.prototype = new CounterTask();
39
39
  AgentInfo.prototype.constructor = AgentInfo;
40
40
  AgentInfo.prototype.process = function (p) {
41
+ // PiiMask.update();
42
+
41
43
  p.starttime = Date.now();
42
44
  /*
43
45
  if (p.starttime > this.startTime + DateUtil.MILLIS_PER_FIVE_MINUTE) {
@@ -5,28 +5,9 @@
5
5
  */
6
6
 
7
7
  var CounterTask = require('../counter-task'),
8
- StatSql = require('../../../stat/stat-sql'),
9
8
  conf = require('../../../conf/configure'),
10
9
  SecurityMaster = require('../../../net/security-master'),
11
- TraceContextManager = require('../../../trace/trace-context-manager'),
12
- MeterActiveX = require('../../meter/meter-activex'),
13
- ActiveStackPack = require('../../../pack/activestack-pack'),
14
- ParamPack = require('../../../pack/param-pack'),
15
- EventPack = require('../../../pack/event-pack'),
16
- ActiveStackStep = require('../../../step/activestack-step'),
17
- DataPackSender = require('../../../data/datapack-sender'),
18
- DataTextAgent = require('../../../data/datatext-agent'),
19
- EventLevel = require('../../../data/event-level'),
20
- MeterUsers = require('../../meter/meter-users'),
21
- KeyGen = require('../../../util/keygen'),
22
- TextTypes = require('../../../lang/text-types'),
23
- ResourceProfile = require('../../../util/resourceprofile'),
24
- Logger = require('../../../logger'),
25
- HashUtil = require('../../../util/hashutil'),
26
- KubeUtil = require('../../../util/kube-util'),
27
- DateUtil = require('../../../util/dateutil'),
28
- AwsEcsClientThread = require('./util/awsEcsClientThread'),
29
- Long = require('long');
10
+ AwsEcsClientThread = require('./util/awsEcsClientThread');
30
11
 
31
12
  function SystemECSTask() {
32
13
  CounterTask.call(this);
@@ -35,17 +16,18 @@ function SystemECSTask() {
35
16
  SystemECSTask.prototype = new CounterTask();
36
17
  SystemECSTask.prototype.constructor = SystemECSTask;
37
18
  SystemECSTask.prototype.process = function (p) {
38
- p.cpu_cores = 1;
39
19
  p.host_ip = SecurityMaster.IP;
40
20
 
41
21
  var ecs = AwsEcsClientThread;
22
+
42
23
  p.cpu = ecs.cpu * conf.correction_factor_cpu;
43
24
  p.cpu_sys = ecs.cpu_sys;
44
25
  p.cpu_usr = ecs.cpu_user;
45
26
  p.mem = ecs.mem_pct;
46
27
 
47
28
  if (ecs.millicore > 0) {
48
- p.metering = ecs.millicore /1024;
29
+ p.metering = ecs.millicore / 1024;
30
+ p.cpu_cores = Math.ceil(p.metering);
49
31
  } else {
50
32
  p.metering = p.cpu_cores;
51
33
  }
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  var http = require('http');
4
2
  /**
5
3
  * Copyright 2016 the WHATAP project authors. All rights reserved.
@@ -9,18 +7,17 @@ var http = require('http');
9
7
 
10
8
  var CounterTask = require('../../counter-task'),
11
9
  conf = require('../../../../conf/configure'),
12
- Logger = require('../../../../logger'),
13
- DateUtil = require('../../../../util/dateutil'),
14
- Long = require('long');
10
+ Logger = require('../../../../logger'),
11
+ DateUtil = require('../../../../util/dateutil');
15
12
 
16
13
  function AwsEcsClientThread() {
17
- if (typeof AwsEcsClientThread.instance === "object") {
18
- return AwsEcsClientThread.instance;
14
+ if (typeof AwsEcsClientThread.instance === "object") {
15
+ return AwsEcsClientThread.instance;
19
16
  }
20
17
 
21
18
  this.millicore = 0;
22
- this.last_milli_check = 0;
23
- this.check = AwsEcsClientThread.CHECK_MAX;
19
+ this.last_milli_check = 0;
20
+ this.check = AwsEcsClientThread.CHECK_MAX;
24
21
 
25
22
 
26
23
  this.cpu = 0;
@@ -28,41 +25,39 @@ function AwsEcsClientThread() {
28
25
  this.cpu_user = 0;
29
26
  this.mem_pct = 0;
30
27
 
31
- AwsEcsClientThread.instance = this;
28
+ var self = this;
29
+ setTimeout(function () {
30
+ self.run();
31
+ }, 100);
32
+ AwsEcsClientThread.instance = this;
32
33
  };
33
34
  AwsEcsClientThread.prototype = new AwsEcsClientThread();
34
35
 
35
- AwsEcsClientThread.prototype.run = function() {
36
+ AwsEcsClientThread.prototype.run = function () {
36
37
  var self = this;
37
38
  try {
38
39
  if (conf.aws_ecs_enabled) {
39
- self.intervalIndex = setInterval(function(){
40
+ self.intervalIndex = setInterval(function () {
40
41
  var meta_uri = process.env["ECS_CONTAINER_METADATA_URI"];
41
42
  if (meta_uri != null) {
42
43
  self.getCpuLimit(meta_uri);
43
44
  self.process(meta_uri);
44
45
  }
45
- }, conf.aws_ecs_stat_interval || 3000);
46
-
47
- var meta_uri = process.env["ECS_CONTAINER_METADATA_URI"];
48
- if (meta_uri != null) {
49
- this.getCpuLimit(meta_uri);
50
- this.process(meta_uri);
51
- }
46
+ }, conf.getProperty('aws_ecs_stat_interval', 3000));
52
47
  }
53
48
  } catch (e) {
54
- Logger.printError('WHATAP ECS-ERR ' , 'run exception', e , true);
49
+ Logger.printError('WHATAP ECS-ERR ', 'run exception', e, true);
55
50
  }
56
51
  }
57
52
 
58
- AwsEcsClientThread.prototype.stop = function(){
59
- if(this.intervalIndex){
53
+ AwsEcsClientThread.prototype.stop = function () {
54
+ if (this.intervalIndex) {
60
55
  clearInterval(this.intervalIndex);
61
56
  this.intervalIndex = undefined;
62
57
  }
63
58
  }
64
59
 
65
- AwsEcsClientThread.prototype.getCpuLimit = function(meta_uri){
60
+ AwsEcsClientThread.prototype.getCpuLimit = function (meta_uri) {
66
61
  var self = this;
67
62
 
68
63
  if (this.check < 0)
@@ -71,68 +66,116 @@ AwsEcsClientThread.prototype.getCpuLimit = function(meta_uri){
71
66
  if (now - DateUtil.MILLIS_PER_HOUR * 8 < this.last_milli_check)
72
67
  return;
73
68
 
69
+ // var json = JSON.parse('{"DockerId":"e9950915-abaa-467f-9898-3bd0d4e6d0aa","Name":"web-application","DockerName":"ecs-web-application-1","Image":"nginx:latest","ImageID":"sha256:123456789abcdef...","Labels":{"com.amazonaws.ecs.cluster":"default","com.amazonaws.ecs.task-arn":"arn:aws:ecs:us-east-1:123456789012:task/default/1234567890abcdef","com.amazonaws.ecs.task-definition-family":"web-application","com.amazonaws.ecs.task-definition-version":"1"},"DesiredStatus":"RUNNING","KnownStatus":"RUNNING","Limits":{"CPU":256,"Memory":512},"CreatedAt":"2024-01-01T00:00:00.000Z","StartedAt":"2024-01-01T00:00:01.000Z","Type":"NORMAL","Networks":[{"NetworkMode":"awsvpc","IPv4Addresses":["172.31.10.100"],"AttachmentIndex":0,"MACAddress":"0a:1b:2c:3d:4e:5f","IPv4SubnetCIDRBlock":"172.31.0.0/20","DomainNameServers":["169.254.169.253"],"DomainNameSearchList":["us-east-1.compute.internal"],"PrivateDNSName":"ip-172-31-10-100.us-east-1.compute.internal","SubnetGatewayIpv4Address":"172.31.0.1/20"}],"ContainerARN":"arn:aws:ecs:us-east-1:123456789012:container/1234567890abcdef","LogDriver":"awslogs","LogOptions":{"awslogs-group":"/ecs/web-application","awslogs-region":"us-east-1","awslogs-stream":"ecs/web-application/1234567890abcdef"}}');
70
+ // 2025-01-23 ECS fargate
71
+ // var json = JSON.parse('{"DockerId":"a663f01570b14228b0795db9c8d11e16-2785547837","Name":"test_container","DockerName":"test_container","Image":"whataphub/ecs_sample:v0.0.4","ImageID":"sha256:748b5cd202288478bbdbd4baf8fe17c8b660163c24c513db5ccbe7a1bdcae0e0","Labels":{"com.amazonaws.ecs.cluster":"arn:aws:ecs:ap-northeast-2:592247757306:cluster/ecs_sample","com.amazonaws.ecs.container-name":"test_container","com.amazonaws.ecs.task-arn":"arn:aws:ecs:ap-northeast-2:592247757306:task/ecs_sample/a663f01570b14228b0795db9c8d11e16","com.amazonaws.ecs.task-definition-family":"ecs_task_sample","com.amazonaws.ecs.task-definition-version":"4"},"DesiredStatus":"RUNNING","KnownStatus":"RUNNING","Limits":{"CPU":2},"CreatedAt":"2025-01-23T04:42:03.843875803Z","StartedAt":"2025-01-23T04:42:03.843875803Z","Type":"NORMAL","Networks":[{"NetworkMode":"awsvpc","IPv4Addresses":["172.31.63.147"]}]}');
72
+ // if (json && json["Limits"]) {
73
+ // this.millicore = json.Limits.CPU;
74
+ // if (this.millicore < 128) {
75
+ // this.millicore *= 1024;
76
+ // }
77
+ // Logger.print("SysCPU", " ECS CPU Limits : " + (this.millicore / 1024) + "core", false)
78
+ // }
79
+
74
80
  read(meta_uri, function(json){
75
81
  if (json && json["Limits"]) {
76
- var Limits = json["Limits"];
77
- if(Limits){ millicore = Limits["CPU"]; }
82
+ this.millicore = json.Limits.CPU;
83
+ if (this.millicore < 128) {
84
+ this.millicore *= 1024;
85
+ }
86
+ Logger.print("WHATAP-811", "ECS CPU Limits : " + (this.millicore / 1024) + "core", false)
78
87
  }
79
88
  }, function(){
80
89
  self.millicore = 0;
81
90
  if (--self.check >= 0) {
82
- Logger.printError('WHATAP ECS-ERR ' , 'not receive limit cpu', e , true);
91
+ Logger.printError('WHATAP-819' , 'not receive limit cpu', e , true);
83
92
  }
84
93
  })
85
94
  }
86
95
 
87
- AwsEcsClientThread.prototype.process = function(meta_uri) {
88
- http.get(meta_uri + '/stats', function(res){
89
- var statusCode = res.statusCode;
90
- res.setEncoding('utf8');
96
+ AwsEcsClientThread.prototype.process = function (meta_uri) {
97
+ var self = this;
91
98
 
92
- var rawData = '';
93
- res.on('data', function(chunk){ rawData += chunk; });
94
- res.on('end', function(){
95
- try {
96
- var stats = JSON.parse(rawData);
99
+ fetch(meta_uri + '/stats', {timeout: 3000})
100
+ .then(response => response.text())
101
+ .then(stats => {
102
+ if (!stats || stats.length === 0) {
103
+ self.reset();
104
+ return;
105
+ }
106
+
107
+ // let stats = '{"blkio_stats":{"io_merged_recursive":[],"io_queue_recursive":[],"io_service_bytes_recursive":[{"major":259,"minor":3,"op":"Read","value":0},{"major":259,"minor":3,"op":"Write","value":45514752},{"major":259,"minor":3,"op":"Sync","value":4268032},{"major":259,"minor":3,"op":"Async","value":41246720},{"major":259,"minor":3,"op":"Discard","value":0},{"major":259,"minor":3,"op":"Total","value":45514752}],"io_service_time_recursive":[],"io_serviced_recursive":[{"major":259,"minor":3,"op":"Read","value":0},{"major":259,"minor":3,"op":"Write","value":342},{"major":259,"minor":3,"op":"Sync","value":272},{"major":259,"minor":3,"op":"Async","value":70},{"major":259,"minor":3,"op":"Discard","value":0},{"major":259,"minor":3,"op":"Total","value":342}],"io_time_recursive":[],"io_wait_time_recursive":[],"sectors_recursive":[]},"cpu_stats":{"cpu_usage":{"percpu_usage":[5585610339,5944268076],"total_usage":15373171220,"usage_in_kernelmode":2150000000,"usage_in_usermode":7990000000},"online_cpus":2,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"id":"10b741d47dc649d5b321f83c7c14c950-441560335","memory_stats":{"limit":9223372036854772000,"max_usage":246165504,"stats":{"active_anon":0,"active_file":27439104,"cache":56365056,"dirty":0,"hierarchical_memory_limit":2147483648,"hierarchical_memsw_limit":9223372036854772000,"inactive_anon":98267136,"inactive_file":28925952,"mapped_file":0,"pgfault":303666,"pgmajfault":0,"pgpgin":199749,"pgpgout":161965,"rss":98402304,"rss_huge":0,"total_active_anon":0,"total_active_file":27439104,"total_cache":56365056,"total_dirty":0,"total_inactive_anon":98267136,"total_inactive_file":28925952,"total_mapped_file":0,"total_pgfault":303666,"total_pgmajfault":0,"total_pgpgin":199749,"total_pgpgout":161965,"total_rss":98402304,"total_rss_huge":0,"total_unevictable":0,"total_writeback":135168,"unevictable":0,"writeback":135168},"usage":168361984},"name":"simple-user-app","networks":{"eth1":{"rx_bytes":1604876131,"rx_dropped":0,"rx_errors":0,"rx_packets":1076062,"tx_bytes":6252490,"tx_dropped":0,"tx_errors":0,"tx_packets":74457}},"num_procs":0,"pids_stats":{},"precpu_stats":{"cpu_usage":{"percpu_usage":[5570558410,5925648831],"total_usage":15328276321,"usage_in_kernelmode":2140000000,"usage_in_usermode":7970000000},"online_cpus":2,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"preread":"2023-05-30T11:29:20.720196524Z","read":"2023-05-30T11:29:30.719936356Z","storage_stats":{}}';
108
+ // 2025-01-23 ECS fargate
109
+ // var stats = '{"read":"2025-01-23T04:42:03.844081622Z","preread":"0001-01-01T00:00:00Z","pids_stats":{},"blkio_stats":{"io_service_bytes_recursive":[],"io_serviced_recursive":[],"io_queue_recursive":[],"io_service_time_recursive":[],"io_wait_time_recursive":[],"io_merged_recursive":[],"io_time_recursive":[],"sectors_recursive":[]},"num_procs":0,"storage_stats":{},"cpu_stats":{"cpu_usage":{"total_usage":33451672,"percpu_usage":[22728826,10722846],"usage_in_kernelmode":10000000,"usage_in_usermode":20000000},"system_cpu_usage":397640000000,"online_cpus":2,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"precpu_stats":{"cpu_usage":{"total_usage":0,"usage_in_kernelmode":0,"usage_in_usermode":0},"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"memory_stats":{"usage":765952,"max_usage":5267456,"stats":{"active_anon":0,"active_file":0,"cache":0,"dirty":0,"hierarchical_memory_limit":4294967296,"hierarchical_memsw_limit":9223372036854771712,"inactive_anon":135168,"inactive_file":0,"mapped_file":0,"pgfault":2112,"pgmajfault":0,"pgpgin":1452,"pgpgout":1452,"rss":270336,"rss_huge":0,"total_active_anon":0,"total_active_file":0,"total_cache":0,"total_dirty":0,"total_inactive_anon":135168,"total_inactive_file":0,"total_mapped_file":0,"total_pgfault":2112,"total_pgmajfault":0,"total_pgpgin":1452,"total_pgpgout":1452,"total_rss":270336,"total_rss_huge":0,"total_unevictable":0,"total_writeback":0,"unevictable":0,"writeback":0},"limit":9223372036854771712},"name":"test_container","id":"a663f01570b14228b0795db9c8d11e16-2785547837","networks":{"eth1":{"rx_bytes":463375353,"rx_packets":310281,"rx_errors":0,"rx_dropped":0,"tx_bytes":250514,"tx_packets":2681,"tx_errors":0,"tx_dropped":0}}}';
110
+ // var stats = '{"read":"2025-01-23T04:52:53.853606208Z","preread":"2025-01-23T04:52:43.853359478Z","pids_stats":{},"blkio_stats":{"io_service_bytes_recursive":[],"io_serviced_recursive":[],"io_queue_recursive":[],"io_service_time_recursive":[],"io_wait_time_recursive":[],"io_merged_recursive":[],"io_time_recursive":[],"sectors_recursive":[]},"num_procs":0,"storage_stats":{},"cpu_stats":{"cpu_usage":{"total_usage":8111895890,"percpu_usage":[3973083470,4138812420],"usage_in_kernelmode":2220000000,"usage_in_usermode":5910000000},"system_cpu_usage":1692450000000,"online_cpus":2,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"precpu_stats":{"cpu_usage":{"total_usage":8023476115,"percpu_usage":[3922781879,4100694236],"usage_in_kernelmode":2180000000,"usage_in_usermode":5820000000},"system_cpu_usage":1672470000000,"online_cpus":2,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"memory_stats":{"usage":66977792,"max_usage":98480128,"stats":{"active_anon":0,"active_file":0,"cache":0,"dirty":0,"hierarchical_memory_limit":4294967296,"hierarchical_memsw_limit":9223372036854771712,"inactive_anon":61906944,"inactive_file":0,"mapped_file":0,"pgfault":463386,"pgmajfault":0,"pgpgin":147477,"pgpgout":132323,"rss":62042112,"rss_huge":0,"total_active_anon":0,"total_active_file":0,"total_cache":0,"total_dirty":0,"total_inactive_anon":61906944,"total_inactive_file":0,"total_mapped_file":0,"total_pgfault":463386,"total_pgmajfault":0,"total_pgpgin":147477,"total_pgpgout":132323,"total_rss":62042112,"total_rss_huge":0,"total_unevictable":0,"total_writeback":0,"unevictable":0,"writeback":0},"limit":9223372036854771712},"name":"test_container","id":"a663f01570b14228b0795db9c8d11e16-2785547837","networks":{"eth1":{"rx_bytes":463489958,"rx_packets":311334,"rx_errors":0,"rx_dropped":0,"tx_bytes":1962223,"tx_packets":4432,"tx_errors":0,"tx_dropped":0}}}'
111
+ const o = JSON.parse(stats);
97
112
 
98
- var precpu_stats = stats["precpu_stats"];
99
- var cpu_stats = stats["cpu_stats"];
100
- var memory_stats = stats["memory_stats"];
113
+ if (conf.getProperty('debug_aws_ecs_enabled', false)) {
114
+ Logger.print("AwsEcsClient", 30, "meta_uri=" + meta_uri + " stats\n" + JSON.stringify(o, null, 4));
115
+ }
101
116
 
102
- var system_cpu_usage = delta(precpu_stats, cpu_stats, "system_cpu_usage");
117
+ const precpu_stats = o.precpu_stats || {};
118
+ const cpu_stats = o.cpu_stats || {};
119
+ const memory_stats = o.memory_stats || {};
103
120
 
104
- var precpu_usage = precpu_stats["cpu_usage"];
105
- var cpu_usage = cpu_stats["cpu_usage"];
121
+ const system_cpu_usage = delta(precpu_stats, cpu_stats, "system_cpu_usage");
106
122
 
107
- var usage_tot = delta(precpu_usage, cpu_usage, "total_usage");
108
- var usage_sys = delta(precpu_usage, cpu_usage, "usage_in_kernelmode");
109
- var usage_usr = delta(precpu_usage, cpu_usage, "usage_in_usermode");
123
+ if (system_cpu_usage > 0) {
124
+ const precpu_usage = precpu_stats.cpu_usage || {};
125
+ const cpu_usage = cpu_stats.cpu_usage || {};
110
126
 
111
- this.cpu = (usage_tot * 100) / system_cpu_usage;
112
- this.cpu_sys = (usage_sys * 100) / system_cpu_usage;
113
- this.cpu_user = (usage_usr * 100) / system_cpu_usage;
114
-
115
- var mem_usage = memory_stats["usage"];
116
- var mem_limit = memory_stats["limit"];
117
-
118
- this.mem_pct = (mem_usage * 100) / mem_limit;
127
+ const usage_tot = delta(precpu_usage, cpu_usage, "total_usage");
128
+ const usage_sys = delta(precpu_usage, cpu_usage, "usage_in_kernelmode");
129
+ const usage_usr = delta(precpu_usage, cpu_usage, "usage_in_usermode");
119
130
 
120
- } catch (e) {
121
- console.error(e.message);
131
+ self.cpu = (usage_tot * 100.0) / system_cpu_usage;
132
+ self.cpu_sys = (usage_sys * 100.0) / system_cpu_usage;
133
+ self.cpu_user = (usage_usr * 100.0) / system_cpu_usage;
134
+ } else {
135
+ self.reset();
122
136
  }
137
+
138
+ if (memory_stats) {
139
+ const mem_usage = memory_stats.usage || 0;
140
+ const memory_stats_stats = memory_stats.stats;
141
+
142
+ if (memory_stats_stats) {
143
+ const mem_limit = memory_stats_stats.hierarchical_memory_limit || 0;
144
+ self.mem_pct = (mem_usage * 100.0) / mem_limit;
145
+ } else {
146
+ self.mem_pct = 0;
147
+ }
148
+ } else {
149
+ self.mem_pct = 0;
150
+ }
151
+ })
152
+ .catch(error => {
153
+ Logger.printError("WHATAP-819", "ECS Process error: " + error, false)
154
+ self.reset();
123
155
  });
156
+ };
124
157
 
125
- });
158
+ AwsEcsClientThread.prototype.reset = function () {
159
+ this.cpu = 0;
160
+ this.cpu_sys = 0;
161
+ this.cpu_user = 0;
162
+ };
163
+
164
+ // reset 함수 추가
165
+ AwsEcsClientThread.prototype.reset = function () {
166
+ this.cpu = 0;
167
+ this.cpu_sys = 0;
168
+ this.cpu_user = 0;
126
169
  };
127
170
 
128
171
  AwsEcsClientThread.CHECK_MAX = 3;
129
172
 
130
- function read(url, succ, fail){
131
- http.get(url, function(res){
173
+ function read(url, succ, fail) {
174
+ http.get(url, function (res) {
132
175
  var statusCode = res.statusCode;
133
176
 
134
177
  if (statusCode !== 200) {
135
- if(fail) fail();
178
+ if (fail) fail();
136
179
 
137
180
  Logger.printError('WHATAP-999', 'read http call (not 200) ', e, true);
138
181
  return;
@@ -141,26 +184,35 @@ function read(url, succ, fail){
141
184
  res.setEncoding('utf8');
142
185
 
143
186
  var rawData = '';
144
- res.on('data', function(chunk){ rawData += chunk; });
145
- res.on('end', function(){
187
+ res.on('data', function (chunk) {
188
+ rawData += chunk;
189
+ });
190
+ res.on('end', function () {
146
191
  try {
147
192
  var stats = JSON.parse(rawData);
148
- if(succ) succ(stats);
193
+ if (succ) succ(stats);
149
194
  } catch (e) {
150
- if(fail) fail(e);
195
+ if (fail) fail(e);
151
196
  Logger.printError('WHATAP-999', 'read http call (not application/json) ', e, true);
152
197
  }
153
198
  });
154
199
  }).on('error', (e) => {
155
- if(fail) fail(e);
200
+ if (fail) fail(e);
156
201
  Logger.printError('WHATAP-999', 'read http call ', e, true);
157
202
  });
158
203
  }
159
204
 
160
205
  function delta(j1, j2, key) {
206
+ if (!j1 || !j2)
207
+ return 0;
208
+
161
209
  var v1 = j1[key];
162
210
  var v2 = j2[key];
163
- return v2 - v1;
211
+
212
+ if(v1 && v2)
213
+ return v2 - v1;
214
+ else
215
+ return 0;
164
216
  }
165
217
 
166
218
  module.exports = new AwsEcsClientThread();
package/lib/logger.js CHANGED
@@ -190,49 +190,54 @@
190
190
  }
191
191
 
192
192
  },
193
- clearOldLog : function () {
194
- if(conf.log_rotation_enabled === false || conf.log_enabled === false) { return; }
195
- if(conf.log_keep_days <= 0) { return; }
196
-
193
+ clearOldLog: function () {
194
+ if (conf.log_rotation_enabled === false || conf.log_enabled === false) {
195
+ return;
196
+ }
197
+ if (conf.log_keep_days <= 0) {
198
+ return;
199
+ }
200
+
197
201
  var root = conf['app.root'];
198
- if(conf.getProperty('log_root', null)){
202
+ if (conf.getProperty('log_root', null)) {
199
203
  root = conf.getProperty('log_root', null);
200
- if(fs.existsSync(root) == false) {
204
+ if (fs.existsSync(root) == false) {
201
205
  fs.mkdirSync(root, {recursive: true});
202
206
  }
203
207
  }
204
208
  var nowUnit = DateUtil.getDateUnit(),
205
209
  dir = path.join(root, 'logs'),
206
- log_prefix = WHATAP_CONF+"-";
207
-
210
+ log_prefix = WHATAP_CONF + "-";
211
+
208
212
  fs.readdir(dir, function (err, files) {
209
-
210
- for(var i=0; i<files.length; i++) {
213
+
214
+ for (var i = 0; i < files.length; i++) {
211
215
  var stat = fs.statSync(path.join(dir, files[i]));
212
- if(stat.isDirectory()) {
216
+ if (stat.isDirectory()) {
213
217
  return true;
214
218
  }
215
219
  var name = files[i];
216
- if(name.indexOf(log_prefix) < 0) {
220
+ if (name.indexOf(log_prefix) < 0) {
217
221
  return true;
218
222
  }
219
223
  var x = name.lastIndexOf('.');
220
- if(x < 0) {
224
+ if (x < 0) {
221
225
  return true;
222
226
  }
223
- var date = name.substr(log_prefix.length + 1, (x - log_prefix.length - 1));
224
- if(date.length != 8) {
227
+ var date = name.substr(log_prefix.length, (x - log_prefix.length));
228
+ if (date.length != 8) {
225
229
  return true;
226
230
  }
227
231
  var d = DateUtil.yyyymmdd(date);
228
232
  var fileUnit = DateUtil.getDateUnit(d);
229
233
  try {
230
- if (nowUnit - fileUnit > conflog_keep_days) {
231
- fs.unlinkSync(path.join(dir, files[i]));
234
+ if (nowUnit - fileUnit > conf.log_keep_days) {
235
+ fs.rmSync(filePath);
232
236
  }
233
- } catch (e) { }
237
+ } catch (e) {
238
+ }
234
239
  }
235
-
240
+
236
241
  });
237
242
  },
238
243
  read : function( file, endpos, length , callback) {
@@ -4,6 +4,7 @@ var LogSinkPack = require('../pack/log-sink-pack');
4
4
  var DataPackSender = require('../data/datapack-sender');
5
5
  var DateUtil = require('../util/dateutil')
6
6
  var ZipSend = require('./zip/zip-send');
7
+ var PiiMask = require('../pii/pii-mask')
7
8
 
8
9
  function SenderUtil() {
9
10
  this.conf = conf;
@@ -41,6 +42,10 @@ SenderUtil.prototype.send = function (log) {
41
42
 
42
43
  p.content = log.content;
43
44
 
45
+ if(conf.getProperty("pii_mask_logsink_enabled", false)){
46
+ // PiiMask.parseLogSink(p)
47
+ }
48
+
44
49
  if(conf.getProperty('logsink_zip_enabled', false)){
45
50
  ZipSend.getInstance().add(p);
46
51
  }else{
@@ -52,7 +52,7 @@ GlobalObserver.prototype.inject = function (mod, moduleName) {
52
52
  if (ctx) {
53
53
  interTxTraceAutoOn(ctx);
54
54
 
55
- if (conf.mtrace_enabled) {
55
+ if (conf.getProperty('mtrace_enabled', false)) {
56
56
  addTraceHeaders(info, ctx);
57
57
  args[1] = info;
58
58
  }
@@ -78,10 +78,10 @@ function addTraceHeaders(info, ctx) {
78
78
  'x-wtap-po': transferPOID(ctx)
79
79
  };
80
80
  }
81
- if (conf.stat_mtrace_enabled) {
81
+ if (conf.getProperty('stat_mtrace_enabled', false)) {
82
82
  info.headers[conf._trace_mtrace_spec_key1] = transferSPEC_URL(ctx);
83
83
  }
84
- if (conf.mtid_mtrace_enabled && ctx.mtid.isZero() === false) {
84
+ if (ctx.mtid.isZero() === false) {
85
85
  info.headers[conf._trace_mtrace_caller_key] = transferMTID_CALLERTX(ctx);
86
86
  }
87
87
  }
@@ -378,33 +378,31 @@ function initCtx(req, res) {
378
378
  /************************************/
379
379
  /* Multi Server Transaction Trace */
380
380
  /************************************/
381
- if(conf.mtrace_enabled) {
381
+ if(conf.getProperty('mtrace_enabled', false)) {
382
382
  var poid=req.headers['x-wtap-po'];
383
383
  if (poid != null) {
384
384
  ctx.setCallerPOID(poid);
385
385
  try{
386
- if(conf.mtid_mtrace_enabled) {
387
- var mt_caller=req.headers[conf._trace_mtrace_caller_key];
388
- if(mt_caller){
389
- var x = mt_caller.indexOf(',');
390
- if (x > 0) {
391
- ctx.mtid = Hexa32.toLong32(mt_caller.substring(0, x));
392
- ctx.mtid_build_checked = true;
393
- var y = mt_caller.indexOf(',', x + 1);
394
- if (y > 0) {
395
- ctx.mdepth = parseInt(mt_caller.substring(x + 1, y));
396
- var z = mt_caller.indexOf(',', y + 1);
397
- if (z < 0) {
398
- ctx.mcaller_txid = Hexa32.toLong32(mt_caller.substring(y + 1));
386
+ var mt_caller=req.headers[conf._trace_mtrace_caller_key];
387
+ if(mt_caller){
388
+ var x = mt_caller.indexOf(',');
389
+ if (x > 0) {
390
+ ctx.mtid = Hexa32.toLong32(mt_caller.substring(0, x));
391
+ ctx.mtid_build_checked = true;
392
+ var y = mt_caller.indexOf(',', x + 1);
393
+ if (y > 0) {
394
+ ctx.mdepth = parseInt(mt_caller.substring(x + 1, y));
395
+ var z = mt_caller.indexOf(',', y + 1);
396
+ if (z < 0) {
397
+ ctx.mcaller_txid = Hexa32.toLong32(mt_caller.substring(y + 1));
398
+ } else {
399
+ ctx.mcaller_txid = Hexa32.toLong32(mt_caller.substring(y + 1, z));
400
+
401
+ var z2 = mt_caller.indexOf(',', z + 1);
402
+ if (z2 < 0) {
403
+ ctx.mcaller_stepId = Hexa32.toLong32(mt_caller.substring(z + 1));
399
404
  } else {
400
- ctx.mcaller_txid = Hexa32.toLong32(mt_caller.substring(y + 1, z));
401
-
402
- var z2 = mt_caller.indexOf(',', z + 1);
403
- if (z2 < 0) {
404
- ctx.mcaller_stepId = Hexa32.toLong32(mt_caller.substring(z + 1));
405
- } else {
406
- ctx.mcaller_stepId = Hexa32.toLong32(mt_caller.substring(z + 1, z2));
407
- }
405
+ ctx.mcaller_stepId = Hexa32.toLong32(mt_caller.substring(z + 1, z2));
408
406
  }
409
407
  }
410
408
  }
@@ -702,7 +700,7 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
702
700
  if(conf.stat_mtrace_enabled){
703
701
  options.headers[conf._trace_mtrace_spec_key1]=transferSPEC_URL(ctx);
704
702
  }
705
- if(conf.mtid_mtrace_enabled && ctx.mtid.isZero()===false){
703
+ if(ctx.mtid.isZero()===false){
706
704
  options.headers[conf._trace_mtrace_caller_key]=transferMTID_CALLERTX(ctx);
707
705
  }
708
706
  }
@@ -757,14 +755,27 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
757
755
  }
758
756
 
759
757
  var req = original.apply(this, [options, wrappedCallback]);
758
+ var httpc_url = options.path
760
759
 
761
760
  req.on('error', function (err) {
762
761
  if (TraceContextManager.resume(ctx._id) === null) { return; }
763
- ctx.is_httpc_error = true;
762
+ const isIgnoreHttpc = shouldIgnoreError(
763
+ err.code,
764
+ httpc_url,
765
+ httpc_status_ignore,
766
+ httpc_status_ignore_set);
767
+
768
+ if (!isIgnoreHttpc && transaction_status_error_enable && step.error.isZero()) {
769
+ ctx.is_httpc_error = true;
770
+
771
+ step.error = StatError.addError(
772
+ err.code,
773
+ err.message,
774
+ ctx.service_hash,
775
+ TextTypes.HTTPC_URL,
776
+ step.url
777
+ );
764
778
 
765
- if (transaction_status_error_enable && step.error.isZero()) {
766
- step.error = StatError.addError(err.code, err.message, ctx.service_hash,
767
- TextTypes.HTTPC_URL, step.url);
768
779
  if (ctx.error.isZero()) {
769
780
  ctx.error = step.error;
770
781
  ctx.statusCode = err.code;
@@ -826,16 +837,16 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
826
837
 
827
838
  function shouldIgnoreError(statusCode, url, statusCodeIgnore, statusIgnoreSet) {
828
839
  if (statusCodeIgnore) {
829
- var ignoreCodes = statusCodeIgnore.split(',');
840
+ const ignoreCodes = statusCodeIgnore.split(',').map(code => code.trim());
830
841
  if (ignoreCodes.includes(String(statusCode))) {
831
842
  return true;
832
843
  }
833
844
  }
834
845
 
835
846
  if (statusIgnoreSet) {
836
- var ignoreSet = statusIgnoreSet.split(',');
837
- var setValue = url + ":" + statusCode;
838
- if (ignoreSet.includes(setValue)) {
847
+ const ignoreSet = statusIgnoreSet.split(',').map(item => item.trim());
848
+ const urlStatusCombo = `${url}:${statusCode}`;
849
+ if (ignoreSet.includes(urlStatusCombo)) {
839
850
  return true;
840
851
  }
841
852
  }
@@ -866,9 +877,7 @@ function updateNotFoundIgnoreMap(url, url_hash, currentTime) {
866
877
 
867
878
  function shouldEndCurrentTransaction(not_found_ignore, ctx, res, requestPath) {
868
879
  if (not_found_ignore) return false;
869
- var is_ignore = ctx.is_httpc_error ?
870
- shouldIgnoreError(res.statusCode, requestPath, httpc_status_ignore, httpc_status_ignore_set) :
871
- shouldIgnoreError(res.statusCode, requestPath, status_ignore, status_ignore_set);
880
+ const is_ignore = shouldIgnoreError(res.statusCode, requestPath, status_ignore, status_ignore_set);
872
881
  return !is_ignore;
873
882
  }
874
883
 
@@ -205,6 +205,9 @@ function createQueryHook(agent) {
205
205
  result_step.sqlhash = psql.sql;
206
206
  result_step.dbc = dbc_hash;
207
207
  ctx.profile.push(result_step);
208
+
209
+ ctx.rs_count = ctx.rs_count ? ctx.rs_count + res.length : res.length;
210
+
208
211
  MeterSql.addFetch(result_step.dbc, result_step.fetch, 0);
209
212
  StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0);
210
213
 
@@ -130,9 +130,11 @@ MssqlObserver.prototype.inject = function (mod, modName) {
130
130
  result_step.sqlhash = sql_step.hash;
131
131
  try {
132
132
  result_step.fetch = args[1][0].length;
133
+ ctx.rs_count = ctx.rs_count ? ctx.rs_count + args[1][0].length : args[1][0].length;
133
134
  } catch(e) {
134
135
  }
135
136
  ctx.profile.push(result_step);
137
+
136
138
  MeterSql.addFetch(dbc_hash, result_step.fetch, 0);
137
139
  StatSql.addFetch(dbc_hash, result_step.sqlhash, result_step.fetch, 0);
138
140
 
@@ -183,6 +183,11 @@ var queryHook = function (dbc, agent) {
183
183
  result_step.sqlhash = psql.sql;
184
184
  result_step.dbc = dbc_hash;
185
185
  ctx.profile.push(result_step);
186
+
187
+ ctx.rs_count = ctx.rs_count ? ctx.rs_count + args[1].length : args[1].length;
188
+ ctx.rs_time = ctx.rs_time ? ctx.rs_time + sql_step.elapsed : sql_step.elapsed;
189
+ // ctx.rs_time = ctx.rs_time ? ctx.rs_time + (result_step.start_time - ctx.getElapsedTime()) : result_step.start_time - ctx.getElapsedTime();
190
+
186
191
  MeterSql.addFetch(result_step.dbc, result_step.fetch, 0);
187
192
  StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0);
188
193
 
@@ -184,6 +184,9 @@ PgSqlObserver.prototype.inject = function (mod, moduleName) {
184
184
  result_step.sqlhash = psql.sql;
185
185
  result_step.dbc = dbc_hash;
186
186
  ctx.profile.push(result_step);
187
+
188
+ ctx.rs_count = ctx.rs_count ? ctx.rs_count + res.rowCount : res.rowCount;
189
+
187
190
  MeterSql.addFetch(result_step.dbc, result_step.fetch, 0);
188
191
  StatSql.addFetch(result_step.dbc, result_step.sqlhash, result_step.fetch, 0);
189
192
 
@@ -79,18 +79,18 @@ SocketIOObserver.prototype.inject = function (mod, moduleName) {
79
79
  SocketIOObserver.prototype.__handleSocketEmitEvent = function(socket, event, args) {
80
80
  if (trace_sampling_enabled) {
81
81
  var now = Date.now();
82
- if (!socket_count.start_time) {
83
- socket_count.start_time = now;
84
- }
85
-
86
- if ((now - socket_count.start_time) > 5000) {
82
+ // if ((now - socket_count.start_time) > 1000) {
83
+ // socket_count.start_time = now;
84
+ // socket_count.count = 0;
85
+ // }
86
+ if (!socket_count.start_time || (now - socket_count.start_time) >= 1000) {
87
87
  socket_count.start_time = now;
88
88
  socket_count.count = 0;
89
89
  }
90
90
 
91
91
  socket_count.count++;
92
92
  if (socket_count.count > trace_sampling_tps) {
93
- MeterService.add(0, 1, 0, 0, 0, 0);
93
+ MeterService.add(0, 1, 0, SecurityMaster.PCODE, SecurityMaster.OKIND, SecurityMaster.OID);
94
94
  return;
95
95
  }
96
96
  }
@@ -146,14 +146,11 @@ SocketIOObserver.prototype.__endTransaction = function(error, ctx) {
146
146
 
147
147
  wtx.ipaddr = ctx.remoteIp;
148
148
 
149
- MeterService.add(wtx.service, wtx.elapsed,
150
- wtx.errorLevel, ctx.mcaller_pcode, ctx.mcaller_okind, ctx.mcaller_oid);
149
+ MeterService.add(0, wtx.elapsed, 0, SecurityMaster.PCODE, SecurityMaster.OKIND, SecurityMaster.OID);
151
150
 
152
151
  profile.oid = SecurityMaster.OID;
153
152
  profile.service = wtx;
154
153
 
155
- TraceContextManager.end(ctx._id);
156
-
157
154
  setTimeout(function () {
158
155
  DataProfileAgent.sendProfile(ctx, profile, false);
159
156
  TraceContextManager.end(ctx._id);
@@ -5,7 +5,8 @@
5
5
  */
6
6
 
7
7
  var Pack = require('./pack'),
8
- PackEnum = require('./packenum');
8
+ PackEnum = require('./packenum'),
9
+ Logger = require('../logger');
9
10
 
10
11
  function HitMapPack1() {
11
12
  Pack.call(this);
@@ -51,19 +52,23 @@ HitMapPack1.prototype.read = function (din) {
51
52
  };
52
53
 
53
54
  function writeArr( dout, arr) {
54
- if(arr==null){
55
- dout.writeByte(0);
56
- }else{
57
- var len = HitMapPack1.LENGTH - 1;
58
- for (; len >= 0; len--) {
59
- if (arr[len] != 0)
60
- break;
61
- }
62
- len = len + 1;
63
- dout.writeByte(len);
64
- for (var i = 0; i < len; i++) {
65
- dout.writeShort(arr[i]);
55
+ try{
56
+ if (arr == null) {
57
+ dout.writeByte(0);
58
+ } else {
59
+ var len = HitMapPack1.LENGTH - 1;
60
+ for (; len >= 0; len--) {
61
+ if (arr[len] != 0)
62
+ break;
63
+ }
64
+ len = len + 1;
65
+ dout.writeByte(len);
66
+ for (var i = 0; i < len; i++) {
67
+ dout.writeUInt16BE(arr[i]);
68
+ }
66
69
  }
70
+ }catch (e) {
71
+ Logger.printError('WHATAP-088', 'Hit-map pack - write error', e, false);
67
72
  }
68
73
  }
69
74
 
@@ -0,0 +1,31 @@
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;
@@ -0,0 +1,174 @@
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;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "whatap",
3
3
  "homepage": "http://www.whatap.io",
4
- "version": "0.5.3",
5
- "releaseDate": "20241113",
4
+ "version": "0.5.5",
5
+ "releaseDate": "20250123",
6
6
  "description": "Monitoring and Profiling Service",
7
7
  "main": "index.js",
8
8
  "scripts": {},