Make Response Timeout Configurable in WebClient Configuration 37/139937/3
authorsourabh_sourabh <sourabh.sourabh@est.tech>
Thu, 16 Jan 2025 13:00:18 +0000 (13:00 +0000)
committersourabh_sourabh <sourabh.sourabh@est.tech>
Thu, 16 Jan 2025 16:11:18 +0000 (16:11 +0000)
- Added responseTimeoutInSeconds property in the ServiceConfig class to allow dynamic configuration of the timeout.
- Updated WebClientConfiguration to read the responseTimeoutInSeconds from ServiceConfig and set it in the HttpClient.

Issue-ID: CPS-2565
Change-Id: I096688319c55f0342b524511883ec0d33806b9b7
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
cps-application/src/main/resources/application.yml
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/config/ServiceConfig.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/http/WebClientConfiguration.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/config/DmiHttpClientConfigSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/config/PolicyExecutorHttpClientConfigSpec.groovy

index 573db1f..27a15b6 100644 (file)
@@ -207,6 +207,7 @@ ncmp:
                 connectionTimeoutInSeconds: 30
                 readTimeoutInSeconds: 30
                 writeTimeoutInSeconds: 30
+                responseTimeoutInSeconds: 60
     dmi:
         httpclient:
             data-services:
@@ -216,6 +217,7 @@ ncmp:
                 connectionTimeoutInSeconds: 30
                 readTimeoutInSeconds: 30
                 writeTimeoutInSeconds: 30
+                responseTimeoutInSeconds: 60
             model-services:
                 maximumInMemorySizeInMegabytes: 16
                 maximumConnectionsTotal: 100
@@ -223,6 +225,7 @@ ncmp:
                 connectionTimeoutInSeconds: 30
                 readTimeoutInSeconds: 30
                 writeTimeoutInSeconds: 30
+                responseTimeoutInSeconds: 60
         auth:
             username: ${DMI_USERNAME:cpsuser}
             password: ${DMI_PASSWORD:cpsr0cks!}
index f1fce0c..775e9d7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2024 Nordix Foundation.
+ *  Copyright (C) 2024-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -33,4 +33,5 @@ public abstract class ServiceConfig {
     private Integer connectionTimeoutInSeconds = 1;
     private long readTimeoutInSeconds = 1;
     private long writeTimeoutInSeconds = 1;
+    private long responseTimeoutInSeconds = 60;
 }
index eefabd1..0214c0c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2024 Nordix Foundation.
+ *  Copyright (C) 2024-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -41,8 +41,6 @@ import reactor.netty.resources.ConnectionProvider;
  */
 public class WebClientConfiguration {
 
-    private static final Duration DEFAULT_RESPONSE_TIMEOUT = Duration.ofSeconds(30);
-
     protected WebClient configureWebClient(final WebClient.Builder webClientBuilder,
                                            final ServiceConfig serviceConfig) {
         final ConnectionProvider connectionProvider = getConnectionProvider(serviceConfig);
@@ -53,7 +51,7 @@ public class WebClientConfiguration {
     private static HttpClient createHttpClient(final ServiceConfig serviceConfig,
                                                final ConnectionProvider connectionProvider) {
         return HttpClient.create(connectionProvider)
-                .responseTimeout(DEFAULT_RESPONSE_TIMEOUT)
+                .responseTimeout(Duration.ofSeconds(serviceConfig.getResponseTimeoutInSeconds()))
                 .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, serviceConfig.getConnectionTimeoutInSeconds() * 1000)
                 .doOnConnected(connection -> connection.addHandlerLast(new ReadTimeoutHandler(
                         serviceConfig.getReadTimeoutInSeconds(), TimeUnit.SECONDS)).addHandlerLast(
index 23f5edd..387252e 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2023-2024 Nordix Foundation.
+ *  Copyright (C) 2023-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@ class DmiHttpClientConfigSpec extends Specification {
                 assert connectionTimeoutInSeconds == 4
                 assert readTimeoutInSeconds == 5
                 assert writeTimeoutInSeconds == 6
+                assert responseTimeoutInSeconds == 60
             }
     }
 
@@ -56,6 +57,7 @@ class DmiHttpClientConfigSpec extends Specification {
                 assert connectionTimeoutInSeconds == 14
                 assert readTimeoutInSeconds == 15
                 assert writeTimeoutInSeconds == 16
+                assert responseTimeoutInSeconds == 60
             }
     }
 
@@ -68,6 +70,7 @@ class DmiHttpClientConfigSpec extends Specification {
                 assert connectionTimeoutInSeconds == 24
                 assert readTimeoutInSeconds == 25
                 assert writeTimeoutInSeconds == 26
+                assert responseTimeoutInSeconds == 60
             }
     }
 }
index b988f9e..3df9103 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2024 Nordix Foundation.
+ *  Copyright (C) 2024-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@ class PolicyExecutorHttpClientConfigSpec extends Specification {
                 assert pendingAcquireMaxCount == 33
                 assert connectionTimeoutInSeconds == 34
                 assert writeTimeoutInSeconds == 36
+                assert responseTimeoutInSeconds == 60
             }
     }