From 7d633203af0902e850476e229be610c4148e87c6 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Wed, 28 Aug 2024 18:12:47 +0800 Subject: [PATCH 01/10] fix --- api/configs/feature/__init__.py | 14 +++++++------- .../nodes/http_request/http_request_node.py | 15 ++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index f2efa52de3ecba..a08ce9b2e762ef 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -1,6 +1,6 @@ from typing import Optional -from pydantic import AliasChoices, Field, HttpUrl, NegativeInt, NonNegativeInt, PositiveInt, computed_field +from pydantic import AliasChoices, Field, HttpUrl, NegativeInt, NonNegativeInt, PositiveInt, computed_field, conint from pydantic_settings import BaseSettings from configs.feature.hosted_service import HostedServiceConfig @@ -217,18 +217,18 @@ def CONSOLE_CORS_ALLOW_ORIGINS(self) -> list[str]: def WEB_API_CORS_ALLOW_ORIGINS(self) -> list[str]: return self.inner_WEB_API_CORS_ALLOW_ORIGINS.split(",") - HTTP_REQUEST_MAX_CONNECT_TIMEOUT: NonNegativeInt = Field( - description="", + HTTP_REQUEST_MAX_CONNECT_TIMEOUT: conint(ge=10) = Field( + description="connect timeout in seconds for HTTP request, which should be no less than 60", default=300, ) - HTTP_REQUEST_MAX_READ_TIMEOUT: NonNegativeInt = Field( - description="", + HTTP_REQUEST_MAX_READ_TIMEOUT: conint(ge=60) = Field( + description="read timeout in seconds for HTTP request, which should be no less than 60", default=600, ) - HTTP_REQUEST_MAX_WRITE_TIMEOUT: NonNegativeInt = Field( - description="", + HTTP_REQUEST_MAX_WRITE_TIMEOUT: conint(ge=10) = Field( + description="read timeout in seconds for HTTP request, which should be no less than 10", default=600, ) diff --git a/api/core/workflow/nodes/http_request/http_request_node.py b/api/core/workflow/nodes/http_request/http_request_node.py index f6c8ea3c83422d..037a7a1848ccfa 100644 --- a/api/core/workflow/nodes/http_request/http_request_node.py +++ b/api/core/workflow/nodes/http_request/http_request_node.py @@ -19,9 +19,9 @@ from models.workflow import WorkflowNodeExecutionStatus HTTP_REQUEST_DEFAULT_TIMEOUT = HttpRequestNodeTimeout( - connect=min(10, dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT), - read=min(60, dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT), - write=min(20, dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT), + connect=dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT, + read=dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT, + write=dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT, ) @@ -96,12 +96,9 @@ def _get_request_timeout(node_data: HttpRequestNodeData) -> HttpRequestNodeTimeo if timeout is None: return HTTP_REQUEST_DEFAULT_TIMEOUT - timeout.connect = min(timeout.connect or HTTP_REQUEST_DEFAULT_TIMEOUT.connect, - dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT) - timeout.read = min(timeout.read or HTTP_REQUEST_DEFAULT_TIMEOUT.read, - dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT) - timeout.write = min(timeout.write or HTTP_REQUEST_DEFAULT_TIMEOUT.write, - dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUT) + timeout.connect = timeout.connect or HTTP_REQUEST_DEFAULT_TIMEOUT.connect + timeout.read = timeout.read or HTTP_REQUEST_DEFAULT_TIMEOUT.read + timeout.write = timeout.write or HTTP_REQUEST_DEFAULT_TIMEOUT.write return timeout @classmethod From 6cbb2a042b32fb6c78e5bc3007261d79fe45ffb7 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Thu, 29 Aug 2024 20:32:57 +0800 Subject: [PATCH 02/10] default values --- api/configs/feature/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index a08ce9b2e762ef..b33b866aaa050c 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -219,17 +219,17 @@ def WEB_API_CORS_ALLOW_ORIGINS(self) -> list[str]: HTTP_REQUEST_MAX_CONNECT_TIMEOUT: conint(ge=10) = Field( description="connect timeout in seconds for HTTP request, which should be no less than 60", - default=300, + default=10, ) HTTP_REQUEST_MAX_READ_TIMEOUT: conint(ge=60) = Field( description="read timeout in seconds for HTTP request, which should be no less than 60", - default=600, + default=60, ) HTTP_REQUEST_MAX_WRITE_TIMEOUT: conint(ge=10) = Field( description="read timeout in seconds for HTTP request, which should be no less than 10", - default=600, + default=20, ) HTTP_REQUEST_NODE_MAX_BINARY_SIZE: PositiveInt = Field( From 27c255da3ea8563b7c111c0fda66ecae3f870c2d Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Thu, 29 Aug 2024 20:36:26 +0800 Subject: [PATCH 03/10] replace deprecated conint --- api/configs/feature/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index b33b866aaa050c..405338837cbdf1 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -2,6 +2,7 @@ from pydantic import AliasChoices, Field, HttpUrl, NegativeInt, NonNegativeInt, PositiveInt, computed_field, conint from pydantic_settings import BaseSettings +from typing_extensions import Annotated from configs.feature.hosted_service import HostedServiceConfig @@ -217,17 +218,17 @@ def CONSOLE_CORS_ALLOW_ORIGINS(self) -> list[str]: def WEB_API_CORS_ALLOW_ORIGINS(self) -> list[str]: return self.inner_WEB_API_CORS_ALLOW_ORIGINS.split(",") - HTTP_REQUEST_MAX_CONNECT_TIMEOUT: conint(ge=10) = Field( + HTTP_REQUEST_MAX_CONNECT_TIMEOUT: Annotated[int, Field(ge=10)] = Field( description="connect timeout in seconds for HTTP request, which should be no less than 60", default=10, ) - HTTP_REQUEST_MAX_READ_TIMEOUT: conint(ge=60) = Field( + HTTP_REQUEST_MAX_READ_TIMEOUT: Annotated[int, Field(ge=60)] = Field( description="read timeout in seconds for HTTP request, which should be no less than 60", default=60, ) - HTTP_REQUEST_MAX_WRITE_TIMEOUT: conint(ge=10) = Field( + HTTP_REQUEST_MAX_WRITE_TIMEOUT: Annotated[int, Field(ge=10)] = Field( description="read timeout in seconds for HTTP request, which should be no less than 10", default=20, ) From 28f2eea5a7161191cb8dca39a13fff9d920ed76a Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Thu, 29 Aug 2024 20:59:17 +0800 Subject: [PATCH 04/10] fix --- api/configs/feature/__init__.py | 40 ++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index 405338837cbdf1..4160241fa94af9 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -1,8 +1,7 @@ -from typing import Optional +from typing import Annotated, Optional from pydantic import AliasChoices, Field, HttpUrl, NegativeInt, NonNegativeInt, PositiveInt, computed_field, conint from pydantic_settings import BaseSettings -from typing_extensions import Annotated from configs.feature.hosted_service import HostedServiceConfig @@ -218,20 +217,29 @@ def CONSOLE_CORS_ALLOW_ORIGINS(self) -> list[str]: def WEB_API_CORS_ALLOW_ORIGINS(self) -> list[str]: return self.inner_WEB_API_CORS_ALLOW_ORIGINS.split(",") - HTTP_REQUEST_MAX_CONNECT_TIMEOUT: Annotated[int, Field(ge=10)] = Field( - description="connect timeout in seconds for HTTP request, which should be no less than 60", - default=10, - ) - - HTTP_REQUEST_MAX_READ_TIMEOUT: Annotated[int, Field(ge=60)] = Field( - description="read timeout in seconds for HTTP request, which should be no less than 60", - default=60, - ) - - HTTP_REQUEST_MAX_WRITE_TIMEOUT: Annotated[int, Field(ge=10)] = Field( - description="read timeout in seconds for HTTP request, which should be no less than 10", - default=20, - ) + HTTP_REQUEST_MAX_CONNECT_TIMEOUT: Annotated[int, Field(ge=10)] = Annotated[ + int, + Field( + description="connect timeout in seconds for HTTP request, which should be no less than 60", + default=10, + ), + ] + + HTTP_REQUEST_MAX_READ_TIMEOUT: Annotated[int, Field(ge=60)] = Annotated[ + int, + Field( + description="read timeout in seconds for HTTP request, which should be no less than 60", + default=60, + ), + ] + + HTTP_REQUEST_MAX_WRITE_TIMEOUT: Annotated[int, Field(ge=10)] = Annotated[ + int, + Field( + description="read timeout in seconds for HTTP request, which should be no less than 10", + default=20, + ), + ] HTTP_REQUEST_NODE_MAX_BINARY_SIZE: PositiveInt = Field( description="", From ba1c9161a6b73df25b9ea88c23253222c829e492 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Thu, 29 Aug 2024 21:39:19 +0800 Subject: [PATCH 05/10] fix --- api/configs/feature/__init__.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index 4160241fa94af9..a802a7a4fb21bf 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -217,29 +217,25 @@ def CONSOLE_CORS_ALLOW_ORIGINS(self) -> list[str]: def WEB_API_CORS_ALLOW_ORIGINS(self) -> list[str]: return self.inner_WEB_API_CORS_ALLOW_ORIGINS.split(",") - HTTP_REQUEST_MAX_CONNECT_TIMEOUT: Annotated[int, Field(ge=10)] = Annotated[ - int, - Field( - description="connect timeout in seconds for HTTP request, which should be no less than 60", - default=10, - ), - ] + HTTP_REQUEST_MAX_CONNECT_TIMEOUT: Annotated[ + int, Field(ge=10, description="connect timeout in seconds for HTTP request, which should be no less than 60") + ] = 10 - HTTP_REQUEST_MAX_READ_TIMEOUT: Annotated[int, Field(ge=60)] = Annotated[ + HTTP_REQUEST_MAX_READ_TIMEOUT: Annotated[ int, Field( + ge=60, description="read timeout in seconds for HTTP request, which should be no less than 60", - default=60, ), - ] + ] = 60 - HTTP_REQUEST_MAX_WRITE_TIMEOUT: Annotated[int, Field(ge=10)] = Annotated[ + HTTP_REQUEST_MAX_WRITE_TIMEOUT: Annotated[ int, Field( + ge=10, description="read timeout in seconds for HTTP request, which should be no less than 10", - default=20, ), - ] + ] = 20 HTTP_REQUEST_NODE_MAX_BINARY_SIZE: PositiveInt = Field( description="", From 3dda5129194de37fa6b69156624500d4914ff6cd Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Thu, 29 Aug 2024 21:48:55 +0800 Subject: [PATCH 06/10] update --- api/tests/unit_tests/configs/test_dify_config.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/tests/unit_tests/configs/test_dify_config.py b/api/tests/unit_tests/configs/test_dify_config.py index fb415483dd39ad..e7d7b842219009 100644 --- a/api/tests/unit_tests/configs/test_dify_config.py +++ b/api/tests/unit_tests/configs/test_dify_config.py @@ -19,6 +19,7 @@ def example_env_file(tmp_path, monkeypatch) -> str: """ CONSOLE_API_URL=https://example.com CONSOLE_WEB_URL=https://example.com + HTTP_REQUEST_MAX_WRITE_TIMEOUT=20 """ ) ) @@ -48,6 +49,12 @@ def test_dify_config(example_env_file): assert config.API_COMPRESSION_ENABLED is False assert config.SENTRY_TRACES_SAMPLE_RATE == 1.0 + # annotated field with default value + assert config.HTTP_REQUEST_MAX_READ_TIMEOUT == 60 + + # annotated field with configured value + assert config.HTTP_REQUEST_MAX_WRITE_TIMEOUT == 20 + # NOTE: If there is a `.env` file in your Workspace, this test might not succeed as expected. # This is due to `pymilvus` loading all the variables from the `.env` file into `os.environ`. From ddb9249fab0d0bad0963ac4d2a7b456907261199 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Thu, 29 Aug 2024 21:50:18 +0800 Subject: [PATCH 07/10] update --- api/tests/unit_tests/configs/test_dify_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/tests/unit_tests/configs/test_dify_config.py b/api/tests/unit_tests/configs/test_dify_config.py index e7d7b842219009..3f639ccacc48f5 100644 --- a/api/tests/unit_tests/configs/test_dify_config.py +++ b/api/tests/unit_tests/configs/test_dify_config.py @@ -19,7 +19,7 @@ def example_env_file(tmp_path, monkeypatch) -> str: """ CONSOLE_API_URL=https://example.com CONSOLE_WEB_URL=https://example.com - HTTP_REQUEST_MAX_WRITE_TIMEOUT=20 + HTTP_REQUEST_MAX_WRITE_TIMEOUT=30 """ ) ) @@ -53,7 +53,7 @@ def test_dify_config(example_env_file): assert config.HTTP_REQUEST_MAX_READ_TIMEOUT == 60 # annotated field with configured value - assert config.HTTP_REQUEST_MAX_WRITE_TIMEOUT == 20 + assert config.HTTP_REQUEST_MAX_WRITE_TIMEOUT == 30 # NOTE: If there is a `.env` file in your Workspace, this test might not succeed as expected. From 8ad117c1a90936bbaa7bb0c0d2f69d4243dad200 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Thu, 29 Aug 2024 22:09:03 +0800 Subject: [PATCH 08/10] update --- api/configs/feature/__init__.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index a802a7a4fb21bf..37b972af78ccd7 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -218,23 +218,15 @@ def WEB_API_CORS_ALLOW_ORIGINS(self) -> list[str]: return self.inner_WEB_API_CORS_ALLOW_ORIGINS.split(",") HTTP_REQUEST_MAX_CONNECT_TIMEOUT: Annotated[ - int, Field(ge=10, description="connect timeout in seconds for HTTP request, which should be no less than 60") + int, Field(ge=10, description="connect timeout in seconds for HTTP request") ] = 10 HTTP_REQUEST_MAX_READ_TIMEOUT: Annotated[ - int, - Field( - ge=60, - description="read timeout in seconds for HTTP request, which should be no less than 60", - ), + int, Field(ge=60, description="read timeout in seconds for HTTP request") ] = 60 HTTP_REQUEST_MAX_WRITE_TIMEOUT: Annotated[ - int, - Field( - ge=10, - description="read timeout in seconds for HTTP request, which should be no less than 10", - ), + int, Field(ge=10, description="read timeout in seconds for HTTP request") ] = 20 HTTP_REQUEST_NODE_MAX_BINARY_SIZE: PositiveInt = Field( From 5db1715ce685b48321ad483c9e4831c14601727b Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Thu, 29 Aug 2024 22:09:48 +0800 Subject: [PATCH 09/10] update --- api/configs/feature/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index 37b972af78ccd7..9db6d69d6b9b24 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -218,15 +218,15 @@ def WEB_API_CORS_ALLOW_ORIGINS(self) -> list[str]: return self.inner_WEB_API_CORS_ALLOW_ORIGINS.split(",") HTTP_REQUEST_MAX_CONNECT_TIMEOUT: Annotated[ - int, Field(ge=10, description="connect timeout in seconds for HTTP request") + PositiveInt, Field(ge=10, description="connect timeout in seconds for HTTP request") ] = 10 HTTP_REQUEST_MAX_READ_TIMEOUT: Annotated[ - int, Field(ge=60, description="read timeout in seconds for HTTP request") + PositiveInt, Field(ge=60, description="read timeout in seconds for HTTP request") ] = 60 HTTP_REQUEST_MAX_WRITE_TIMEOUT: Annotated[ - int, Field(ge=10, description="read timeout in seconds for HTTP request") + PositiveInt, Field(ge=10, description="read timeout in seconds for HTTP request") ] = 20 HTTP_REQUEST_NODE_MAX_BINARY_SIZE: PositiveInt = Field( From fb360cf45d452d5c06066af67b04aee5ae830e49 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Thu, 29 Aug 2024 22:11:04 +0800 Subject: [PATCH 10/10] update --- api/configs/feature/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index 9db6d69d6b9b24..303bce2aa5050c 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -1,6 +1,6 @@ from typing import Annotated, Optional -from pydantic import AliasChoices, Field, HttpUrl, NegativeInt, NonNegativeInt, PositiveInt, computed_field, conint +from pydantic import AliasChoices, Field, HttpUrl, NegativeInt, NonNegativeInt, PositiveInt, computed_field from pydantic_settings import BaseSettings from configs.feature.hosted_service import HostedServiceConfig