Skip to content

Commit 1cda1ee

Browse files
committed
fixes for aol#262, aol#261, aol#275
1 parent 49127ae commit 1cda1ee

File tree

11 files changed

+135
-90
lines changed

11 files changed

+135
-90
lines changed

micro-event-metrics/src/main/java/com/aol/micro/server/event/metrics/MetricsCatcher.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,29 @@ public void jobComplete(JobCompleteEvent data) {
112112
jobs.complete(data.getCorrelationId());
113113
registry.counter(prefix + ".jobs-active-" + data.getType() + "-count")
114114
.dec();
115+
116+
registry.counter(prefix + ".jobs-processed-" + data.getType() + "-count-data")
117+
.inc(data.getDataSize());
118+
registry.meter(prefix + ".jobs-processed-" + data.getType() + "-meter-data")
119+
.mark(data.getDataSize());
120+
registry.counter(prefix + ".jobs-errors-" + data.getType() + "-count-data")
121+
.inc(data.getErrors());
122+
registry.meter(prefix + ".jobs-errors-" + data.getType() + "-meter-data")
123+
.mark(data.getErrors());
124+
125+
if (data.getErrors() > 0l) {
126+
registry.counter(prefix + ".jobs-succeeded-" + data.getType() + "-count")
127+
.inc();
128+
registry.meter(prefix + ".jobs-succeeded-" + data.getType() + "-meter")
129+
.mark();
130+
131+
} else {
132+
133+
registry.counter(prefix + ".jobs-failed-" + data.getType() + "-count")
134+
.inc();
135+
registry.meter(prefix + ".jobs-failed-" + data.getType() + "-meter")
136+
.mark();
137+
}
115138
}
116139
}
117140

micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherConfigOffTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void queriesCounterDec() {
8888
public void jobsCounterDec() {
8989

9090
catcher.jobComplete(new JobCompleteEvent(
91-
10l, "test"));
91+
10l, "test", 10l, 5l));
9292
assertThat(registry.counter(this.config.getPrefix() + ".jobs-active-test-count")
9393
.getCount(),
9494
equalTo(0l));

micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void queriesCounterDec() {
8989
public void jobsCounterDec() {
9090

9191
catcher.jobComplete(new JobCompleteEvent(
92-
10l, "test"));
92+
10l, "test", 10l, 5l));
9393
assertThat(registry.counter(this.config.getPrefix() + ".jobs-active-test-count")
9494
.getCount(),
9595
equalTo(-1l));

micro-events/src/main/java/com/aol/micro/server/events/ConfigureActiveJobsAspect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public JobsBeingExecuted microEventJobsBeingExecuted() {
2525
public RequestTypes microEventRequestTypes() {
2626
RequestsBeingExecuted def = this.microEventRequestsBeingExecuted();
2727
RequestTypes types = new RequestTypes(
28-
bus);
28+
bus, requestCapture);
2929
types.getMap()
3030
.put(def.getType(), def);
3131
return types;
@@ -34,7 +34,7 @@ public RequestTypes microEventRequestTypes() {
3434
@Bean
3535
public RequestsBeingExecuted microEventRequestsBeingExecuted() {
3636
return new RequestsBeingExecuted(
37-
bus, requestCapture);
37+
bus);
3838
}
3939

4040
}

micro-events/src/main/java/com/aol/micro/server/events/JobCompleteEvent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ public class JobCompleteEvent {
1212
private final Date date = new Date();
1313
private final long correlationId;
1414
private final String type;
15+
private final long errors;
16+
private final long dataSize;
1517

1618
}

micro-events/src/main/java/com/aol/micro/server/events/JobsBeingExecuted.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ private Object executeScheduledJob(final ProceedingJoinPoint pjp, final String t
8686
return retVal;
8787
} finally {
8888
logSystemEvent(pjp, type, data, retVal);
89+
retVal = Optional.ofNullable(retVal)
90+
.orElse(SystemData.builder()
91+
.correlationId("" + correlationId)
92+
.errors(0l)
93+
.processed(0l)
94+
.build());
8995
eventBus.post(new JobCompleteEvent(
90-
correlationId, type));
96+
correlationId, type, retVal.getErrors(), retVal.getProcessed()));
9197
}
9298
}
9399

micro-events/src/main/java/com/aol/micro/server/events/RequestTypes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ public class RequestTypes<T> {
2121

2222
private final EventBus bus;
2323

24-
public RequestTypes(EventBus bus) {
24+
public RequestTypes(EventBus bus, boolean queryCapture) {
2525
this.bus = bus;
26-
bus.register(this);
26+
if (queryCapture)
27+
bus.register(this);
28+
2729
}
2830

2931
@Override

micro-events/src/main/java/com/aol/micro/server/events/RequestsBeingExecuted.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ public class RequestsBeingExecuted<T> {
1616
@Getter
1717
private final String type;
1818

19-
public RequestsBeingExecuted(@Qualifier("microserverEventBus") EventBus bus, boolean queryCapture) {
19+
public RequestsBeingExecuted(@Qualifier("microserverEventBus") EventBus bus) {
2020
this.bus = bus;
2121
this.type = "default";
22-
if (queryCapture)
23-
bus.register(this);
2422

2523
}
2624

micro-events/src/main/java/com/aol/micro/server/events/SystemData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
public class SystemData<K, V> {
2020

2121
private static final Random r = new Random();
22-
private final Integer processed;
23-
private final Integer errors;
22+
private final long processed;
23+
private final long errors;
2424
private final Map<K, V> dataMap;
2525
private String correlationId;
2626

27-
private SystemData(Integer processed, Integer errors, Map<K, V> dataMap) {
27+
private SystemData(long processed, long errors, Map<K, V> dataMap) {
2828
this.processed = processed;
2929
this.errors = errors;
3030
this.dataMap = dataMap;

micro-events/src/test/java/com/aol/micro/server/events/RequestsBeingExecutedTest.java

Lines changed: 89 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -11,77 +11,94 @@
1111

1212
public class RequestsBeingExecutedTest {
1313

14-
RequestsBeingExecuted requests;
15-
EventBus bus;
16-
@Before
17-
public void setup(){
18-
bus = new EventBus();
19-
requests = new RequestsBeingExecuted(bus,true);
20-
}
21-
@Test
22-
public void oneEvent() {
23-
bus.post(RequestEvents.start("data", 100l));
24-
assertThat(requests.events(),is(1));
25-
}
26-
@Test
27-
public void twoEvents() {
28-
bus.post(RequestEvents.start("data", 100l));
29-
bus.post(RequestEvents.start("data", 120l));
30-
assertThat(requests.events(),is(2));
31-
}
32-
@Test
33-
public void twoIdenticalEvents() {
34-
bus.post(RequestEvents.start("data", 100l));
35-
bus.post(RequestEvents.start("data", 100l));
36-
assertThat(requests.events(),is(2));
37-
}
38-
39-
@Test
40-
public void oneEventSize() {
41-
bus.post(RequestEvents.start("data", 100l));
42-
assertThat(requests.size(),is(1));
43-
}
44-
@Test
45-
public void twoEventsSize() {
46-
bus.post(RequestEvents.start("data", 100l));
47-
bus.post(RequestEvents.start("data", 120l));
48-
assertThat(requests.size(),is(2));
49-
}
50-
@Test
51-
public void twoIdenticalEventsSize() {
52-
bus.post(RequestEvents.start("data", 100l));
53-
bus.post(RequestEvents.start("data", 100l));
54-
assertThat(requests.size(),is(1));
55-
}
56-
@Test
57-
public void twoEventsOneFinished() {
58-
bus.post(RequestEvents.start("data", 100l));
59-
bus.post(RequestEvents.start("data", 120l));
60-
bus.post(RequestEvents.finish("data",120l));
61-
assertThat(requests.events(),is(2));
62-
assertThat(requests.size(),is(1));
63-
}
64-
@Test
65-
public void twoEventsDifferentTypesOneFinishedDefaultTypeIsIgnored() {
66-
requests = new RequestsBeingExecuted(bus,"typeA");
67-
bus.post(RequestEvents.start("data", 130l));
68-
bus.post(RequestEvents.start("data", 120l,"typeA","data2"));
69-
bus.post(RequestEvents.finish("data",120l,"typeA"));
70-
assertThat(requests.events(),is(1));
71-
assertThat(requests.size(),is(0));
72-
}
73-
@Test
74-
public void testToString() {
75-
bus.post(RequestEvents.start("data", 100l));
76-
bus.post(RequestEvents.start("data", 120l));
77-
bus.post(RequestEvents.finish("data",120l));
78-
79-
System.out.println(requests.toString());
80-
assertThat(requests.toString(),containsString("\"removed\":1"));
81-
assertThat(requests.toString(),containsString("\"added\":2"));
82-
83-
}
84-
85-
14+
RequestsBeingExecuted requests;
15+
EventBus bus;
16+
RequestTypes types;
17+
18+
@Before
19+
public void setup() {
20+
bus = new EventBus();
21+
requests = new RequestsBeingExecuted(
22+
bus);
23+
types = new RequestTypes(
24+
bus, true);
25+
types.getMap()
26+
.put("default", requests);
27+
}
28+
29+
@Test
30+
public void oneEvent() {
31+
bus.post(RequestEvents.start("data", 100l));
32+
assertThat(requests.events(), is(1));
33+
}
34+
35+
@Test
36+
public void twoEvents() {
37+
bus.post(RequestEvents.start("data", 100l));
38+
bus.post(RequestEvents.start("data", 120l));
39+
assertThat(requests.events(), is(2));
40+
}
41+
42+
@Test
43+
public void twoIdenticalEvents() {
44+
bus.post(RequestEvents.start("data", 100l));
45+
bus.post(RequestEvents.start("data", 100l));
46+
assertThat(requests.events(), is(2));
47+
}
48+
49+
@Test
50+
public void oneEventSize() {
51+
bus.post(RequestEvents.start("data", 100l));
52+
assertThat(requests.size(), is(1));
53+
}
54+
55+
@Test
56+
public void twoEventsSize() {
57+
bus.post(RequestEvents.start("data", 100l));
58+
bus.post(RequestEvents.start("data", 120l));
59+
assertThat(requests.size(), is(2));
60+
}
61+
62+
@Test
63+
public void twoIdenticalEventsSize() {
64+
bus.post(RequestEvents.start("data", 100l));
65+
bus.post(RequestEvents.start("data", 100l));
66+
assertThat(requests.size(), is(1));
67+
}
68+
69+
@Test
70+
public void twoEventsOneFinished() {
71+
bus.post(RequestEvents.start("data", 100l));
72+
bus.post(RequestEvents.start("data", 120l));
73+
bus.post(RequestEvents.finish("data", 120l));
74+
assertThat(requests.events(), is(2));
75+
assertThat(requests.size(), is(1));
76+
}
77+
78+
@Test
79+
public void twoEventsDifferentTypesOneFinishedDefaultTypeIsIgnored() {
80+
requests = new RequestsBeingExecuted(
81+
bus, "typeA");
82+
83+
types.getMap()
84+
.put("typeA", requests);
85+
bus.post(RequestEvents.start("data", 130l));
86+
bus.post(RequestEvents.start("data", 120l, "typeA", "data2"));
87+
bus.post(RequestEvents.finish("data", 120l, "typeA"));
88+
assertThat(requests.events(), is(1));
89+
assertThat(requests.size(), is(0));
90+
}
91+
92+
@Test
93+
public void testToString() {
94+
bus.post(RequestEvents.start("data", 100l));
95+
bus.post(RequestEvents.start("data", 120l));
96+
bus.post(RequestEvents.finish("data", 120l));
97+
98+
System.out.println(requests.toString());
99+
assertThat(requests.toString(), containsString("\"removed\":1"));
100+
assertThat(requests.toString(), containsString("\"added\":2"));
101+
102+
}
86103

87104
}

micro-events/src/test/java/com/aol/micro/server/rest/resources/ActiveResourceTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
import static org.mockito.Mockito.mock;
66
import static org.mockito.Mockito.when;
77

8-
import java.util.Arrays;
98
import java.util.Map;
109

11-
import javax.ws.rs.container.AsyncResponse;
12-
1310
import org.aspectj.lang.ProceedingJoinPoint;
1411
import org.aspectj.lang.Signature;
1512
import org.junit.Before;
@@ -36,13 +33,13 @@ public class ActiveResourceTest {
3633
public void setUp() throws Exception {
3734
bus = new EventBus();
3835
queries1 = new RequestsBeingExecuted(
39-
bus, true);
36+
bus);
4037
queries2 = new RequestsBeingExecuted(
4138
bus, "partition");
4239
jobs = new JobsBeingExecuted(
4340
new EventBus(), 10);
4441
RequestTypes types = new RequestTypes(
45-
bus);
42+
bus, true);
4643
types.getMap()
4744
.put(queries1.getType(), queries1);
4845
types.getMap()

0 commit comments

Comments
 (0)