Skip to content

Commit

Permalink
Merge pull request #5475 from Skanetrafiken/log-azure-siri-errors
Browse files Browse the repository at this point in the history
Add logging of siri errors to SiriAzureETUpdater
  • Loading branch information
Bartosz-Kruba authored Nov 6, 2023
2 parents fb85e6d + a842ae8 commit 4e6fcba
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.opentripplanner.ext.siri.updater.azure;

import static net.logstash.logback.argument.StructuredArguments.keyValue;

import com.azure.messaging.servicebus.ServiceBusErrorContext;
import com.azure.messaging.servicebus.ServiceBusReceivedMessageContext;
import jakarta.xml.bind.JAXBException;
Expand All @@ -14,11 +16,14 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import javax.xml.stream.XMLStreamException;
import org.apache.hc.core5.net.URIBuilder;
import org.opentripplanner.ext.siri.SiriTimetableSnapshotSource;
import org.opentripplanner.framework.time.DurationUtils;
import org.opentripplanner.transit.service.TransitModel;
import org.opentripplanner.updater.spi.ResultLogger;
import org.opentripplanner.updater.spi.UpdateError;
import org.opentripplanner.updater.spi.UpdateResult;
import org.opentripplanner.updater.trip.metrics.TripUpdateMetrics;
import org.rutebanken.siri20.util.SiriXml;
Expand Down Expand Up @@ -106,13 +111,15 @@ private void processMessage(String message, String id) {
}

super.saveResultOnGraph.execute((graph, transitModel) -> {
snapshotSource.applyEstimatedTimetable(
var result = snapshotSource.applyEstimatedTimetable(
fuzzyTripMatcher(),
entityResolver(),
feedId,
false,
updates
);
ResultLogger.logUpdateResultErrors(feedId, "siri-et", result);
recordMetrics.accept(result);
});
} catch (JAXBException | XMLStreamException e) {
LOG.error(e.getLocalizedMessage(), e);
Expand All @@ -138,6 +145,7 @@ private void processHistory(String message, String id) {
false,
updates
);
ResultLogger.logUpdateResultErrors(feedId, "siri-et", result);
recordMetrics.accept(result);

setPrimed(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.ext.siri.updater.azure;

import com.azure.core.amqp.implementation.ConnectionStringProperties;
import java.time.LocalDate;
import org.opentripplanner.updater.trip.UrlUpdaterParameters;

Expand All @@ -23,6 +24,11 @@ public void setFromDateTime(LocalDate fromDateTime) {

@Override
public String url() {
return getDataInitializationUrl();
var url = getServiceBusUrl();
try {
return new ConnectionStringProperties(url).getEndpoint().toString();
} catch (IllegalArgumentException e) {
return url;
}
}
}
38 changes: 22 additions & 16 deletions src/main/java/org/opentripplanner/updater/spi/ResultLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,30 @@ public static void logUpdateResult(String feedId, String type, UpdateResult upda
DoubleUtils.roundTo2Decimals((double) updateResult.successful() / totalUpdates * 100)
);

var errorIndex = updateResult.failures();

errorIndex
.keySet()
.forEach(key -> {
var value = errorIndex.get(key);
var tripIds = value.stream().map(UpdateError::debugId).collect(Collectors.toSet());
LOG.warn(
"[{} {}] {} failures of {}: {}",
keyValue("feedId", feedId),
keyValue("type", type),
value.size(),
keyValue("errorType", key),
tripIds
);
});
logUpdateResultErrors(feedId, type, updateResult);
} else {
LOG.info("[feedId={}, type={}] Feed did not contain any updates", feedId, type);
}
}

public static void logUpdateResultErrors(String feedId, String type, UpdateResult updateResult) {
if (updateResult.failed() == 0) {
return;
}
var errorIndex = updateResult.failures();
errorIndex
.keySet()
.forEach(key -> {
var value = errorIndex.get(key);
var tripIds = value.stream().map(UpdateError::debugId).collect(Collectors.toSet());
LOG.warn(
"[{} {}] {} failures of {}: {}",
keyValue("feedId", feedId),
keyValue("type", type),
value.size(),
keyValue("errorType", key),
tripIds
);
});
}
}

0 comments on commit 4e6fcba

Please sign in to comment.