Skip to content

Commit ff12f2f

Browse files
authored
Merge pull request #1774 from grainier/latency-tracker-fix
Fix latency/throughput tracker issues
2 parents 6b804a6 + aa1c1dc commit ff12f2f

File tree

4 files changed

+76
-56
lines changed

4 files changed

+76
-56
lines changed

modules/siddhi-core/src/main/java/io/siddhi/core/aggregation/AggregationRuntime.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,13 @@ public StreamEvent find(StateEvent matchingEvent, CompiledCondition compiledCond
341341
SiddhiQueryContext siddhiQueryContext) {
342342
try {
343343
SnapshotService.getSkipStateStorageThreadLocal().set(true);
344+
if (throughputTrackerFind != null &&
345+
Level.BASIC.compareTo(siddhiQueryContext.getSiddhiAppContext().getRootMetricsLevel()) <= 0) {
346+
throughputTrackerFind.eventIn();
347+
}
344348
if (latencyTrackerFind != null &&
345349
Level.BASIC.compareTo(siddhiQueryContext.getSiddhiAppContext().getRootMetricsLevel()) <= 0) {
346350
latencyTrackerFind.markIn();
347-
throughputTrackerFind.eventIn();
348351
}
349352
if (!isDistributed && !isFirstEventArrived) {
350353
// No need to initialise executors if it is distributed

modules/siddhi-core/src/main/java/io/siddhi/core/stream/input/source/SourceMapper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public final void onEvent(Object eventObject, Object[] transportProperties, Stri
194194
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
195195
throughputTracker.eventIn();
196196
}
197-
if (throughputTracker != null &&
197+
if (mapperLatencyTracker != null &&
198198
Level.DETAIL.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
199199
mapperLatencyTracker.markIn();
200200
}
@@ -207,7 +207,7 @@ public final void onEvent(Object eventObject, Object[] transportProperties, Stri
207207
receivedEventCounter.countEvents(eventObject);
208208
}
209209
} finally {
210-
if (throughputTracker != null &&
210+
if (mapperLatencyTracker != null &&
211211
Level.DETAIL.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
212212
mapperLatencyTracker.markOut();
213213
}

modules/siddhi-core/src/main/java/io/siddhi/core/table/Table.java

+62-50
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,22 @@ private void handleStoreAddError(ComplexEventChunk addingEventChunk, boolean isF
216216
}
217217

218218
public void addEvents(ComplexEventChunk<StreamEvent> addingEventChunk, int noOfEvents) {
219-
if (latencyTrackerInsert != null &&
220-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
221-
latencyTrackerInsert.markIn();
222-
}
223-
addingEventChunk.reset();
224-
add(addingEventChunk);
225-
if (latencyTrackerInsert != null &&
226-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
227-
latencyTrackerInsert.markOut();
228-
}
229-
if (throughputTrackerInsert != null &&
230-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
231-
throughputTrackerInsert.eventsIn(noOfEvents);
219+
try {
220+
if (throughputTrackerInsert != null &&
221+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
222+
throughputTrackerInsert.eventsIn(noOfEvents);
223+
}
224+
if (latencyTrackerInsert != null &&
225+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
226+
latencyTrackerInsert.markIn();
227+
}
228+
addingEventChunk.reset();
229+
add(addingEventChunk);
230+
} finally {
231+
if (latencyTrackerInsert != null &&
232+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
233+
latencyTrackerInsert.markOut();
234+
}
232235
}
233236
}
234237

@@ -335,18 +338,21 @@ protected void onDeleteError(ComplexEventChunk<StateEvent> deletingEventChunk, C
335338

336339
public void deleteEvents(ComplexEventChunk<StateEvent> deletingEventChunk, CompiledCondition compiledCondition,
337340
int noOfEvents) {
338-
if (latencyTrackerDelete != null &&
339-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
340-
latencyTrackerDelete.markIn();
341-
}
342-
delete(deletingEventChunk, compiledCondition);
343-
if (latencyTrackerDelete != null &&
344-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
345-
latencyTrackerDelete.markOut();
346-
}
347-
if (throughputTrackerDelete != null &&
348-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
349-
throughputTrackerDelete.eventsIn(noOfEvents);
341+
try {
342+
if (throughputTrackerDelete != null &&
343+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
344+
throughputTrackerDelete.eventsIn(noOfEvents);
345+
}
346+
if (latencyTrackerDelete != null &&
347+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
348+
latencyTrackerDelete.markIn();
349+
}
350+
delete(deletingEventChunk, compiledCondition);
351+
} finally {
352+
if (latencyTrackerDelete != null &&
353+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
354+
latencyTrackerDelete.markOut();
355+
}
350356
}
351357
}
352358

@@ -418,18 +424,21 @@ protected void onUpdateError(ComplexEventChunk<StateEvent> updatingEventChunk, C
418424
public void updateEvents(ComplexEventChunk<StateEvent> updatingEventChunk,
419425
CompiledCondition compiledCondition,
420426
CompiledUpdateSet compiledUpdateSet, int noOfEvents) {
421-
if (latencyTrackerUpdate != null &&
422-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
423-
latencyTrackerUpdate.markIn();
424-
}
425-
update(updatingEventChunk, compiledCondition, compiledUpdateSet);
426-
if (latencyTrackerUpdate != null &&
427-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
428-
latencyTrackerUpdate.markOut();
429-
}
430-
if (throughputTrackerUpdate != null &&
431-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
432-
throughputTrackerUpdate.eventsIn(noOfEvents);
427+
try {
428+
if (throughputTrackerUpdate != null &&
429+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
430+
throughputTrackerUpdate.eventsIn(noOfEvents);
431+
}
432+
if (latencyTrackerUpdate != null &&
433+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
434+
latencyTrackerUpdate.markIn();
435+
}
436+
update(updatingEventChunk, compiledCondition, compiledUpdateSet);
437+
} finally {
438+
if (latencyTrackerUpdate != null &&
439+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
440+
latencyTrackerUpdate.markOut();
441+
}
433442
}
434443
}
435444

@@ -506,19 +515,22 @@ public void updateOrAddEvents(ComplexEventChunk<StateEvent> updateOrAddingEventC
506515
CompiledCondition compiledCondition,
507516
CompiledUpdateSet compiledUpdateSet,
508517
AddingStreamEventExtractor addingStreamEventExtractor, int noOfEvents) {
509-
if (latencyTrackerUpdateOrInsert != null &&
510-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
511-
latencyTrackerUpdateOrInsert.markIn();
512-
}
513-
updateOrAdd(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet,
514-
addingStreamEventExtractor);
515-
if (latencyTrackerUpdateOrInsert != null &&
516-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
517-
latencyTrackerUpdateOrInsert.markOut();
518-
}
519-
if (throughputTrackerUpdateOrInsert != null &&
520-
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
521-
throughputTrackerUpdateOrInsert.eventsIn(noOfEvents);
518+
try {
519+
if (throughputTrackerUpdateOrInsert != null &&
520+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
521+
throughputTrackerUpdateOrInsert.eventsIn(noOfEvents);
522+
}
523+
if (latencyTrackerUpdateOrInsert != null &&
524+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
525+
latencyTrackerUpdateOrInsert.markIn();
526+
}
527+
updateOrAdd(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet,
528+
addingStreamEventExtractor);
529+
} finally {
530+
if (latencyTrackerUpdateOrInsert != null &&
531+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
532+
latencyTrackerUpdateOrInsert.markOut();
533+
}
522534
}
523535
}
524536

modules/siddhi-core/src/main/java/io/siddhi/core/window/Window.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,15 @@ public void add(ComplexEventChunk complexEventChunk) {
238238
if (throughputTrackerInsert != null &&
239239
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
240240
throughputTrackerInsert.eventsIn(numberOfEvents);
241+
}
242+
if (latencyTrackerInsert != null &&
243+
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
241244
latencyTrackerInsert.markIn();
242245
}
243246
// Send to the window windowProcessor
244247
windowProcessor.process(new ComplexEventChunk<>(firstEvent, currentEvent));
245248
} finally {
246-
if (throughputTrackerInsert != null &&
249+
if (latencyTrackerInsert != null &&
247250
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
248251
latencyTrackerInsert.markOut();
249252
}
@@ -261,11 +264,13 @@ public StreamEvent find(StateEvent matchingEvent, CompiledCondition compiledCond
261264
try {
262265
if (throughputTrackerFind != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
263266
throughputTrackerFind.eventIn();
267+
}
268+
if (latencyTrackerFind != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
264269
latencyTrackerFind.markIn();
265270
}
266271
return ((FindableProcessor) this.internalWindowProcessor).find(matchingEvent, compiledCondition);
267272
} finally {
268-
if (throughputTrackerFind != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
273+
if (latencyTrackerFind != null && Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
269274
latencyTrackerFind.markOut();
270275
}
271276
}
@@ -330,7 +335,7 @@ private class StreamPublishProcessor implements Processor {
330335
}
331336

332337
public void process(ComplexEventChunk complexEventChunk) {
333-
if (throughputTrackerInsert != null &&
338+
if (latencyTrackerInsert != null &&
334339
Level.BASIC.compareTo(siddhiAppContext.getRootMetricsLevel()) <= 0) {
335340
latencyTrackerInsert.markOut();
336341
}

0 commit comments

Comments
 (0)