Skip to content

Commit

Permalink
Add logging of siri errors to SiriAzureETUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
habrahamsson-skanetrafiken committed Nov 3, 2023
1 parent a9b0151 commit 35ebd1a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 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,13 @@
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.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 +110,15 @@ private void processMessage(String message, String id) {
}

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

setPrimed(true);
Expand Down Expand Up @@ -174,4 +181,25 @@ private List<EstimatedTimetableDeliveryStructure> getUpdates(String message, Str

return siri.getServiceDelivery().getEstimatedTimetableDeliveries();
}

private void logErrors(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", "siri-et"),
value.size(),
keyValue("errorType", key),
tripIds
);
});
}
}
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;
}
}
}

0 comments on commit 35ebd1a

Please sign in to comment.