3
3
import com .exceptionless .exceptionlessclient .configuration .ConfigurationManager ;
4
4
import com .exceptionless .exceptionlessclient .models .Event ;
5
5
import com .exceptionless .exceptionlessclient .models .EventPluginContext ;
6
- import com .exceptionless .exceptionlessclient .models .error .Error ;
7
- import com .exceptionless .exceptionlessclient .models .error .InnerError ;
8
6
import com .exceptionless .exceptionlessclient .plugins .EventPluginIF ;
9
7
import com .exceptionless .exceptionlessclient .plugins .MergedEvent ;
10
8
import lombok .Builder ;
11
9
import lombok .Getter ;
12
- import lombok .extern .slf4j .Slf4j ;
10
+ import org .slf4j .Logger ;
11
+ import org .slf4j .LoggerFactory ;
13
12
14
13
import java .util .*;
15
14
16
- @ Slf4j
17
- public class DuplicateErrorCheckerPlugin implements EventPluginIF {
15
+ public class DuplicateCheckerPlugin implements EventPluginIF {
16
+ private static final Logger LOG = LoggerFactory . getLogger ( DuplicateCheckerPlugin . class );
18
17
private static final String MERGED_EVENTS_RESUBMISSION_TIMER_NAME =
19
18
"merged-events-resubmission-timer" ;
20
19
private static final Integer DEFAULT_PRIORITY = 1010 ;
@@ -28,8 +27,7 @@ public class DuplicateErrorCheckerPlugin implements EventPluginIF {
28
27
private final Integer mergedEventsResubmissionInSecs ;
29
28
30
29
@ Builder
31
- public DuplicateErrorCheckerPlugin (
32
- Integer mergedEventsResubmissionInSecs , Integer maxHashesCount ) {
30
+ public DuplicateCheckerPlugin (Integer mergedEventsResubmissionInSecs , Integer maxHashesCount ) {
33
31
this .maxHashesCount = maxHashesCount == null ? DEFAULT_MAX_HASHES_COUNT : maxHashesCount ;
34
32
this .mergedEvents = new ArrayDeque <>();
35
33
this .mergedEventsResubmissionTimer = new Timer (MERGED_EVENTS_RESUBMISSION_TIMER_NAME );
@@ -52,7 +50,7 @@ public void run() {
52
50
event .resubmit ();
53
51
}
54
52
} catch (Exception e ) {
55
- log .error ("Error in resubmitting merged events" , e );
53
+ LOG .error ("Error in resubmitting merged events" , e );
56
54
}
57
55
}
58
56
},
@@ -69,20 +67,14 @@ public int getPriority() {
69
67
public void run (
70
68
EventPluginContext eventPluginContext , ConfigurationManager configurationManager ) {
71
69
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 );
79
71
Optional <MergedEvent > maybeMergedEvent =
80
72
mergedEvents .stream ().filter (mergedEvent -> mergedEvent .getHash () == hash ).findFirst ();
81
73
if (maybeMergedEvent .isPresent ()) {
82
74
MergedEvent mergedEvent = maybeMergedEvent .get ();
83
75
mergedEvent .incrementCount (event .getCount ());
84
76
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 ));
86
78
eventPluginContext .getContext ().setEventCancelled (true );
87
79
return ;
88
80
}
@@ -96,7 +88,7 @@ public void run(
96
88
timeStampedHash .getHash () == hash
97
89
&& timeStampedHash .getTimestamp ()
98
90
>= (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 ));
100
92
mergedEvents .add (
101
93
MergedEvent .builder ()
102
94
.event (event )
@@ -118,13 +110,16 @@ private void addNewHashIfPossible(long hash, long now) {
118
110
hashes .add (TimeStampedHash .builder ().hash (hash ).timestamp (now ).build ());
119
111
}
120
112
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 ());
128
123
}
129
124
130
125
@ Builder
0 commit comments