Skip to content

Commit 1b36e08

Browse files
authored
Merge pull request #126 from pagopa/release-uat
fix: Release uat
2 parents f7ef180 + 1f299e4 commit 1b36e08

18 files changed

+276
-216
lines changed

.grype.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ignore:
22
# false positive match on reactor-netty packages due to a bug on grype: https://github.com/anchore/grype/issues/431
3-
# Actually we are using netty 4.1.94
3+
# Actually we are using netty 4.1.100
44
- vulnerability: CVE-2014-3488 # solved in netty 3.9.2
55
- vulnerability: CVE-2015-2156 # solved in netty 4.1.42
66
- vulnerability: CVE-2019-16869 # solved in netty 4.1.42
@@ -15,3 +15,4 @@ ignore:
1515
- vulnerability: CVE-2022-24823 # solved in netty 4.1.77
1616
- vulnerability: CVE-2022-41881 # solved in netty 4.1.86
1717
- vulnerability: CVE-2023-34462 # solved in netty 4.1.94
18+
- vulnerability: CVE-2023-44487 # solved in netty 4.1.100

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Build
33
#
4-
FROM maven:3.9.4-amazoncorretto-17-al2023@sha256:c7719f952f62e301c6c24b86ef9a2ea1cd0a314a862ed12e51f0ffbc3fbb96b5 AS buildtime
4+
FROM maven:3.9.5-amazoncorretto-17-al2023@sha256:b7f94a5f1b6582a045692e31c2c97ef6f0ed867961669a0adbc2d5f0bbf8bc85 AS buildtime
55

66
WORKDIR /build
77
COPY . .
@@ -11,7 +11,7 @@ RUN mvn clean package -DskipTests
1111
#
1212
# Docker RUNTIME
1313
#
14-
FROM amazoncorretto:17.0.8-alpine3.18@sha256:34650d7c653af234dad21cd2d89d2f0dbdb1bad54041014932e51b3492e0dec5 AS runtime
14+
FROM amazoncorretto:17.0.9-alpine3.18@sha256:df48bf2e183230040890460ddb4359a10aa6c7aad24bd88899482c52053c7e17 AS runtime
1515

1616
RUN apk add shadow
1717
RUN useradd --uid 10000 runner
@@ -21,7 +21,7 @@ WORKDIR /app
2121

2222
COPY --from=buildtime /build/target/*.jar /app/app.jar
2323
# The agent is enabled at runtime via JAVA_TOOL_OPTIONS.
24-
ADD https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.4.16/applicationinsights-agent-3.4.16.jar /app/applicationinsights-agent.jar
24+
ADD https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.4.17/applicationinsights-agent-3.4.17.jar /app/applicationinsights-agent.jar
2525

2626
RUN chown -R runner:runner /app
2727

pom.xml

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.1.3</version>
9-
<relativePath/> <!-- lookup parent from repository -->
8+
<version>3.1.5</version>
109
</parent>
10+
1111
<groupId>it.gov.pagopa</groupId>
1212
<artifactId>idpay-transactions</artifactId>
13-
<version>1.1.0</version>
1413
<name>idpay-transactions</name>
1514
<description>Transactions Microservice</description>
15+
<version>1.1.2</version>
16+
1617
<properties>
1718
<java.version>17</java.version>
1819
</properties>
@@ -49,7 +50,7 @@
4950
<groupId>org.projectlombok</groupId>
5051
<artifactId>lombok</artifactId>
5152
<optional>true</optional>
52-
<version>1.18.28</version>
53+
<version>1.18.30</version>
5354
</dependency>
5455
<dependency>
5556
<groupId>org.apache.commons</groupId>
@@ -59,7 +60,7 @@
5960
<dependency>
6061
<groupId>org.springdoc</groupId>
6162
<artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
62-
<version>2.1.0</version>
63+
<version>2.2.0</version>
6364
</dependency>
6465
<dependency>
6566
<groupId>org.codehaus.janino</groupId>
@@ -68,30 +69,18 @@
6869
</dependency>
6970

7071
<!-- Security fixes -->
71-
<dependency>
72-
<groupId>org.yaml</groupId>
73-
<artifactId>snakeyaml</artifactId>
74-
<!-- Forced to 2.0 due to https://nvd.nist.gov/vuln/detail/CVE-2022-1471 -->
75-
<version>2.0</version>
76-
</dependency>
7772
<dependency>
7873
<groupId>org.xerial.snappy</groupId>
7974
<artifactId>snappy-java</artifactId>
80-
<!-- Forced to 2.0 due to https://nvd.nist.gov/vuln/detail/CVE-2023-34453 -->
81-
<version>1.1.10.3</version>
75+
<!-- Forced to > 1.1.10.3 due to https://nvd.nist.gov/vuln/detail/CVE-2023-34453 -->
76+
<version>1.1.10.5</version>
8277
<scope>test</scope>
8378
</dependency>
8479
<dependency>
85-
<groupId>com.squareup.okhttp3</groupId>
86-
<artifactId>okhttp</artifactId>
87-
<!-- Forced to 4.11.0 in order to update dependency of okio -->
88-
<version>4.11.0</version>
89-
</dependency>
90-
<dependency>
91-
<groupId>com.squareup.okio</groupId>
92-
<artifactId>okio</artifactId>
93-
<!-- Forced to 3.4.0 due to https://nvd.nist.gov/vuln/detail/CVE-2023-3635 -->
94-
<version>3.4.0</version>
80+
<groupId>org.yaml</groupId>
81+
<artifactId>snakeyaml</artifactId>
82+
<!-- Forced to > 2.0 due to https://nvd.nist.gov/vuln/detail/CVE-2022-1471 -->
83+
<version>2.2</version>
9584
</dependency>
9685

9786
<!--TEST-->
@@ -114,7 +103,7 @@
114103
<dependency>
115104
<groupId>de.flapdoodle.embed</groupId>
116105
<artifactId>de.flapdoodle.embed.mongo.spring30x</artifactId>
117-
<version>4.7.0</version>
106+
<version>4.9.3</version>
118107
<scope>test</scope>
119108
</dependency>
120109
<dependency>
@@ -140,6 +129,15 @@
140129
<type>pom</type>
141130
<scope>import</scope>
142131
</dependency>
132+
133+
<dependency>
134+
<groupId>io.netty</groupId>
135+
<artifactId>netty-bom</artifactId>
136+
<!-- Forced to 4.1.100 due to https://nvd.nist.gov/vuln/detail/CVE-2023-44487 -->
137+
<version>4.1.100.Final</version>
138+
<type>pom</type>
139+
<scope>import</scope>
140+
</dependency>
143141
</dependencies>
144142
</dependencyManagement>
145143
<build>

src/main/java/it/gov/pagopa/common/reactive/mongo/retry/MongoRequestRateTooLargeAutomaticRetryAspect.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package it.gov.pagopa.common.reactive.mongo.retry;
22

33
import it.gov.pagopa.common.reactive.web.ReactiveRequestContextHolder;
4+
import lombok.Generated;
45
import lombok.extern.slf4j.Slf4j;
56
import org.aspectj.lang.ProceedingJoinPoint;
67
import org.aspectj.lang.annotation.Around;
@@ -47,6 +48,12 @@ public MongoRequestRateTooLargeAutomaticRetryAspect(
4748
this.maxMillisElapsedBatch = maxMillisElapsedBatch;
4849
}
4950

51+
@Generated
52+
@Pointcut("execution(* org.springframework.data.mongodb.repository.*MongoRepository+.*(..))")
53+
public void inSpringRepositoryClass() {
54+
}
55+
56+
@Generated
5057
@Pointcut("within(*..*Repository*)")
5158
public void inRepositoryClass() {
5259
}
@@ -59,48 +66,48 @@ public void returnMono() {
5966
public void returnFlux() {
6067
}
6168

62-
@Around("inRepositoryClass() && returnMono()")
69+
@Around("(inRepositoryClass() or inSpringRepositoryClass()) && returnMono()")
6370
public Object decorateMonoRepositoryMethods(ProceedingJoinPoint pjp) throws Throwable {
6471
Mono<?> out = (Mono<?>) pjp.proceed();
65-
66-
return Mono.deferContextual(ctx -> decorateMethod(out, ctx));
72+
String flowName = pjp.getSignature().toShortString();
73+
return Mono.deferContextual(ctx -> decorateMethod(flowName, out, ctx));
6774
}
6875

69-
@Around("inRepositoryClass() && returnFlux()")
76+
@Around("(inRepositoryClass() or inSpringRepositoryClass()) && returnFlux()")
7077
public Object decorateFluxRepositoryMethods(ProceedingJoinPoint pjp) throws Throwable {
7178
@SuppressWarnings("unchecked") // only with Flux the compiler return error when using wildcard, so here we are using Object
7279
Flux<Object> out = (Flux<Object>) pjp.proceed();
73-
74-
return Flux.deferContextual(ctx -> decorateMethod(out, ctx));
80+
String flowName = pjp.getSignature().toShortString();
81+
return Flux.deferContextual(ctx -> decorateMethod(flowName, out, ctx));
7582
}
7683

77-
private <T extends Publisher<?>> T decorateMethod(T out, ContextView ctx) {
84+
private <T extends Publisher<?>> T decorateMethod(String flowName, T out, ContextView ctx) {
7885
Optional<ServerWebExchange> serverWebExchange = ctx.getOrEmpty(ReactiveRequestContextHolder.CONTEXT_KEY);
7986
if (serverWebExchange.isEmpty()) {
8087
if(enabledBatch) {
81-
return invokeWithRetry(out, maxRetryBatch, maxMillisElapsedBatch);
88+
return invokeWithRetry(flowName, out, maxRetryBatch, maxMillisElapsedBatch);
8289
}else {
8390
return out;
8491
}
8592
} else {
8693
MongoRequestRateTooLargeApiRetryable apiRetryableConfig = getRequestRateTooLargeApiRetryableConfig(serverWebExchange.get());
8794
if(apiRetryableConfig!=null){
88-
return invokeWithRetry(out, apiRetryableConfig.maxRetry(), apiRetryableConfig.maxMillisElapsed());
95+
return invokeWithRetry(flowName, out, apiRetryableConfig.maxRetry(), apiRetryableConfig.maxMillisElapsed());
8996
} else if(enabledApi){
90-
return invokeWithRetry(out, maxRetryApi, maxMillisElapsedApi);
97+
return invokeWithRetry(flowName, out, maxRetryApi, maxMillisElapsedApi);
9198
}else {
9299
return out;
93100
}
94101
}
95102
}
96103

97104
@SuppressWarnings("unchecked")
98-
private <T extends Publisher<?>> T invokeWithRetry(T out, long maxRetry, long maxMillisElapsed) {
105+
private <T extends Publisher<?>> T invokeWithRetry(String flowName, T out, long maxRetry, long maxMillisElapsed) {
99106
if(out instanceof Mono<?> mono) {
100-
return (T) MongoRequestRateTooLargeRetryer.withRetry(mono, maxRetry,
107+
return (T) MongoRequestRateTooLargeRetryer.withRetry(flowName, mono, maxRetry,
101108
maxMillisElapsed);
102109
} else {
103-
return (T) MongoRequestRateTooLargeRetryer.withRetry((Flux<?>) out, maxRetry,
110+
return (T) MongoRequestRateTooLargeRetryer.withRetry(flowName, (Flux<?>) out, maxRetry,
104111
maxMillisElapsed);
105112
}
106113
}

src/main/java/it/gov/pagopa/common/reactive/mongo/retry/MongoRequestRateTooLargeRetryer.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import it.gov.pagopa.common.reactive.mongo.retry.exception.MongoRequestRateTooLargeRetryExpiredException;
44
import lombok.extern.slf4j.Slf4j;
5-
import org.jetbrains.annotations.NotNull;
65
import org.springframework.dao.DataAccessException;
76
import reactor.core.publisher.Flux;
87
import reactor.core.publisher.Mono;
@@ -22,15 +21,15 @@ private MongoRequestRateTooLargeRetryer() {
2221

2322
private static final Pattern RETRY_AFTER_MS_PATTERN = Pattern.compile("RetryAfterMs=(\\d+)");
2423

25-
public static <T> Mono<T> withRetry(Mono<T> publisher, long maxRetry, long maxMillisElapsed){
26-
return publisher.retryWhen( buildRetry(maxRetry, maxMillisElapsed, System.currentTimeMillis()));
24+
public static <T> Mono<T> withRetry(String flowName, Mono<T> publisher, long maxRetry, long maxMillisElapsed){
25+
return publisher.retryWhen( buildRetry(flowName, maxRetry, maxMillisElapsed, System.currentTimeMillis()));
2726
}
2827

29-
public static <T> Flux<T> withRetry(Flux<T> publisher, long maxRetry, long maxMillisElapsed){
30-
return publisher.retryWhen( buildRetry(maxRetry, maxMillisElapsed, System.currentTimeMillis()));
28+
public static <T> Flux<T> withRetry(String flowName, Flux<T> publisher, long maxRetry, long maxMillisElapsed){
29+
return publisher.retryWhen( buildRetry(flowName, maxRetry, maxMillisElapsed, System.currentTimeMillis()));
3130
}
3231

33-
private static Retry buildRetry(long maxRetry, long maxMillisElapsed, long startTime) {
32+
private static Retry buildRetry(String flowName, long maxRetry, long maxMillisElapsed, long startTime) {
3433
Long[] retryAfterMs = {null};
3534
return buildBaseRetry(maxRetry)
3635
.filter(MongoRequestRateTooLargeRetryer::isRequestRateTooLargeException)
@@ -44,32 +43,30 @@ private static Retry buildRetry(long maxRetry, long maxMillisElapsed, long start
4443
}
4544

4645
if (maxMillisElapsed > 0 && millisElapsed > maxMillisElapsed){
47-
return Mono.error(buildMongoRequestRateTooLargeRetryExpiredException(maxRetry, e,
46+
return Mono.error(buildMongoRequestRateTooLargeRetryExpiredException(flowName, maxRetry, e,
4847
maxMillisElapsed, millisElapsed, retryAfterMs[0]));
4948
}
5049

5150
if (retryAfterMs[0] != null) {
5251
log.info(
53-
"[REQUEST_RATE_TOO_LARGE_RETRY] Retrying after {} ms due to RequestRateTooLargeException: attempt {} of {} after {} ms of max {} ms",
54-
retryAfterMs[0], counter, maxRetry, millisElapsed, maxMillisElapsed);
52+
"[REQUEST_RATE_TOO_LARGE_RETRY][{}] Retrying after {} ms due to RequestRateTooLargeException: attempt {} of {} after {} ms of max {} ms",
53+
flowName, retryAfterMs[0], counter, maxRetry, millisElapsed, maxMillisElapsed);
5554
return Mono.delay(Duration.ofMillis(retryAfterMs[0])).then();
5655
}else {
5756
log.info(
58-
"[REQUEST_RATE_TOO_LARGE_RETRY] Retrying for RequestRateTooLargeException: attempt {} of {} after {} ms of max {} ms",
59-
counter, maxRetry, millisElapsed, maxMillisElapsed);
57+
"[REQUEST_RATE_TOO_LARGE_RETRY][{}] Retrying for RequestRateTooLargeException: attempt {} of {} after {} ms of max {} ms",
58+
flowName, counter, maxRetry, millisElapsed, maxMillisElapsed);
6059
return Mono.empty();
6160
}
6261
})
6362
.onRetryExhaustedThrow((r, e) -> buildMongoRequestRateTooLargeRetryExpiredException(
64-
maxRetry, e, maxMillisElapsed,
63+
flowName, maxRetry, e, maxMillisElapsed,
6564
System.currentTimeMillis() - startTime, retryAfterMs[0]));
6665
}
6766

68-
69-
@NotNull
7067
private static MongoRequestRateTooLargeRetryExpiredException buildMongoRequestRateTooLargeRetryExpiredException(
71-
long maxRetry, RetrySignal e, long maxMillisElapsed, long startTime, Long retryAfterMs) {
72-
return new MongoRequestRateTooLargeRetryExpiredException(maxRetry, e.totalRetries() + 1,
68+
String flowName, long maxRetry, RetrySignal e, long maxMillisElapsed, long startTime, Long retryAfterMs) {
69+
return new MongoRequestRateTooLargeRetryExpiredException(flowName, maxRetry, e.totalRetries() + 1,
7370
maxMillisElapsed, startTime, retryAfterMs, e.failure());
7471
}
7572

@@ -89,7 +86,7 @@ public static Long getRetryAfterMs(Throwable ex) {
8986
}
9087

9188
public static boolean isRequestRateTooLargeException(Throwable ex) {
92-
return ex instanceof DataAccessException && ex.getMessage().contains("TooManyRequests");
89+
return ex instanceof DataAccessException && (ex.getMessage().contains("TooManyRequests") || ex.getMessage().contains("Error=16500,"));
9390
}
9491

9592
}

src/main/java/it/gov/pagopa/common/reactive/mongo/retry/exception/MongoRequestRateTooLargeRetryExpiredException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public class MongoRequestRateTooLargeRetryExpiredException extends RuntimeExcept
1212
private final Long retryAfterMs;
1313

1414

15-
public MongoRequestRateTooLargeRetryExpiredException(long maxRetry, long counter,
15+
public MongoRequestRateTooLargeRetryExpiredException(String flowName, long maxRetry, long counter,
1616
long maxMillisElapsed, long millisElapsed, Long retryAfterMs, Throwable cause) {
17-
super("[REQUEST_RATE_TOO_LARGE_RETRY_EXPIRED] Expired retry for RequestRateTooLargeException: attempt %d of %d after %d ms of max %d ms, suggested retry after %s ms"
18-
.formatted(counter, maxRetry, millisElapsed, maxMillisElapsed, String.valueOf(retryAfterMs)),
17+
super("[REQUEST_RATE_TOO_LARGE_RETRY_EXPIRED][%s] Expired retry for RequestRateTooLargeException: attempt %d of %d after %d ms of max %d ms, suggested retry after %s ms"
18+
.formatted(flowName, counter, maxRetry, millisElapsed, maxMillisElapsed, String.valueOf(retryAfterMs)),
1919
cause);
2020
this.maxRetry = maxRetry;
2121
this.counter = counter;

src/main/java/it/gov/pagopa/common/stream/StreamsHealthIndicator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package it.gov.pagopa.common.stream;
22

33
import lombok.NonNull;
4-
import org.springframework.beans.factory.annotation.Autowired;
54
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
65
import org.springframework.boot.actuate.health.Health;
76
import org.springframework.cloud.stream.messaging.DirectWithAttributesChannel;
@@ -23,11 +22,14 @@
2322
@GlobalChannelInterceptor
2423
public class StreamsHealthIndicator extends AbstractHealthIndicator implements ChannelInterceptor {
2524

26-
@Autowired
27-
private ApplicationContext applicationContext;
25+
private final ApplicationContext applicationContext;
2826

2927
private final Set<String> disconnectedSubscribers = new HashSet<>();
3028

29+
public StreamsHealthIndicator(ApplicationContext applicationContext) {
30+
this.applicationContext = applicationContext;
31+
}
32+
3133
@Override
3234
protected void doHealthCheck(Health.Builder builder) {
3335
Map<String, Integer> publisherSubscriptionCounts = applicationContext.getBeansOfType(DirectWithAttributesChannel.class).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getSubscriberCount()));

src/main/java/it/gov/pagopa/common/web/exception/MongoExceptionHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import it.gov.pagopa.common.reactive.mongo.retry.exception.MongoRequestRateTooLargeRetryExpiredException;
55
import it.gov.pagopa.common.web.dto.ErrorDTO;
66
import lombok.extern.slf4j.Slf4j;
7-
import org.jetbrains.annotations.NotNull;
8-
import org.springframework.beans.factory.annotation.Autowired;
97
import org.springframework.core.Ordered;
108
import org.springframework.core.annotation.Order;
119
import org.springframework.dao.DataAccessException;
@@ -23,8 +21,11 @@
2321
@Order(Ordered.HIGHEST_PRECEDENCE)
2422
public class MongoExceptionHandler {
2523

26-
@Autowired
27-
private ErrorManager errorManager;
24+
private final ErrorManager errorManager;
25+
26+
public MongoExceptionHandler(ErrorManager errorManager) {
27+
this.errorManager = errorManager;
28+
}
2829

2930
@ExceptionHandler(DataAccessException.class)
3031
protected ResponseEntity<ErrorDTO> handleDataAccessException(
@@ -46,7 +47,6 @@ protected ResponseEntity<ErrorDTO> handleMongoRequestRateTooLargeRetryExpiredExc
4647
return getErrorDTOResponseEntity(ex, request, ex.getRetryAfterMs());
4748
}
4849

49-
@NotNull
5050
private ResponseEntity<ErrorDTO> getErrorDTOResponseEntity(Exception ex,
5151
ServerWebExchange request, Long retryAfterMs) {
5252
String message = ex.getMessage();

0 commit comments

Comments
 (0)