Skip to content

Commit

Permalink
Added some more monitoring / debugging capabilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
Asgeir Nilsen committed Nov 4, 2017
1 parent f7a2b91 commit d99978e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/main/java/no/fint/provider/events/admin/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
import no.fint.provider.events.subscriber.DownstreamSubscriber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.net.URI;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -41,6 +47,14 @@ public class AdminController {
public List<MongoAuditEvent> getAllEvents() {
return mongoTemplate.findAll(MongoAuditEvent.class);
}

@GetMapping("/audit/events/since/{when}")
public List<MongoAuditEvent> queryEventsSince(@PathVariable String when) {
Duration duration = Duration.parse(when);
Criteria c = Criteria.where("timestamp").gt(ZonedDateTime.now().minus(duration).toInstant().toEpochMilli());
Query q = new Query(c);
return mongoTemplate.find(q, MongoAuditEvent.class);
}

@DeleteMapping("/tempQueues")
public boolean deleteTempQueues() {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/no/fint/provider/events/sse/FintSseEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import lombok.EqualsAndHashCode;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

@Data
@EqualsAndHashCode(callSuper = true)
public class FintSseEmitter extends SseEmitter {
private String id;
private String registered;
private final AtomicInteger pendingEvents = new AtomicInteger();

public FintSseEmitter() {
setRegisteredDate();
Expand All @@ -27,4 +30,13 @@ private void setRegisteredDate() {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
registered = formatter.format(new Date());
}

@Override
public void send(SseEventBuilder builder) throws IOException {
pendingEvents.incrementAndGet();
super.send(builder);
pendingEvents.decrementAndGet();
}


}
1 change: 1 addition & 0 deletions src/main/java/no/fint/provider/events/sse/SseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
public class SseClient {
private String registered;
private String id;
private int pending;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<SseOrg> getClients() {
List<SseOrg> orgs = new ArrayList<>();
clients.forEach((key, value) -> {
List<SseClient> sseClients = new ArrayList<>();
value.forEach(emitter -> sseClients.add(new SseClient(emitter.getRegistered(), emitter.getId())));
value.forEach(emitter -> sseClients.add(new SseClient(emitter.getRegistered(), emitter.getId(), emitter.getPendingEvents().get())));

orgs.add(new SseOrg(key, sseClients));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DownstreamSubscriber {

@FintEventListener
public void receive(Event event) {
log.info("Event received: {}", event.getAction());
log.info("Event received: {} for {}", event.getAction(), event.getOrgId());
if (event.isHealthCheck()) {
event.addObject(new Health(Constants.COMPONENT, HealthStatus.RECEIVED_IN_PROVIDER_FROM_CONSUMER));
}
Expand Down

0 comments on commit d99978e

Please sign in to comment.