Skip to content

Commit 31a10a8

Browse files
committed
reduce logging for skipped records even more
1 parent 6426261 commit 31a10a8

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

writer/src/main/java/com/opendatahub/timeseries/bdp/writer/dal/MeasurementAbstractHistory.java

+17-10
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
import java.util.ArrayList;
1010
import java.util.Date;
1111
import java.util.HashMap;
12+
import java.util.HashSet;
1213
import java.util.List;
1314
import java.util.Map;
1415
import java.util.Map.Entry;
16+
import java.util.function.BiConsumer;
17+
import java.util.function.Consumer;
1518
import java.util.function.Function;
1619

1720
import org.slf4j.Logger;
@@ -174,6 +177,10 @@ public static void pushRecords(EntityManager em, String stationType, DataMapDto<
174177
throw new JPAException(String.format("Provenance with UUID %s not found", dataMap.getProvenance()));
175178
}
176179
log.setProvenance(provenance);
180+
181+
var skippedDataTypes = new HashSet<String>();
182+
int skippedCount = 0;
183+
177184
for (Entry<String, DataMapDto<RecordDtoImpl>> stationEntry : dataMap.getBranch().entrySet()) {
178185
Station station = Station.findStation(em, stationType, stationEntry.getKey());
179186
if (station == null) {
@@ -245,7 +252,6 @@ public static void pushRecords(EntityManager em, String stationType, DataMapDto<
245252
}
246253
}
247254

248-
int skippedRecs = 0;
249255
for (Period period : periods.values()) {
250256
period.number.updateLatest(em, (newest) -> {
251257
return new Measurement(station, type, ((Number) newest.getValue()).doubleValue(),
@@ -262,13 +268,8 @@ public static void pushRecords(EntityManager em, String stationType, DataMapDto<
262268
period.period);
263269
});
264270

265-
skippedRecs = skippedRecs + period.skippedRecs;
266-
}
267-
268-
if (skippedRecs > 0) {
269-
log.warn(String.format("Skipped %d records due to timestamp for type: [%s, %s, %s]",
270-
skippedRecs,
271-
station.stationtype, station.stationcode, type.getCname()));
271+
skippedDataTypes.add(type.getCname());
272+
skippedCount += period.skippedCount;
272273
}
273274

274275
em.getTransaction().commit();
@@ -283,6 +284,12 @@ public static void pushRecords(EntityManager em, String stationType, DataMapDto<
283284
}
284285
}
285286
}
287+
288+
if (skippedCount > 0) {
289+
log.warn(String.format("Skipped %d records due to timestamp for type: [%s, (%s)]",
290+
skippedCount,
291+
stationType, String.join(", ", skippedDataTypes)));
292+
}
286293
} catch (Exception e) {
287294
if (em.getTransaction().isActive())
288295
em.getTransaction().rollback();
@@ -303,7 +310,7 @@ private static class Period {
303310
private DataType type;
304311
private Integer period;
305312
private Provenance provenance;
306-
public int skippedRecs = 0;
313+
public int skippedCount = 0;
307314

308315
private class TimeSeries {
309316
private MeasurementAbstract latest;
@@ -332,7 +339,7 @@ public void addHistory(EntityManager em, Log log, SimpleRecordDto dto, Measureme
332339
} else {
333340
LOG.debug(String.format("Skipping record due to timestamp: [%s, %s, %s, %d, %d]",
334341
station.stationtype, station.stationcode, type.getCname(), period, dto.getTimestamp()));
335-
skippedRecs++;
342+
skippedCount++;
336343
}
337344
}
338345

0 commit comments

Comments
 (0)