-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconfig_loader.js
117 lines (93 loc) · 2.71 KB
/
config_loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
'use strict';
class ConfigLoader {
constructor(agent) {
let self = this;
self.agent = agent;
self.LOAD_DELAY = 2 * 1000;
self.LOAD_INTERVAL = 120 * 1000;
self.delayTimer = undefined;
self.loadTimer = undefined;
self.lastLoadTs = 0;
}
start() {
let self = this;
if (self.agent.getOption('autoProfiling')) {
self.delayTimer = self.agent.setTimeout(() => {
self.loadTimer = self.agent.setInterval(() => {
self.load((err) => {
if(err) {
self.agent.log('Error loading config');
self.agent.exception(err);
}
});
}, self.LOAD_INTERVAL);
self.load((err) => {
if(err) {
self.agent.log('Error loading config');
self.agent.exception(err);
}
});
}, self.LOAD_DELAY);
}
}
stop() {
let self = this;
if (self.delayTimer) {
clearTimeout(self.delayTimer);
self.delayTimer = undefined;
}
if (self.loadTimer) {
clearInterval(self.loadTimer);
self.loadTimer = undefined;
}
}
load(callback) {
let self = this;
let now = Date.now();
if (!self.agent.getOption('autoProfiling') && self.lastLoadTs > now - self.LOAD_INTERVAL) {
return callback(null);
}
self.lastLoadTs = now;
self.agent.apiRequest.post('config', {}, (err, res, config) => {
if (err) {
return callback(err);
}
if (config['agent_enabled'] === 'yes') {
self.agent.config.setAgentEnabled(config['agent_enabled'] == 'yes');
}
else {
self.agent.config.setAgentEnabled(false);
}
if (config['profiling_disabled'] === 'yes') {
self.agent.config.setProfilingDisabled(config['profiling_disabled'] == 'yes');
}
else {
self.agent.config.setProfilingDisabled(false);
}
if (self.agent.config.isAgentEnabled() && !self.agent.config.isProfilingDisabled()) {
self.agent.cpuReporter.start();
self.agent.allocationReporter.start();
self.agent.asyncReporter.start();
self.agent.spanReporter.start();
}
else {
self.agent.cpuReporter.stop();
self.agent.allocationReporter.stop();
self.agent.asyncReporter.stop();
self.agent.spanReporter.stop();
}
if (self.agent.config.isAgentEnabled()) {
self.agent.errorReporter.start();
self.agent.processReporter.start();
self.agent.log('Agent activated.');
}
else {
self.agent.errorReporter.stop();
self.agent.processReporter.stop();
self.agent.log('Agent deactivated.');
}
callback(null);
});
}
}
exports.ConfigLoader = ConfigLoader;