33import com .exceptionless .exceptionlessclient .configuration .ConfigurationManager ;
44import com .exceptionless .exceptionlessclient .models .Event ;
55import com .exceptionless .exceptionlessclient .models .EventPluginContext ;
6- import com .exceptionless .exceptionlessclient .models .error .Error ;
7- import com .exceptionless .exceptionlessclient .models .error .InnerError ;
86import com .exceptionless .exceptionlessclient .plugins .EventPluginIF ;
97import com .exceptionless .exceptionlessclient .plugins .MergedEvent ;
108import lombok .Builder ;
119import lombok .Getter ;
12- import lombok .extern .slf4j .Slf4j ;
10+ import org .slf4j .Logger ;
11+ import org .slf4j .LoggerFactory ;
1312
1413import java .util .*;
1514
16- @ Slf4j
17- public class DuplicateErrorCheckerPlugin implements EventPluginIF {
15+ public class DuplicateCheckerPlugin implements EventPluginIF {
16+ private static final Logger LOG = LoggerFactory . getLogger ( DuplicateCheckerPlugin . class );
1817 private static final String MERGED_EVENTS_RESUBMISSION_TIMER_NAME =
1918 "merged-events-resubmission-timer" ;
2019 private static final Integer DEFAULT_PRIORITY = 1010 ;
@@ -28,8 +27,7 @@ public class DuplicateErrorCheckerPlugin implements EventPluginIF {
2827 private final Integer mergedEventsResubmissionInSecs ;
2928
3029 @ Builder
31- public DuplicateErrorCheckerPlugin (
32- Integer mergedEventsResubmissionInSecs , Integer maxHashesCount ) {
30+ public DuplicateCheckerPlugin (Integer mergedEventsResubmissionInSecs , Integer maxHashesCount ) {
3331 this .maxHashesCount = maxHashesCount == null ? DEFAULT_MAX_HASHES_COUNT : maxHashesCount ;
3432 this .mergedEvents = new ArrayDeque <>();
3533 this .mergedEventsResubmissionTimer = new Timer (MERGED_EVENTS_RESUBMISSION_TIMER_NAME );
@@ -52,7 +50,7 @@ public void run() {
5250 event .resubmit ();
5351 }
5452 } catch (Exception e ) {
55- log .error ("Error in resubmitting merged events" , e );
53+ LOG .error ("Error in resubmitting merged events" , e );
5654 }
5755 }
5856 },
@@ -69,20 +67,14 @@ public int getPriority() {
6967 public void run (
7068 EventPluginContext eventPluginContext , ConfigurationManager configurationManager ) {
7169 Event event = eventPluginContext .getEvent ();
72- Optional <Error > maybeError = event .getError ();
73- if (maybeError .isEmpty ()) {
74- return ;
75- }
76- Error error = maybeError .get ();
77-
78- long hash = getHashCode (error );
70+ long hash = getHash (event );
7971 Optional <MergedEvent > maybeMergedEvent =
8072 mergedEvents .stream ().filter (mergedEvent -> mergedEvent .getHash () == hash ).findFirst ();
8173 if (maybeMergedEvent .isPresent ()) {
8274 MergedEvent mergedEvent = maybeMergedEvent .get ();
8375 mergedEvent .incrementCount (event .getCount ());
8476 mergedEvent .updateDate (event .getDate ());
85- log .info (String .format ("Ignoring duplicate event with hash: %s" , hash ));
77+ LOG .info (String .format ("Ignoring duplicate event with hash: %s" , hash ));
8678 eventPluginContext .getContext ().setEventCancelled (true );
8779 return ;
8880 }
@@ -96,7 +88,7 @@ public void run(
9688 timeStampedHash .getHash () == hash
9789 && timeStampedHash .getTimestamp ()
9890 >= (now - mergedEventsResubmissionInSecs * 1000 ))) {
99- log .trace (String .format ("Adding event with hash :%s" , hash ));
91+ LOG .trace (String .format ("Adding event with hash :%s" , hash ));
10092 mergedEvents .add (
10193 MergedEvent .builder ()
10294 .event (event )
@@ -118,13 +110,16 @@ private void addNewHashIfPossible(long hash, long now) {
118110 hashes .add (TimeStampedHash .builder ().hash (hash ).timestamp (now ).build ());
119111 }
120112
121- private long getHashCode (InnerError error ) {
122- long hash = 0L ;
123- while (error != null ) {
124- hash += Objects .hash (error .getMessage (), error .getStackTrace ());
125- error = error .getInner ();
126- }
127- return hash ;
113+ private long getHash (Event event ) {
114+ return Objects .hash (
115+ event .getType (),
116+ event .getSource (),
117+ event .getDate (),
118+ event .getTags (),
119+ event .getMessage (),
120+ event .getData (),
121+ event .getGeo (),
122+ event .getValue ());
128123 }
129124
130125 @ Builder
0 commit comments