Skip to content

Commit

Permalink
Add subscription update interceptor to add systemId to update logs
Browse files Browse the repository at this point in the history
  • Loading branch information
testower committed Sep 9, 2024
1 parent 820dee1 commit 771c79a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<okhttp.version>4.12.0</okhttp.version>
<kryo.version>5.6.0</kryo.version>
<jackson.version>2.17.2</jackson.version>
<gbfs-loader-java.version>4.0.10</gbfs-loader-java.version>
<gbfs-loader-java.version>4.0.11</gbfs-loader-java.version>
<gbfs-validator-java.version>2.0.7</gbfs-validator-java.version>
<gbfs-mapper-java.version>2.0.8</gbfs-mapper-java.version>
<prettier-java.version>2.1.0</prettier-java.version>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/entur/lamassu/leader/FeedUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ private void createSubscription(FeedProvider feedProvider) {
enableValidation
);

var interceptor = new LoggingSubscriptionUpdateInterceptor(feedProvider);

String id;

if (feedProvider.getVersion() != null && feedProvider.getVersion().startsWith("3")) {
Expand All @@ -150,7 +152,8 @@ private void createSubscription(FeedProvider feedProvider) {
);
receiveV3Update(feedProvider, gbfsV3Delivery);
cacheReady.set(true);
}
},
interceptor
);
} else {
id =
Expand All @@ -164,7 +167,8 @@ private void createSubscription(FeedProvider feedProvider) {
GbfsFeedVersionMappers.map(gbfsV2Delivery, feedProvider.getLanguage())
);
cacheReady.set(true);
}
},
interceptor
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
*
* * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
* * the European Commission - subsequent versions of the EUPL (the "Licence");
* * You may not use this work except in compliance with the Licence.
* * You may obtain a copy of the Licence at:
* *
* * https://joinup.ec.europa.eu/software/page/eupl
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the Licence is distributed on an "AS IS" basis,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the Licence for the specific language governing permissions and
* * limitations under the Licence.
*
*/

package org.entur.lamassu.leader;

import org.entur.gbfs.SubscriptionUpdateInterceptor;
import org.entur.lamassu.model.provider.FeedProvider;
import org.slf4j.MDC;

public class LoggingSubscriptionUpdateInterceptor implements SubscriptionUpdateInterceptor {
private final FeedProvider feedProvider;

public LoggingSubscriptionUpdateInterceptor(
FeedProvider feedProvider
) {
this.feedProvider = feedProvider;
}
@Override
public void beforeUpdate() {
MDC.put("systemId", feedProvider.getSystemId());
}

@Override
public void afterUpdate() {
MDC.remove("systemId");
}
}
3 changes: 3 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"serviceContext": {
"service": "lamassu"
},
"mdc": {
"systemId": "%X{systemId}"
},
"message": "%message\n%ex{full}",
"severity": "%level",
"reportLocation": {
Expand Down

0 comments on commit 771c79a

Please sign in to comment.