Skip to content

Commit 387b561

Browse files
committed
Ref #34306: fix issues with CSV collector and Micrometer
1 parent 2c5264a commit 387b561

3 files changed

Lines changed: 207 additions & 167 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/stat/impl/AbstractDbCollector.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.slf4j.LoggerFactory;
3535
import org.springframework.context.ApplicationEvent;
3636
import org.springframework.context.event.EventListener;
37+
import org.springframework.scheduling.annotation.Async;
3738
import org.springframework.security.core.Authentication;
3839

3940
import javax.inject.Inject;
@@ -48,23 +49,27 @@ public abstract class AbstractDbCollector implements IStatCollector {
4849
private SpecExpressionResolver specExpressionResolver;
4950
private final Logger logger = LoggerFactory.getLogger(getClass());
5051

52+
@Async
5153
@EventListener
5254
public void onUserLogoutEvent(UserLogoutEvent event) throws IOException {
5355
writeToDb(event, event.getTimestamp(), event.getUserId(), "Logout", null, event.getAuthentication());
5456
}
5557

58+
@Async
5659
@EventListener
5760
public void onUserLoginEvent(UserLoginEvent event) throws IOException {
5861
writeToDb(event, event.getTimestamp(), event.getUserId(), "Login", null, event.getAuthentication());
5962
}
6063

64+
@Async
6165
@EventListener
6266
public void onProxyStartEvent(ProxyStartEvent event) throws IOException {
6367
if (event.isLocalEvent()) {
6468
writeToDb(event,event.getTimestamp(), event.getUserId(), "ProxyStart", event.getSpecId(), event.getAuthentication());
6569
}
6670
}
6771

72+
@Async
6873
@EventListener
6974
public void onProxyStopEvent(ProxyStopEvent event) throws IOException {
7075
if (event.isLocalEvent()) {

src/main/java/eu/openanalytics/containerproxy/stat/impl/CSVCollector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ public void init() throws IOException {
107107

108108
schema = schemaBuilder.build();
109109
writer = csvMapper.writer(schema).writeValues(fileWriter);
110+
schema = schemaBuilder.setUseHeader(false).build(); // don't write header when writer re-starts
110111
}
111112

112113
@Override
113-
protected void writeToDb(ApplicationEvent event, long timestamp, String userId, String type, String data, Authentication authentication) throws IOException {
114+
protected synchronized void writeToDb(ApplicationEvent event, long timestamp, String userId, String type, String data, Authentication authentication) {
114115
try {
115116
Map<String, String> row = new HashMap<>();
116117
for (String column : schema.getColumnNames()) {

0 commit comments

Comments
 (0)