Skip to content

Commit 343603b

Browse files
authored
Merge pull request #4129 from zlamalp/logging
refactor(dispatcher): optimized logging in event processing
2 parents 64e0246 + b84a55e commit 343603b

File tree

7 files changed

+45
-34
lines changed

7 files changed

+45
-34
lines changed

perun-dispatcher/src/main/java/cz/metacentrum/perun/dispatcher/jms/EngineMessageConsumer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,19 @@ public void run() {
106106
while (!shouldStop()) {
107107

108108
producer = producerFactory.getProducer();
109-
109+
110110
// Step 11. Deliver output and try to receive the message
111111
TextMessage messageReceived = null;
112112
try {
113113
if(producer != null) {
114114
producer.deliverOutputMessages();
115115
}
116116

117-
log.debug("Gonna call messageConsumer.receive(timeout)...");
117+
log.trace("Gonna call messageConsumer.receive(timeout)...");
118118
messageReceived = (TextMessage) messageConsumer.receive(timeout);
119119
if (messageReceived != null) {
120-
if (log.isDebugEnabled()) {
121-
log.debug("System message received [" + messageReceived.getText() + "]");
120+
if (log.isTraceEnabled()) {
121+
log.trace("System message received [" + messageReceived.getText() + "]");
122122
}
123123
try {
124124
engineMessageProcessor.processEngineMessage(messageReceived.getText());
@@ -129,8 +129,8 @@ public void run() {
129129
}
130130
messageReceived.acknowledge();
131131
} else {
132-
if (log.isDebugEnabled()) {
133-
log.debug("No message available...");
132+
if (log.isTraceEnabled()) {
133+
log.trace("No message available...");
134134
}
135135
}
136136
} catch (JMSException e) {

perun-dispatcher/src/main/java/cz/metacentrum/perun/dispatcher/jms/EngineMessageProcessor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ public void startProcessingSystemMessages() {
140140
if(outputMessages == null) {
141141
outputMessages = new LinkedBlockingDeque<TextMessage>();
142142
}
143-
143+
144144
connection = null;
145145
try {
146146
if(restartHornetQServer) {
147147
engineMessageProducerFactory.removeProducer();
148148
perunHornetQServer.stopServer();
149149
perunHornetQServer.startServer();
150150
}
151-
151+
152152
// Step 2. Instantiate the TransportConfiguration object which
153153
// contains the knowledge of what transport to use,
154154
// The server port etc.
@@ -289,12 +289,12 @@ protected void processEngineMessage(String message) throws PerunHornetQServerExc
289289

290290
// process expected messages
291291
EngineMessageProducer engineMessageProducer;
292-
292+
293293
if (clientMessageSplitter[0].equalsIgnoreCase("register")) {
294294

295295
// Do we have this queue already?
296296
engineMessageProducer = engineMessageProducerFactory.getProducer();
297-
297+
298298
if (engineMessageProducer != null) {
299299
// ...and close all tasks that could have been running there
300300
schedulingPool.closeTasksForEngine();

perun-dispatcher/src/main/java/cz/metacentrum/perun/dispatcher/jms/EngineMessageProducer.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ public void sendMessage(String text) {
8383

8484
/**
8585
* Try to deliver all pending messages.
86-
* @throws JMSException
87-
*
86+
* @throws JMSException
87+
*
8888
*/
8989
public void deliverOutputMessages() throws JMSException {
9090
while(!outputMessages.isEmpty()) {
9191
TextMessage message = outputMessages.poll();
9292
producer.send(message);
9393
if (log.isDebugEnabled()) {
94-
log.debug("Sent message (queue:" + queueName + "): " + message.getText());
94+
log.debug("Sent message (queue name:" + queueName + "): " + message.getText());
9595
}
9696
}
9797
}
98-
98+
9999
/**
100100
* Get name of the queue for engine.
101101
*
@@ -105,14 +105,13 @@ public String getQueueName() {
105105
return queueName;
106106
}
107107

108-
/**
108+
/**
109109
* Shutdown before destroying the producer.
110-
*
111110
*/
112111
public void shutdown() {
113112
try {
114113
producer.close();
115-
// session is not not ours to close
114+
// session is not ours to close
116115
// session.close();
117116
} catch (JMSException e) {
118117
log.error(e.toString(), e);

perun-dispatcher/src/main/java/cz/metacentrum/perun/dispatcher/processing/EventProcessor.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,17 @@ public void run() {
134134
try {
135135
Event event = eventQueue.take();
136136
createTaskFromEvent(event);
137-
log.debug("Remaining events in a Queue = {}", eventQueue.size());
137+
log.trace("Remaining events in a Queue = {}", eventQueue.size());
138138
} catch (Exception e) {
139139
log.error(e.getMessage(), e);
140140
}
141141
}
142-
log.debug("EventProcessor has stopped.");
142+
log.warn("EventProcessor has stopped.");
143143
}
144144

145145
/**
146146
* Creates Task from Event data. Tries to resolve Service and Facility pairs from Event.
147-
* Events for non existing entities are discarded.
147+
* Events for non-existing entities are discarded.
148148
*
149149
* @param event Event to parse
150150
* @throws ServiceNotExistsException When Service from Event doesn't exists anymore
@@ -160,12 +160,20 @@ private void createTaskFromEvent(Event event) throws ServiceNotExistsException,
160160
Facility facility = map.getKey();
161161
for (Service service : map.getValue()) {
162162
if (!service.isEnabled()) {
163-
log.debug("Service not enabled: {}.", service);
163+
if (log.isDebugEnabled()) {
164+
log.debug("Service disabled: {}.", service);
165+
} else {
166+
log.info("Service disabled: {}.", service.getId() + " / " + service.getName());
167+
}
164168
continue;
165169
}
166170

167171
if (((PerunBl) perun).getServicesManagerBl().isServiceBlockedOnFacility(service, facility)) {
168-
log.debug("Service blocked on Facility: {} , {}.", service, facility);
172+
if (log.isDebugEnabled()) {
173+
log.debug("Service blocked on Facility: {} , {}.", service, facility);
174+
} else {
175+
log.info("Service blocked on Facility: {} , {}.", service.getId() + " / " + service.getName(), facility.getId() + " / " + facility.getName());
176+
}
169177
continue;
170178
}
171179

@@ -198,7 +206,12 @@ private void createTaskFromEvent(Event event) throws ServiceNotExistsException,
198206
if (destinations.isEmpty()) {
199207
// All service destinations were blocked -> Task is denied to be sent to engine just like
200208
// when service is blocked globally in Perun or on facility as a whole.
201-
log.debug("{} blocked on all destinations on {}.", service, facility);
209+
210+
if (log.isDebugEnabled()) {
211+
log.debug("{} blocked on all destinations on {}.", service, facility);
212+
} else {
213+
log.info("Service: {} blocked on all destinations on Facility: {}.", service.getId() + " / " + service.getName(), facility.getId() + " / " + facility.getName());
214+
}
202215
continue;
203216
}
204217
}
@@ -227,7 +240,7 @@ private void createTaskFromEvent(Event event) throws ServiceNotExistsException,
227240
task.setSourceUpdated(true);
228241
if (isForced) task.setPropagationForced(true);
229242
task.setRecurrence(0);
230-
log.debug("[{}] Task is already in pool. Re-setting source updated and forced flags, {}.", task.getId(), task);
243+
log.info("[{}] Task is already in pool. Re-setting source updated and forced flags, {}.", task.getId(), task);
231244
} else {
232245
// no such task yet, create one
233246
task = new Task();
@@ -241,7 +254,7 @@ private void createTaskFromEvent(Event event) throws ServiceNotExistsException,
241254
task.setPropagationForced(isForced);
242255
try {
243256
schedulingPool.addToPool(task);
244-
log.debug("[{}] New Task added to pool. {}.", task.getId(), task);
257+
log.info("[{}] New Task added to pool. {}.", task.getId(), task);
245258
} catch (TaskStoreException e) {
246259
log.error("[{}] Could not add Task to pool. Task {} will be lost: {}", task.getId(), task, e);
247260
}

perun-dispatcher/src/main/java/cz/metacentrum/perun/dispatcher/processing/impl/EventServiceResolverImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ public void setPerun(Perun perun) {
8585
@Override
8686
public Map<Facility, Set<Service>> resolveEvent(AuditEvent event) throws InvalidEventMessageException, ServiceNotExistsException, PrivilegeException {
8787

88-
log.info("Event - I am going to process event: {}", event);
89-
9088
Map<Facility, Set<Service>> result = new HashMap<Facility, Set<Service>>();
9189

9290
if (event instanceof EngineIgnoreEvent) {
93-
log.info("Event ignored {} facilities will be returned", result.size());
91+
log.debug("Event {} ignored 0 facilities will be returned", event.getName());
9492
return result;
9593
}
9694

95+
log.info("Event - I am going to process event: {}", event);
96+
9797
// GET All Beans (only PerunBeans) from message
9898
List<PerunBean> listOfBeans = new ArrayList<PerunBean>();
9999
listOfBeans = AuditParser.parseLog(event.getMessage());
@@ -282,7 +282,7 @@ public Map<Facility, Set<Service>> resolveEvent(AuditEvent event) throws Invalid
282282
}
283283
}
284284

285-
log.info("{} facilities will be returned", result.size());
285+
log.debug("{} facilities will be returned", result.size());
286286
return result;
287287

288288
}

perun-notification/src/main/java/cz/metacentrum/perun/notif/dao/jdbc/PerunNotifAuditMessageDaoImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package cz.metacentrum.perun.notif.dao.jdbc;
22

3-
import cz.metacentrum.perun.core.api.exceptions.InternalErrorException;
43
import cz.metacentrum.perun.core.impl.Utils;
54
import cz.metacentrum.perun.notif.dao.PerunNotifAuditMessageDao;
65
import cz.metacentrum.perun.notif.entities.PerunNotifAuditMessage;
@@ -29,22 +28,22 @@ public PerunNotifAuditMessage save(String message) {
2928
int newPerunNotifAuditMessageId = Utils.getNewId(this.getJdbcTemplate(), "pn_audit_message_id_seq");
3029
this.getJdbcTemplate().update("INSERT INTO pn_audit_message(id, message) values (?,?)", newPerunNotifAuditMessageId, message);
3130

32-
logger.debug("PerunNotifAuditMessage saved to db: id = {} message = {}", newPerunNotifAuditMessageId, message);
31+
logger.trace("PerunNotifAuditMessage saved to db: id = {} message = {}", newPerunNotifAuditMessageId, message);
3332
return new PerunNotifAuditMessage(newPerunNotifAuditMessageId, message);
3433
}
3534

3635
public void remove(long id) {
3736

3837
logger.debug("Removing perunNotifAuditMessage with id = {}", id);
3938
this.getJdbcTemplate().update("delete from pn_audit_message where id=?", id);
40-
logger.debug("PerunNotifAuditMessage with id: {} removed.", id);
39+
logger.trace("PerunNotifAuditMessage with id: {} removed.", id);
4140
}
4241

4342
public List<PerunNotifAuditMessage> getAll() {
4443

4544
logger.debug("Listing all perunNotifAuditMessages.");
4645
List<PerunNotifAuditMessage> result = this.getJdbcTemplate().query("SELECT * FROM pn_audit_message", PerunNotifAuditMessage.PERUN_NOTIF_MESSAGE);
47-
logger.debug("Result of list of PerunNotifAuditMessage: {}", result);
46+
logger.trace("Result of list of PerunNotifAuditMessage: {}", result);
4847
return result;
4948
}
5049
}

perun-notification/src/main/java/cz/metacentrum/perun/notif/managers/SchedulingManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void processPerunAuditMessages() {
133133
private void processPerunNotifAuditMessage(PerunNotifAuditMessage perunAuditMessage, PerunSession session) throws Exception {
134134

135135
try {
136-
logger.debug("Getting regexIds, matching received message with id: " + perunAuditMessage.getId());
136+
logger.trace("Getting regexIds, matching received message with id: " + perunAuditMessage.getId());
137137
Set<Integer> regexIds = perunNotifRegexManager.getIdsOfRegexesMatchingMessage(perunAuditMessage);
138138
logger.debug("Received regexIds for message with id: " + perunAuditMessage.getId() + "; regexIds = " + regexIds + "; now getting templateIds.");
139139
if (regexIds == null || regexIds.isEmpty()) {

0 commit comments

Comments
 (0)