unrealon 1.0.9__py3-none-any.whl → 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unrealon/__init__.py +23 -21
- unrealon-1.1.1.dist-info/METADATA +722 -0
- unrealon-1.1.1.dist-info/RECORD +82 -0
- {unrealon-1.0.9.dist-info → unrealon-1.1.1.dist-info}/WHEEL +1 -1
- unrealon-1.1.1.dist-info/entry_points.txt +9 -0
- {unrealon-1.0.9.dist-info → unrealon-1.1.1.dist-info/licenses}/LICENSE +1 -1
- unrealon_bridge/__init__.py +114 -0
- unrealon_bridge/cli.py +316 -0
- unrealon_bridge/client/__init__.py +93 -0
- unrealon_bridge/client/base.py +78 -0
- unrealon_bridge/client/commands.py +89 -0
- unrealon_bridge/client/connection.py +90 -0
- unrealon_bridge/client/events.py +65 -0
- unrealon_bridge/client/health.py +38 -0
- unrealon_bridge/client/html_parser.py +146 -0
- unrealon_bridge/client/logging.py +139 -0
- unrealon_bridge/client/proxy.py +70 -0
- unrealon_bridge/client/scheduler.py +450 -0
- unrealon_bridge/client/session.py +70 -0
- unrealon_bridge/configs/__init__.py +14 -0
- unrealon_bridge/configs/bridge_config.py +212 -0
- unrealon_bridge/configs/bridge_config.yaml +39 -0
- unrealon_bridge/models/__init__.py +138 -0
- unrealon_bridge/models/base.py +28 -0
- unrealon_bridge/models/command.py +41 -0
- unrealon_bridge/models/events.py +40 -0
- unrealon_bridge/models/html_parser.py +79 -0
- unrealon_bridge/models/logging.py +55 -0
- unrealon_bridge/models/parser.py +63 -0
- unrealon_bridge/models/proxy.py +41 -0
- unrealon_bridge/models/requests.py +95 -0
- unrealon_bridge/models/responses.py +88 -0
- unrealon_bridge/models/scheduler.py +592 -0
- unrealon_bridge/models/session.py +28 -0
- unrealon_bridge/server/__init__.py +91 -0
- unrealon_bridge/server/base.py +171 -0
- unrealon_bridge/server/handlers/__init__.py +23 -0
- unrealon_bridge/server/handlers/command.py +110 -0
- unrealon_bridge/server/handlers/html_parser.py +139 -0
- unrealon_bridge/server/handlers/logging.py +95 -0
- unrealon_bridge/server/handlers/parser.py +95 -0
- unrealon_bridge/server/handlers/proxy.py +75 -0
- unrealon_bridge/server/handlers/scheduler.py +545 -0
- unrealon_bridge/server/handlers/session.py +66 -0
- unrealon_browser/__init__.py +61 -18
- unrealon_browser/{src/cli → cli}/browser_cli.py +6 -13
- unrealon_browser/{src/cli → cli}/cookies_cli.py +5 -1
- unrealon_browser/{src/core → core}/browser_manager.py +2 -2
- unrealon_browser/{src/managers → managers}/captcha.py +1 -1
- unrealon_browser/{src/managers → managers}/cookies.py +1 -1
- unrealon_browser/managers/logger_bridge.py +231 -0
- unrealon_browser/{src/managers → managers}/profile.py +1 -1
- unrealon_driver/__init__.py +73 -19
- unrealon_driver/browser/__init__.py +8 -0
- unrealon_driver/browser/config.py +74 -0
- unrealon_driver/browser/manager.py +416 -0
- unrealon_driver/exceptions.py +28 -0
- unrealon_driver/parser/__init__.py +55 -0
- unrealon_driver/parser/cli_manager.py +141 -0
- unrealon_driver/parser/daemon_manager.py +227 -0
- unrealon_driver/parser/managers/__init__.py +46 -0
- unrealon_driver/parser/managers/browser.py +51 -0
- unrealon_driver/parser/managers/config.py +281 -0
- unrealon_driver/parser/managers/error.py +412 -0
- unrealon_driver/parser/managers/html.py +732 -0
- unrealon_driver/parser/managers/logging.py +609 -0
- unrealon_driver/parser/managers/result.py +321 -0
- unrealon_driver/parser/parser_manager.py +628 -0
- unrealon/sdk_config.py +0 -88
- unrealon-1.0.9.dist-info/METADATA +0 -810
- unrealon-1.0.9.dist-info/RECORD +0 -246
- unrealon_browser/pyproject.toml +0 -182
- unrealon_browser/src/__init__.py +0 -62
- unrealon_browser/src/managers/logger_bridge.py +0 -395
- unrealon_driver/README.md +0 -204
- unrealon_driver/pyproject.toml +0 -187
- unrealon_driver/src/__init__.py +0 -90
- unrealon_driver/src/cli/__init__.py +0 -10
- unrealon_driver/src/cli/main.py +0 -66
- unrealon_driver/src/cli/simple.py +0 -510
- unrealon_driver/src/config/__init__.py +0 -11
- unrealon_driver/src/config/auto_config.py +0 -478
- unrealon_driver/src/core/__init__.py +0 -18
- unrealon_driver/src/core/exceptions.py +0 -289
- unrealon_driver/src/core/parser.py +0 -638
- unrealon_driver/src/dto/__init__.py +0 -66
- unrealon_driver/src/dto/cli.py +0 -119
- unrealon_driver/src/dto/config.py +0 -18
- unrealon_driver/src/dto/events.py +0 -237
- unrealon_driver/src/dto/execution.py +0 -313
- unrealon_driver/src/dto/services.py +0 -311
- unrealon_driver/src/execution/__init__.py +0 -23
- unrealon_driver/src/execution/daemon_mode.py +0 -317
- unrealon_driver/src/execution/interactive_mode.py +0 -88
- unrealon_driver/src/execution/modes.py +0 -45
- unrealon_driver/src/execution/scheduled_mode.py +0 -209
- unrealon_driver/src/execution/test_mode.py +0 -250
- unrealon_driver/src/logging/__init__.py +0 -24
- unrealon_driver/src/logging/driver_logger.py +0 -512
- unrealon_driver/src/services/__init__.py +0 -24
- unrealon_driver/src/services/browser_service.py +0 -726
- unrealon_driver/src/services/llm/__init__.py +0 -15
- unrealon_driver/src/services/llm/browser_llm_service.py +0 -363
- unrealon_driver/src/services/llm/llm.py +0 -195
- unrealon_driver/src/services/logger_service.py +0 -232
- unrealon_driver/src/services/metrics_service.py +0 -185
- unrealon_driver/src/services/scheduler_service.py +0 -489
- unrealon_driver/src/services/websocket_service.py +0 -362
- unrealon_driver/src/utils/__init__.py +0 -16
- unrealon_driver/src/utils/service_factory.py +0 -317
- unrealon_driver/src/utils/time_formatter.py +0 -338
- unrealon_llm/README.md +0 -44
- unrealon_llm/__init__.py +0 -26
- unrealon_llm/pyproject.toml +0 -154
- unrealon_llm/src/__init__.py +0 -228
- unrealon_llm/src/cli/__init__.py +0 -0
- unrealon_llm/src/core/__init__.py +0 -11
- unrealon_llm/src/core/smart_client.py +0 -438
- unrealon_llm/src/dto/__init__.py +0 -155
- unrealon_llm/src/dto/models/__init__.py +0 -0
- unrealon_llm/src/dto/models/config.py +0 -343
- unrealon_llm/src/dto/models/core.py +0 -328
- unrealon_llm/src/dto/models/enums.py +0 -123
- unrealon_llm/src/dto/models/html_analysis.py +0 -345
- unrealon_llm/src/dto/models/statistics.py +0 -473
- unrealon_llm/src/dto/models/translation.py +0 -383
- unrealon_llm/src/dto/models/type_conversion.py +0 -462
- unrealon_llm/src/dto/schemas/__init__.py +0 -0
- unrealon_llm/src/exceptions.py +0 -392
- unrealon_llm/src/llm_config/__init__.py +0 -20
- unrealon_llm/src/llm_config/logging_config.py +0 -178
- unrealon_llm/src/llm_logging/__init__.py +0 -42
- unrealon_llm/src/llm_logging/llm_events.py +0 -107
- unrealon_llm/src/llm_logging/llm_logger.py +0 -466
- unrealon_llm/src/managers/__init__.py +0 -15
- unrealon_llm/src/managers/cache_manager.py +0 -67
- unrealon_llm/src/managers/cost_manager.py +0 -107
- unrealon_llm/src/managers/request_manager.py +0 -298
- unrealon_llm/src/modules/__init__.py +0 -0
- unrealon_llm/src/modules/html_processor/__init__.py +0 -25
- unrealon_llm/src/modules/html_processor/base_processor.py +0 -415
- unrealon_llm/src/modules/html_processor/details_processor.py +0 -85
- unrealon_llm/src/modules/html_processor/listing_processor.py +0 -91
- unrealon_llm/src/modules/html_processor/models/__init__.py +0 -20
- unrealon_llm/src/modules/html_processor/models/processing_models.py +0 -40
- unrealon_llm/src/modules/html_processor/models/universal_model.py +0 -56
- unrealon_llm/src/modules/html_processor/processor.py +0 -102
- unrealon_llm/src/modules/llm/__init__.py +0 -0
- unrealon_llm/src/modules/translator/__init__.py +0 -0
- unrealon_llm/src/provider.py +0 -116
- unrealon_llm/src/utils/__init__.py +0 -95
- unrealon_llm/src/utils/common.py +0 -64
- unrealon_llm/src/utils/data_extractor.py +0 -188
- unrealon_llm/src/utils/html_cleaner.py +0 -767
- unrealon_llm/src/utils/language_detector.py +0 -308
- unrealon_llm/src/utils/models_cache.py +0 -592
- unrealon_llm/src/utils/smart_counter.py +0 -229
- unrealon_llm/src/utils/token_counter.py +0 -189
- unrealon_sdk/README.md +0 -25
- unrealon_sdk/__init__.py +0 -30
- unrealon_sdk/pyproject.toml +0 -231
- unrealon_sdk/src/__init__.py +0 -150
- unrealon_sdk/src/cli/__init__.py +0 -12
- unrealon_sdk/src/cli/commands/__init__.py +0 -22
- unrealon_sdk/src/cli/commands/benchmark.py +0 -42
- unrealon_sdk/src/cli/commands/diagnostics.py +0 -573
- unrealon_sdk/src/cli/commands/health.py +0 -46
- unrealon_sdk/src/cli/commands/integration.py +0 -498
- unrealon_sdk/src/cli/commands/reports.py +0 -43
- unrealon_sdk/src/cli/commands/security.py +0 -36
- unrealon_sdk/src/cli/commands/server.py +0 -483
- unrealon_sdk/src/cli/commands/servers.py +0 -56
- unrealon_sdk/src/cli/commands/tests.py +0 -55
- unrealon_sdk/src/cli/main.py +0 -126
- unrealon_sdk/src/cli/utils/reporter.py +0 -519
- unrealon_sdk/src/clients/openapi.yaml +0 -3347
- unrealon_sdk/src/clients/python_http/__init__.py +0 -3
- unrealon_sdk/src/clients/python_http/api_config.py +0 -228
- unrealon_sdk/src/clients/python_http/models/BaseModel.py +0 -12
- unrealon_sdk/src/clients/python_http/models/BroadcastDeliveryStats.py +0 -33
- unrealon_sdk/src/clients/python_http/models/BroadcastMessage.py +0 -17
- unrealon_sdk/src/clients/python_http/models/BroadcastMessageRequest.py +0 -35
- unrealon_sdk/src/clients/python_http/models/BroadcastPriority.py +0 -10
- unrealon_sdk/src/clients/python_http/models/BroadcastResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/BroadcastResultResponse.py +0 -33
- unrealon_sdk/src/clients/python_http/models/BroadcastTarget.py +0 -11
- unrealon_sdk/src/clients/python_http/models/ConnectionStats.py +0 -27
- unrealon_sdk/src/clients/python_http/models/ConnectionsResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/DeveloperMessageResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ErrorResponse.py +0 -25
- unrealon_sdk/src/clients/python_http/models/HTTPValidationError.py +0 -16
- unrealon_sdk/src/clients/python_http/models/HealthResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/HealthStatus.py +0 -33
- unrealon_sdk/src/clients/python_http/models/LogLevel.py +0 -10
- unrealon_sdk/src/clients/python_http/models/LoggingRequest.py +0 -27
- unrealon_sdk/src/clients/python_http/models/LoggingResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/MaintenanceMode.py +0 -9
- unrealon_sdk/src/clients/python_http/models/MaintenanceModeRequest.py +0 -33
- unrealon_sdk/src/clients/python_http/models/MaintenanceStatusResponse.py +0 -39
- unrealon_sdk/src/clients/python_http/models/ParserCommandRequest.py +0 -25
- unrealon_sdk/src/clients/python_http/models/ParserMessageResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/ParserRegistrationRequest.py +0 -28
- unrealon_sdk/src/clients/python_http/models/ParserRegistrationResponse.py +0 -25
- unrealon_sdk/src/clients/python_http/models/ParserType.py +0 -10
- unrealon_sdk/src/clients/python_http/models/ProxyBlockRequest.py +0 -19
- unrealon_sdk/src/clients/python_http/models/ProxyEndpointResponse.py +0 -20
- unrealon_sdk/src/clients/python_http/models/ProxyListResponse.py +0 -19
- unrealon_sdk/src/clients/python_http/models/ProxyProvider.py +0 -10
- unrealon_sdk/src/clients/python_http/models/ProxyPurchaseRequest.py +0 -25
- unrealon_sdk/src/clients/python_http/models/ProxyResponse.py +0 -47
- unrealon_sdk/src/clients/python_http/models/ProxyRotationRequest.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ProxyStatus.py +0 -10
- unrealon_sdk/src/clients/python_http/models/ProxyUsageRequest.py +0 -19
- unrealon_sdk/src/clients/python_http/models/ProxyUsageStatsResponse.py +0 -26
- unrealon_sdk/src/clients/python_http/models/ServiceRegistrationDto.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ServiceStatsResponse.py +0 -31
- unrealon_sdk/src/clients/python_http/models/SessionStartRequest.py +0 -23
- unrealon_sdk/src/clients/python_http/models/SuccessResponse.py +0 -25
- unrealon_sdk/src/clients/python_http/models/SystemNotificationResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ValidationError.py +0 -18
- unrealon_sdk/src/clients/python_http/models/ValidationErrorResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/WebSocketMetrics.py +0 -21
- unrealon_sdk/src/clients/python_http/models/__init__.py +0 -44
- unrealon_sdk/src/clients/python_http/services/None_service.py +0 -35
- unrealon_sdk/src/clients/python_http/services/ParserManagement_service.py +0 -190
- unrealon_sdk/src/clients/python_http/services/ProxyManagement_service.py +0 -289
- unrealon_sdk/src/clients/python_http/services/SocketLogging_service.py +0 -187
- unrealon_sdk/src/clients/python_http/services/SystemHealth_service.py +0 -119
- unrealon_sdk/src/clients/python_http/services/WebSocketAPI_service.py +0 -198
- unrealon_sdk/src/clients/python_http/services/__init__.py +0 -0
- unrealon_sdk/src/clients/python_http/services/admin_service.py +0 -125
- unrealon_sdk/src/clients/python_http/services/async_None_service.py +0 -35
- unrealon_sdk/src/clients/python_http/services/async_ParserManagement_service.py +0 -190
- unrealon_sdk/src/clients/python_http/services/async_ProxyManagement_service.py +0 -289
- unrealon_sdk/src/clients/python_http/services/async_SocketLogging_service.py +0 -189
- unrealon_sdk/src/clients/python_http/services/async_SystemHealth_service.py +0 -123
- unrealon_sdk/src/clients/python_http/services/async_WebSocketAPI_service.py +0 -200
- unrealon_sdk/src/clients/python_http/services/async_admin_service.py +0 -125
- unrealon_sdk/src/clients/python_websocket/__init__.py +0 -28
- unrealon_sdk/src/clients/python_websocket/client.py +0 -490
- unrealon_sdk/src/clients/python_websocket/events.py +0 -732
- unrealon_sdk/src/clients/python_websocket/example.py +0 -136
- unrealon_sdk/src/clients/python_websocket/types.py +0 -871
- unrealon_sdk/src/core/__init__.py +0 -64
- unrealon_sdk/src/core/client.py +0 -556
- unrealon_sdk/src/core/config.py +0 -465
- unrealon_sdk/src/core/exceptions.py +0 -239
- unrealon_sdk/src/core/metadata.py +0 -191
- unrealon_sdk/src/core/models.py +0 -142
- unrealon_sdk/src/core/types.py +0 -68
- unrealon_sdk/src/dto/__init__.py +0 -268
- unrealon_sdk/src/dto/authentication.py +0 -108
- unrealon_sdk/src/dto/cache.py +0 -208
- unrealon_sdk/src/dto/common.py +0 -19
- unrealon_sdk/src/dto/concurrency.py +0 -393
- unrealon_sdk/src/dto/events.py +0 -108
- unrealon_sdk/src/dto/health.py +0 -339
- unrealon_sdk/src/dto/load_balancing.py +0 -336
- unrealon_sdk/src/dto/logging.py +0 -230
- unrealon_sdk/src/dto/performance.py +0 -165
- unrealon_sdk/src/dto/rate_limiting.py +0 -295
- unrealon_sdk/src/dto/resource_pooling.py +0 -128
- unrealon_sdk/src/dto/structured_logging.py +0 -112
- unrealon_sdk/src/dto/task_scheduling.py +0 -121
- unrealon_sdk/src/dto/websocket.py +0 -55
- unrealon_sdk/src/enterprise/__init__.py +0 -59
- unrealon_sdk/src/enterprise/authentication.py +0 -401
- unrealon_sdk/src/enterprise/cache_manager.py +0 -578
- unrealon_sdk/src/enterprise/error_recovery.py +0 -494
- unrealon_sdk/src/enterprise/event_system.py +0 -549
- unrealon_sdk/src/enterprise/health_monitor.py +0 -747
- unrealon_sdk/src/enterprise/load_balancer.py +0 -964
- unrealon_sdk/src/enterprise/logging/__init__.py +0 -68
- unrealon_sdk/src/enterprise/logging/cleanup.py +0 -156
- unrealon_sdk/src/enterprise/logging/development.py +0 -744
- unrealon_sdk/src/enterprise/logging/service.py +0 -410
- unrealon_sdk/src/enterprise/multithreading_manager.py +0 -853
- unrealon_sdk/src/enterprise/performance_monitor.py +0 -539
- unrealon_sdk/src/enterprise/proxy_manager.py +0 -696
- unrealon_sdk/src/enterprise/rate_limiter.py +0 -652
- unrealon_sdk/src/enterprise/resource_pool.py +0 -763
- unrealon_sdk/src/enterprise/task_scheduler.py +0 -709
- unrealon_sdk/src/internal/__init__.py +0 -10
- unrealon_sdk/src/internal/command_router.py +0 -497
- unrealon_sdk/src/internal/connection_manager.py +0 -397
- unrealon_sdk/src/internal/http_client.py +0 -446
- unrealon_sdk/src/internal/websocket_client.py +0 -420
- unrealon_sdk/src/provider.py +0 -471
- unrealon_sdk/src/utils.py +0 -234
- /unrealon_browser/{src/cli → cli}/__init__.py +0 -0
- /unrealon_browser/{src/cli → cli}/interactive_mode.py +0 -0
- /unrealon_browser/{src/cli → cli}/main.py +0 -0
- /unrealon_browser/{src/core → core}/__init__.py +0 -0
- /unrealon_browser/{src/dto → dto}/__init__.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/config.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/core.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/dataclasses.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/detection.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/enums.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/statistics.py +0 -0
- /unrealon_browser/{src/managers → managers}/__init__.py +0 -0
- /unrealon_browser/{src/managers → managers}/stealth.py +0 -0
unrealon_sdk/src/dto/logging.py
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Logging-related Data Transfer Objects
|
|
3
|
-
|
|
4
|
-
Custom DTO models for enterprise logging system functionality.
|
|
5
|
-
These models provide type-safe logging configuration and event tracking.
|
|
6
|
-
Includes models for both development logging and structured logging.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
from datetime import datetime, timezone
|
|
10
|
-
from typing import Dict, List, Optional, Any
|
|
11
|
-
from enum import Enum
|
|
12
|
-
from dataclasses import dataclass
|
|
13
|
-
|
|
14
|
-
from pydantic import BaseModel, Field, ConfigDict
|
|
15
|
-
|
|
16
|
-
# Import LogEntryMessage at module level to avoid inline imports
|
|
17
|
-
try:
|
|
18
|
-
from unrealon_sdk.src.enterprise.logging.service import LogEntryMessage
|
|
19
|
-
except ImportError:
|
|
20
|
-
# Fallback for when logging service is not available
|
|
21
|
-
LogEntryMessage = None
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class LogDestination(str, Enum):
|
|
25
|
-
"""Available log destinations."""
|
|
26
|
-
|
|
27
|
-
CONSOLE = "console"
|
|
28
|
-
WEBSOCKET = "websocket"
|
|
29
|
-
FILE = "file"
|
|
30
|
-
HTTP = "http"
|
|
31
|
-
BUFFER = "buffer"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
class SDKEventType(str, Enum):
|
|
35
|
-
"""SDK development event types for process tracking."""
|
|
36
|
-
|
|
37
|
-
# SDK Lifecycle Events
|
|
38
|
-
SDK_INITIALIZED = "sdk_initialized"
|
|
39
|
-
SDK_STARTED = "sdk_started"
|
|
40
|
-
SDK_SHUTDOWN = "sdk_shutdown"
|
|
41
|
-
SDK_ERROR = "sdk_error"
|
|
42
|
-
|
|
43
|
-
# Layer Development Events (Skyscraper Architecture)
|
|
44
|
-
LAYER_STARTED = "layer_started"
|
|
45
|
-
LAYER_COMPLETED = "layer_completed"
|
|
46
|
-
LAYER_VALIDATION = "layer_validation"
|
|
47
|
-
LAYER_FAILED = "layer_failed"
|
|
48
|
-
|
|
49
|
-
# Component Development Events
|
|
50
|
-
COMPONENT_CREATED = "component_created"
|
|
51
|
-
COMPONENT_TESTED = "component_tested"
|
|
52
|
-
COMPONENT_INTEGRATED = "component_integrated"
|
|
53
|
-
COMPONENT_DEPRECATED = "component_deprecated"
|
|
54
|
-
|
|
55
|
-
# Connection Management Events
|
|
56
|
-
CONNECTION_ESTABLISHED = "connection_established"
|
|
57
|
-
CONNECTION_LOST = "connection_lost"
|
|
58
|
-
CONNECTION_RETRY = "connection_retry"
|
|
59
|
-
CONNECTION_HEALTH_CHECK = "connection_health_check"
|
|
60
|
-
|
|
61
|
-
# Command Processing Events
|
|
62
|
-
COMMAND_RECEIVED = "command_received"
|
|
63
|
-
COMMAND_EXECUTED = "command_executed"
|
|
64
|
-
COMMAND_COMPLETED = "command_completed"
|
|
65
|
-
COMMAND_FAILED = "command_failed"
|
|
66
|
-
COMMAND_TIMEOUT = "command_timeout"
|
|
67
|
-
|
|
68
|
-
# Proxy Management Events
|
|
69
|
-
PROXY_MANAGER_INITIALIZED = "proxy_manager_initialized"
|
|
70
|
-
PROXY_ALLOCATED = "proxy_allocated"
|
|
71
|
-
PROXY_ROTATION = "proxy_rotation"
|
|
72
|
-
PROXY_HEALTH_CHECK = "proxy_health_check"
|
|
73
|
-
PROXY_BLACKLISTED = "proxy_blacklisted"
|
|
74
|
-
|
|
75
|
-
# Logging Service Events
|
|
76
|
-
LOGGING_SERVICE_INITIALIZED = "logging_service_initialized"
|
|
77
|
-
LOG_BUFFER_FLUSHED = "log_buffer_flushed"
|
|
78
|
-
LOG_WEBSOCKET_SENT = "log_websocket_sent"
|
|
79
|
-
LOG_WEBSOCKET_ERROR = "log_websocket_error"
|
|
80
|
-
|
|
81
|
-
# Performance Monitoring Events
|
|
82
|
-
PERFORMANCE_METRIC_COLLECTED = "performance_metric_collected"
|
|
83
|
-
PERFORMANCE_THRESHOLD_EXCEEDED = "performance_threshold_exceeded"
|
|
84
|
-
PERFORMANCE_OPTIMIZATION_APPLIED = "performance_optimization_applied"
|
|
85
|
-
|
|
86
|
-
# Error Recovery Events
|
|
87
|
-
ERROR_DETECTED = "error_detected"
|
|
88
|
-
ERROR_RECOVERY_STARTED = "error_recovery_started"
|
|
89
|
-
ERROR_RECOVERY_COMPLETED = "error_recovery_completed"
|
|
90
|
-
ERROR_RECOVERY_FAILED = "error_recovery_failed"
|
|
91
|
-
|
|
92
|
-
# API Integration Events
|
|
93
|
-
API_CALL_STARTED = "api_call_started"
|
|
94
|
-
API_CALL_COMPLETED = "api_call_completed"
|
|
95
|
-
API_CALL_FAILED = "api_call_failed"
|
|
96
|
-
API_RATE_LIMITED = "api_rate_limited"
|
|
97
|
-
|
|
98
|
-
# Development Quality Events
|
|
99
|
-
TYPE_SAFETY_VALIDATION = "type_safety_validation"
|
|
100
|
-
PYDANTIC_MODEL_VALIDATION = "pydantic_model_validation"
|
|
101
|
-
CODE_QUALITY_CHECK = "code_quality_check"
|
|
102
|
-
LINT_CHECK = "lint_check"
|
|
103
|
-
|
|
104
|
-
# Testing Events
|
|
105
|
-
TEST_STARTED = "test_started"
|
|
106
|
-
TEST_PASSED = "test_passed"
|
|
107
|
-
TEST_FAILED = "test_failed"
|
|
108
|
-
TEST_COVERAGE_MEASURED = "test_coverage_measured"
|
|
109
|
-
|
|
110
|
-
# Integration Events
|
|
111
|
-
CLIENT_INTEGRATION = "client_integration"
|
|
112
|
-
WEBSOCKET_INTEGRATION = "websocket_integration"
|
|
113
|
-
HTTP_INTEGRATION = "http_integration"
|
|
114
|
-
|
|
115
|
-
# Debug Events
|
|
116
|
-
DEBUG_CHECKPOINT = "debug_checkpoint"
|
|
117
|
-
DEBUG_VARIABLE_DUMP = "debug_variable_dump"
|
|
118
|
-
DEBUG_STACK_TRACE = "debug_stack_trace"
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
class SDKSeverity(str, Enum):
|
|
122
|
-
"""SDK development event severity levels."""
|
|
123
|
-
|
|
124
|
-
TRACE = "trace" # Detailed tracing information
|
|
125
|
-
DEBUG = "debug" # Debug information
|
|
126
|
-
INFO = "info" # General information
|
|
127
|
-
WARNING = "warning" # Warning conditions
|
|
128
|
-
ERROR = "error" # Error conditions
|
|
129
|
-
CRITICAL = "critical" # Critical conditions
|
|
130
|
-
FATAL = "fatal" # Fatal conditions causing shutdown
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
@dataclass
|
|
134
|
-
class SDKContext:
|
|
135
|
-
"""Context information for SDK development events."""
|
|
136
|
-
|
|
137
|
-
# Development context
|
|
138
|
-
layer_name: Optional[str] = None
|
|
139
|
-
component_name: Optional[str] = None
|
|
140
|
-
method_name: Optional[str] = None
|
|
141
|
-
file_path: Optional[str] = None
|
|
142
|
-
line_number: Optional[int] = None
|
|
143
|
-
|
|
144
|
-
# Runtime context
|
|
145
|
-
thread_id: Optional[str] = None
|
|
146
|
-
session_id: Optional[str] = None
|
|
147
|
-
correlation_id: Optional[str] = None
|
|
148
|
-
|
|
149
|
-
# Performance context
|
|
150
|
-
execution_time_ms: Optional[float] = None
|
|
151
|
-
memory_usage_mb: Optional[float] = None
|
|
152
|
-
cpu_usage_percent: Optional[float] = None
|
|
153
|
-
|
|
154
|
-
# Connection context
|
|
155
|
-
parser_id: Optional[str] = None
|
|
156
|
-
adapter_url: Optional[str] = None
|
|
157
|
-
websocket_connected: Optional[bool] = None
|
|
158
|
-
http_client_active: Optional[bool] = None
|
|
159
|
-
|
|
160
|
-
# Command context
|
|
161
|
-
command_id: Optional[str] = None
|
|
162
|
-
command_type: Optional[str] = None
|
|
163
|
-
command_priority: Optional[str] = None
|
|
164
|
-
|
|
165
|
-
# Additional metadata (use Any for flexible context data)
|
|
166
|
-
metadata: Optional[Any] = None
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
class SDKDevelopmentEvent(BaseModel):
|
|
170
|
-
"""Structured development event model for SDK logging."""
|
|
171
|
-
|
|
172
|
-
model_config = ConfigDict(extra="forbid")
|
|
173
|
-
|
|
174
|
-
# Event identification
|
|
175
|
-
event_type: SDKEventType = Field(..., description="Type of SDK development event")
|
|
176
|
-
severity: SDKSeverity = Field(..., description="Event severity level")
|
|
177
|
-
timestamp: datetime = Field(
|
|
178
|
-
default_factory=lambda: datetime.now(timezone.utc), description="Event timestamp in UTC"
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
# Event details
|
|
182
|
-
message: str = Field(..., description="Human-readable event description")
|
|
183
|
-
details: Any = Field(
|
|
184
|
-
default_factory=dict, description="Additional event details (flexible structure)"
|
|
185
|
-
)
|
|
186
|
-
|
|
187
|
-
# Context information
|
|
188
|
-
context: SDKContext = Field(default_factory=SDKContext, description="Event context")
|
|
189
|
-
|
|
190
|
-
# Result information
|
|
191
|
-
success: bool = Field(..., description="Whether the operation was successful")
|
|
192
|
-
error_code: Optional[str] = Field(None, description="Error code if operation failed")
|
|
193
|
-
error_message: Optional[str] = Field(None, description="Error message if operation failed")
|
|
194
|
-
|
|
195
|
-
# Performance metrics
|
|
196
|
-
duration_ms: Optional[float] = Field(None, description="Operation duration in milliseconds")
|
|
197
|
-
|
|
198
|
-
def to_websocket_message(self, session_id: str) -> Any:
|
|
199
|
-
"""Convert to WebSocket LogEntryMessage for real-time streaming."""
|
|
200
|
-
# Note: This method will use LogEntryMessage from enterprise logging service
|
|
201
|
-
if LogEntryMessage is None:
|
|
202
|
-
raise ImportError("LogEntryMessage not available - logging service not installed")
|
|
203
|
-
|
|
204
|
-
return LogEntryMessage(
|
|
205
|
-
type="sdk_development_log",
|
|
206
|
-
session_id=session_id,
|
|
207
|
-
entry={
|
|
208
|
-
"event_type": self.event_type.value,
|
|
209
|
-
"severity": self.severity.value,
|
|
210
|
-
"message": self.message,
|
|
211
|
-
"success": self.success,
|
|
212
|
-
"details": self.details,
|
|
213
|
-
"context": self.context.__dict__ if hasattr(self.context, "__dict__") else {},
|
|
214
|
-
"error_code": self.error_code,
|
|
215
|
-
"error_message": self.error_message,
|
|
216
|
-
"duration_ms": self.duration_ms,
|
|
217
|
-
},
|
|
218
|
-
timestamp=self.timestamp.isoformat(),
|
|
219
|
-
)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
__all__ = [
|
|
223
|
-
# Enums
|
|
224
|
-
"LogDestination",
|
|
225
|
-
"SDKEventType",
|
|
226
|
-
"SDKSeverity",
|
|
227
|
-
# Models
|
|
228
|
-
"SDKContext",
|
|
229
|
-
"SDKDevelopmentEvent",
|
|
230
|
-
]
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Performance Monitoring Data Transfer Objects
|
|
3
|
-
|
|
4
|
-
DTO models for enterprise performance monitoring system functionality.
|
|
5
|
-
These models provide type-safe performance metrics, alerts, and reporting.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from datetime import datetime, timezone
|
|
9
|
-
from typing import Dict, List, Optional, Any, Union
|
|
10
|
-
from enum import Enum
|
|
11
|
-
from dataclasses import dataclass, field
|
|
12
|
-
|
|
13
|
-
from pydantic import BaseModel, Field, ConfigDict
|
|
14
|
-
|
|
15
|
-
from unrealon_sdk.src.utils import generate_correlation_id
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class MetricType(str, Enum):
|
|
19
|
-
"""Types of performance metrics."""
|
|
20
|
-
|
|
21
|
-
COUNTER = "counter" # Incrementing values (requests, errors)
|
|
22
|
-
GAUGE = "gauge" # Point-in-time values (memory, CPU)
|
|
23
|
-
HISTOGRAM = "histogram" # Distribution of values (response times)
|
|
24
|
-
TIMER = "timer" # Elapsed time measurements
|
|
25
|
-
RATE = "rate" # Events per time unit
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class AlertSeverity(str, Enum):
|
|
29
|
-
"""Alert severity levels."""
|
|
30
|
-
|
|
31
|
-
INFO = "info"
|
|
32
|
-
WARNING = "warning"
|
|
33
|
-
ERROR = "error"
|
|
34
|
-
CRITICAL = "critical"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class MetricUnit(str, Enum):
|
|
38
|
-
"""Metric measurement units."""
|
|
39
|
-
|
|
40
|
-
# Time units
|
|
41
|
-
MILLISECONDS = "ms"
|
|
42
|
-
SECONDS = "s"
|
|
43
|
-
MINUTES = "min"
|
|
44
|
-
|
|
45
|
-
# Size units
|
|
46
|
-
BYTES = "bytes"
|
|
47
|
-
KILOBYTES = "kb"
|
|
48
|
-
MEGABYTES = "mb"
|
|
49
|
-
|
|
50
|
-
# Rate units
|
|
51
|
-
PER_SECOND = "/s"
|
|
52
|
-
PER_MINUTE = "/min"
|
|
53
|
-
|
|
54
|
-
# Percentage
|
|
55
|
-
PERCENT = "%"
|
|
56
|
-
|
|
57
|
-
# Count
|
|
58
|
-
COUNT = "count"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
@dataclass
|
|
62
|
-
class MetricValue:
|
|
63
|
-
"""Individual metric measurement."""
|
|
64
|
-
|
|
65
|
-
timestamp: datetime
|
|
66
|
-
value: Union[int, float]
|
|
67
|
-
labels: Dict[str, str] = field(default_factory=dict)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
@dataclass
|
|
71
|
-
class MetricThreshold:
|
|
72
|
-
"""Threshold configuration for alerting."""
|
|
73
|
-
|
|
74
|
-
warning_threshold: Optional[float] = None
|
|
75
|
-
error_threshold: Optional[float] = None
|
|
76
|
-
critical_threshold: Optional[float] = None
|
|
77
|
-
|
|
78
|
-
# For rate-based alerts (e.g., error rate)
|
|
79
|
-
time_window_seconds: float = 60.0
|
|
80
|
-
min_samples: int = 5
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
class PerformanceMetric(BaseModel):
|
|
84
|
-
"""Performance metric model with metadata."""
|
|
85
|
-
|
|
86
|
-
model_config = ConfigDict(extra="forbid")
|
|
87
|
-
|
|
88
|
-
name: str = Field(..., description="Metric name")
|
|
89
|
-
metric_type: MetricType = Field(..., description="Type of metric")
|
|
90
|
-
unit: MetricUnit = Field(..., description="Measurement unit")
|
|
91
|
-
description: str = Field(..., description="Metric description")
|
|
92
|
-
|
|
93
|
-
# Current values
|
|
94
|
-
current_value: Optional[float] = Field(default=None, description="Latest value")
|
|
95
|
-
total_samples: int = Field(default=0, description="Total number of samples")
|
|
96
|
-
|
|
97
|
-
# Statistical data
|
|
98
|
-
min_value: Optional[float] = Field(default=None, description="Minimum recorded value")
|
|
99
|
-
max_value: Optional[float] = Field(default=None, description="Maximum recorded value")
|
|
100
|
-
avg_value: Optional[float] = Field(default=None, description="Average value")
|
|
101
|
-
|
|
102
|
-
# Metadata
|
|
103
|
-
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
|
104
|
-
last_updated: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
|
105
|
-
tags: Dict[str, str] = Field(default_factory=dict, description="Metric tags")
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
class PerformanceAlert(BaseModel):
|
|
109
|
-
"""Performance alert model."""
|
|
110
|
-
|
|
111
|
-
model_config = ConfigDict(extra="forbid")
|
|
112
|
-
|
|
113
|
-
alert_id: str = Field(default_factory=generate_correlation_id)
|
|
114
|
-
metric_name: str = Field(..., description="Name of metric that triggered alert")
|
|
115
|
-
severity: AlertSeverity = Field(..., description="Alert severity")
|
|
116
|
-
threshold_value: float = Field(..., description="Threshold that was exceeded")
|
|
117
|
-
current_value: float = Field(..., description="Current metric value")
|
|
118
|
-
message: str = Field(..., description="Alert message")
|
|
119
|
-
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
|
120
|
-
acknowledged: bool = Field(default=False, description="Whether alert was acknowledged")
|
|
121
|
-
resolved: bool = Field(default=False, description="Whether alert was resolved")
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
class PerformanceReport(BaseModel):
|
|
125
|
-
"""Comprehensive performance report."""
|
|
126
|
-
|
|
127
|
-
model_config = ConfigDict(extra="forbid")
|
|
128
|
-
|
|
129
|
-
report_id: str = Field(default_factory=generate_correlation_id)
|
|
130
|
-
period_start: datetime = Field(..., description="Report period start")
|
|
131
|
-
period_end: datetime = Field(..., description="Report period end")
|
|
132
|
-
|
|
133
|
-
# System metrics
|
|
134
|
-
avg_cpu_percent: float = Field(..., description="Average CPU usage")
|
|
135
|
-
avg_memory_mb: float = Field(..., description="Average memory usage in MB")
|
|
136
|
-
peak_memory_mb: float = Field(..., description="Peak memory usage in MB")
|
|
137
|
-
|
|
138
|
-
# Operation metrics
|
|
139
|
-
total_operations: int = Field(..., description="Total operations performed")
|
|
140
|
-
avg_operation_time_ms: float = Field(..., description="Average operation time")
|
|
141
|
-
error_rate_percent: float = Field(..., description="Error rate percentage")
|
|
142
|
-
|
|
143
|
-
# Network metrics
|
|
144
|
-
total_requests: int = Field(..., description="Total network requests")
|
|
145
|
-
avg_response_time_ms: float = Field(..., description="Average response time")
|
|
146
|
-
timeout_count: int = Field(..., description="Number of timeouts")
|
|
147
|
-
|
|
148
|
-
# Alerts
|
|
149
|
-
total_alerts: int = Field(..., description="Total alerts generated")
|
|
150
|
-
critical_alerts: int = Field(..., description="Critical alerts")
|
|
151
|
-
unresolved_alerts: int = Field(..., description="Unresolved alerts")
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
__all__ = [
|
|
155
|
-
# Enums
|
|
156
|
-
"MetricType",
|
|
157
|
-
"AlertSeverity",
|
|
158
|
-
"MetricUnit",
|
|
159
|
-
# Models
|
|
160
|
-
"MetricValue",
|
|
161
|
-
"MetricThreshold",
|
|
162
|
-
"PerformanceMetric",
|
|
163
|
-
"PerformanceAlert",
|
|
164
|
-
"PerformanceReport",
|
|
165
|
-
]
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Rate Limiting DTOs - Data Transfer Objects for request throttling system.
|
|
3
|
-
|
|
4
|
-
This module contains all Pydantic models and enums related to rate limiting,
|
|
5
|
-
separated from business logic for clean architecture and reusability.
|
|
6
|
-
|
|
7
|
-
Components:
|
|
8
|
-
- Rate limiting strategies and configuration models
|
|
9
|
-
- Throttling metrics and statistics models
|
|
10
|
-
- Backoff algorithms and retry policies
|
|
11
|
-
- Performance and analytics data structures
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
import uuid
|
|
15
|
-
from datetime import datetime, timezone, timedelta
|
|
16
|
-
from typing import Dict, List, Optional, Any, Union
|
|
17
|
-
from enum import Enum
|
|
18
|
-
from dataclasses import dataclass, field
|
|
19
|
-
|
|
20
|
-
from pydantic import BaseModel, Field, ConfigDict
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class RateLimitStrategy(str, Enum):
|
|
24
|
-
"""Rate limiting strategies."""
|
|
25
|
-
|
|
26
|
-
TOKEN_BUCKET = "token_bucket" # Token bucket algorithm
|
|
27
|
-
LEAKY_BUCKET = "leaky_bucket" # Leaky bucket algorithm
|
|
28
|
-
SLIDING_WINDOW = "sliding_window" # Sliding window counter
|
|
29
|
-
FIXED_WINDOW = "fixed_window" # Fixed window counter
|
|
30
|
-
ADAPTIVE = "adaptive" # Adaptive rate limiting based on load
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class BackoffStrategy(str, Enum):
|
|
34
|
-
"""Backoff strategies for rate limiting."""
|
|
35
|
-
|
|
36
|
-
LINEAR = "linear" # Linear backoff
|
|
37
|
-
EXPONENTIAL = "exponential" # Exponential backoff
|
|
38
|
-
FIBONACCI = "fibonacci" # Fibonacci sequence backoff
|
|
39
|
-
JITTERED = "jittered" # Jittered exponential backoff
|
|
40
|
-
CUSTOM = "custom" # Custom backoff function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
class RateLimitScope(str, Enum):
|
|
44
|
-
"""Rate limit scope levels."""
|
|
45
|
-
|
|
46
|
-
GLOBAL = "global" # Global rate limit across all operations
|
|
47
|
-
USER = "user" # Per-user rate limiting
|
|
48
|
-
API_KEY = "api_key" # Per-API key rate limiting
|
|
49
|
-
ENDPOINT = "endpoint" # Per-endpoint rate limiting
|
|
50
|
-
OPERATION = "operation" # Per-operation type rate limiting
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
class RateLimitStatus(str, Enum):
|
|
54
|
-
"""Rate limit operation status."""
|
|
55
|
-
|
|
56
|
-
ALLOWED = "allowed" # Request allowed
|
|
57
|
-
THROTTLED = "throttled" # Request throttled but queued
|
|
58
|
-
REJECTED = "rejected" # Request rejected due to rate limit
|
|
59
|
-
RETRYING = "retrying" # Request being retried with backoff
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
class RateLimitEventType(str, Enum):
|
|
63
|
-
"""Rate limit event types for monitoring."""
|
|
64
|
-
|
|
65
|
-
REQUEST_ALLOWED = "request_allowed"
|
|
66
|
-
REQUEST_THROTTLED = "request_throttled"
|
|
67
|
-
REQUEST_REJECTED = "request_rejected"
|
|
68
|
-
LIMIT_EXCEEDED = "limit_exceeded"
|
|
69
|
-
QUOTA_RESET = "quota_reset"
|
|
70
|
-
BACKOFF_APPLIED = "backoff_applied"
|
|
71
|
-
ADAPTIVE_ADJUSTMENT = "adaptive_adjustment"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
class RateLimitConfig(BaseModel):
|
|
75
|
-
"""Rate limiting configuration model."""
|
|
76
|
-
|
|
77
|
-
model_config = ConfigDict(extra="forbid")
|
|
78
|
-
|
|
79
|
-
# Basic limits
|
|
80
|
-
requests_per_second: float = Field(default=10.0, description="Requests per second limit")
|
|
81
|
-
requests_per_minute: int = Field(default=600, description="Requests per minute limit")
|
|
82
|
-
requests_per_hour: int = Field(default=36000, description="Requests per hour limit")
|
|
83
|
-
requests_per_day: int = Field(default=864000, description="Requests per day limit")
|
|
84
|
-
|
|
85
|
-
# Strategy configuration
|
|
86
|
-
strategy: RateLimitStrategy = Field(
|
|
87
|
-
default=RateLimitStrategy.TOKEN_BUCKET, description="Rate limiting strategy"
|
|
88
|
-
)
|
|
89
|
-
scope: RateLimitScope = Field(default=RateLimitScope.GLOBAL, description="Rate limit scope")
|
|
90
|
-
|
|
91
|
-
# Token bucket specific
|
|
92
|
-
bucket_capacity: int = Field(default=100, description="Token bucket capacity")
|
|
93
|
-
refill_rate: float = Field(default=10.0, description="Token refill rate per second")
|
|
94
|
-
|
|
95
|
-
# Sliding window specific
|
|
96
|
-
window_size_seconds: int = Field(default=60, description="Sliding window size in seconds")
|
|
97
|
-
window_segments: int = Field(default=10, description="Number of window segments")
|
|
98
|
-
|
|
99
|
-
# Backoff configuration
|
|
100
|
-
backoff_strategy: BackoffStrategy = Field(
|
|
101
|
-
default=BackoffStrategy.EXPONENTIAL, description="Backoff strategy"
|
|
102
|
-
)
|
|
103
|
-
base_delay_seconds: float = Field(default=1.0, description="Base delay for backoff")
|
|
104
|
-
max_delay_seconds: float = Field(default=300.0, description="Maximum delay for backoff")
|
|
105
|
-
backoff_multiplier: float = Field(default=2.0, description="Backoff multiplier")
|
|
106
|
-
jitter_enabled: bool = Field(default=True, description="Enable jitter in backoff")
|
|
107
|
-
|
|
108
|
-
# Adaptive configuration
|
|
109
|
-
adaptive_enabled: bool = Field(default=False, description="Enable adaptive rate limiting")
|
|
110
|
-
load_threshold: float = Field(default=0.8, description="Load threshold for adaptation")
|
|
111
|
-
adaptation_factor: float = Field(default=0.5, description="Rate adaptation factor")
|
|
112
|
-
|
|
113
|
-
# Queue configuration
|
|
114
|
-
queue_enabled: bool = Field(default=True, description="Enable request queuing")
|
|
115
|
-
max_queue_size: int = Field(default=1000, description="Maximum queue size")
|
|
116
|
-
queue_timeout_seconds: float = Field(default=30.0, description="Queue timeout")
|
|
117
|
-
|
|
118
|
-
# Monitoring
|
|
119
|
-
enable_metrics: bool = Field(default=True, description="Enable rate limit metrics")
|
|
120
|
-
metrics_window_seconds: int = Field(default=300, description="Metrics collection window")
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
class RateLimitQuota(BaseModel):
|
|
124
|
-
"""Rate limit quota tracking model."""
|
|
125
|
-
|
|
126
|
-
model_config = ConfigDict(extra="forbid")
|
|
127
|
-
|
|
128
|
-
# Identification
|
|
129
|
-
scope_id: str = Field(..., description="Scope identifier (user_id, api_key, etc.)")
|
|
130
|
-
scope_type: RateLimitScope = Field(..., description="Scope type")
|
|
131
|
-
|
|
132
|
-
# Current state
|
|
133
|
-
current_requests: int = Field(default=0, description="Current request count")
|
|
134
|
-
remaining_requests: int = Field(default=0, description="Remaining requests")
|
|
135
|
-
reset_time: datetime = Field(..., description="When quota resets")
|
|
136
|
-
|
|
137
|
-
# Limits
|
|
138
|
-
requests_limit: int = Field(..., description="Request limit for this quota")
|
|
139
|
-
window_start: datetime = Field(..., description="Window start time")
|
|
140
|
-
window_end: datetime = Field(..., description="Window end time")
|
|
141
|
-
|
|
142
|
-
# Token bucket state (if applicable)
|
|
143
|
-
tokens_available: float = Field(default=0.0, description="Available tokens")
|
|
144
|
-
last_refill: datetime = Field(
|
|
145
|
-
default_factory=lambda: datetime.now(timezone.utc), description="Last token refill time"
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
# Statistics
|
|
149
|
-
total_requests: int = Field(default=0, description="Total requests made")
|
|
150
|
-
throttled_requests: int = Field(default=0, description="Throttled requests")
|
|
151
|
-
rejected_requests: int = Field(default=0, description="Rejected requests")
|
|
152
|
-
|
|
153
|
-
def is_expired(self) -> bool:
|
|
154
|
-
"""Check if quota window has expired."""
|
|
155
|
-
return datetime.now(timezone.utc) > self.reset_time
|
|
156
|
-
|
|
157
|
-
def time_until_reset(self) -> timedelta:
|
|
158
|
-
"""Get time until quota resets."""
|
|
159
|
-
now = datetime.now(timezone.utc)
|
|
160
|
-
if now >= self.reset_time:
|
|
161
|
-
return timedelta(0)
|
|
162
|
-
return self.reset_time - now
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
class RateLimitRequest(BaseModel):
|
|
166
|
-
"""Rate limit request tracking model."""
|
|
167
|
-
|
|
168
|
-
model_config = ConfigDict(extra="forbid")
|
|
169
|
-
|
|
170
|
-
# Request identification
|
|
171
|
-
request_id: str = Field(default_factory=lambda: str(uuid.uuid4()))
|
|
172
|
-
scope_id: str = Field(..., description="Scope identifier")
|
|
173
|
-
scope_type: RateLimitScope = Field(..., description="Scope type")
|
|
174
|
-
operation_type: str = Field(..., description="Type of operation")
|
|
175
|
-
|
|
176
|
-
# Timing
|
|
177
|
-
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
|
178
|
-
processing_time_ms: Optional[float] = Field(default=None, description="Processing time")
|
|
179
|
-
|
|
180
|
-
# Rate limit result
|
|
181
|
-
status: RateLimitStatus = Field(..., description="Rate limit decision")
|
|
182
|
-
retry_after_seconds: Optional[float] = Field(default=None, description="Retry after delay")
|
|
183
|
-
queue_position: Optional[int] = Field(default=None, description="Position in queue")
|
|
184
|
-
|
|
185
|
-
# Context
|
|
186
|
-
quota_remaining: int = Field(default=0, description="Remaining quota")
|
|
187
|
-
quota_reset_time: datetime = Field(..., description="Quota reset time")
|
|
188
|
-
backoff_count: int = Field(default=0, description="Number of backoff attempts")
|
|
189
|
-
|
|
190
|
-
# Metadata
|
|
191
|
-
user_agent: Optional[str] = Field(default=None, description="User agent")
|
|
192
|
-
ip_address: Optional[str] = Field(default=None, description="IP address")
|
|
193
|
-
additional_headers: Dict[str, str] = Field(
|
|
194
|
-
default_factory=dict, description="Additional request headers"
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
class RateLimitStatistics(BaseModel):
|
|
199
|
-
"""Rate limiting statistics model."""
|
|
200
|
-
|
|
201
|
-
model_config = ConfigDict(extra="forbid")
|
|
202
|
-
|
|
203
|
-
# Basic counters
|
|
204
|
-
total_requests: int = Field(default=0, description="Total requests processed")
|
|
205
|
-
allowed_requests: int = Field(default=0, description="Allowed requests")
|
|
206
|
-
throttled_requests: int = Field(default=0, description="Throttled requests")
|
|
207
|
-
rejected_requests: int = Field(default=0, description="Rejected requests")
|
|
208
|
-
|
|
209
|
-
# Performance metrics
|
|
210
|
-
avg_processing_time_ms: float = Field(default=0.0, description="Average processing time")
|
|
211
|
-
throttle_rate_percent: float = Field(default=0.0, description="Throttle rate percentage")
|
|
212
|
-
rejection_rate_percent: float = Field(default=0.0, description="Rejection rate percentage")
|
|
213
|
-
|
|
214
|
-
# Queue metrics
|
|
215
|
-
avg_queue_size: float = Field(default=0.0, description="Average queue size")
|
|
216
|
-
avg_queue_wait_time_ms: float = Field(default=0.0, description="Average queue wait time")
|
|
217
|
-
queue_timeouts: int = Field(default=0, description="Queue timeout count")
|
|
218
|
-
|
|
219
|
-
# Backoff metrics
|
|
220
|
-
total_backoffs: int = Field(default=0, description="Total backoff attempts")
|
|
221
|
-
avg_backoff_delay_ms: float = Field(default=0.0, description="Average backoff delay")
|
|
222
|
-
max_backoff_delay_ms: float = Field(default=0.0, description="Maximum backoff delay")
|
|
223
|
-
|
|
224
|
-
# Adaptive metrics (if enabled)
|
|
225
|
-
rate_adjustments: int = Field(default=0, description="Number of rate adjustments")
|
|
226
|
-
current_rate_multiplier: float = Field(default=1.0, description="Current rate multiplier")
|
|
227
|
-
system_load_percent: float = Field(default=0.0, description="Current system load")
|
|
228
|
-
|
|
229
|
-
# Time window
|
|
230
|
-
window_start: datetime = Field(
|
|
231
|
-
default_factory=lambda: datetime.now(timezone.utc), description="Statistics window start"
|
|
232
|
-
)
|
|
233
|
-
window_end: datetime = Field(
|
|
234
|
-
default_factory=lambda: datetime.now(timezone.utc), description="Statistics window end"
|
|
235
|
-
)
|
|
236
|
-
last_reset: datetime = Field(
|
|
237
|
-
default_factory=lambda: datetime.now(timezone.utc), description="Last statistics reset"
|
|
238
|
-
)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
class BackoffState(BaseModel):
|
|
242
|
-
"""Backoff state tracking model."""
|
|
243
|
-
|
|
244
|
-
model_config = ConfigDict(extra="forbid")
|
|
245
|
-
|
|
246
|
-
# Identification
|
|
247
|
-
scope_id: str = Field(..., description="Scope identifier")
|
|
248
|
-
operation_type: str = Field(..., description="Operation type")
|
|
249
|
-
|
|
250
|
-
# Backoff state
|
|
251
|
-
attempt_count: int = Field(default=0, description="Current attempt count")
|
|
252
|
-
current_delay_seconds: float = Field(default=0.0, description="Current delay")
|
|
253
|
-
next_retry_time: datetime = Field(..., description="Next retry time")
|
|
254
|
-
|
|
255
|
-
# Configuration
|
|
256
|
-
strategy: BackoffStrategy = Field(..., description="Backoff strategy")
|
|
257
|
-
base_delay: float = Field(..., description="Base delay")
|
|
258
|
-
max_delay: float = Field(..., description="Maximum delay")
|
|
259
|
-
multiplier: float = Field(default=2.0, description="Backoff multiplier")
|
|
260
|
-
|
|
261
|
-
# History
|
|
262
|
-
retry_history: List[datetime] = Field(
|
|
263
|
-
default_factory=list, description="Retry attempt timestamps"
|
|
264
|
-
)
|
|
265
|
-
success_time: Optional[datetime] = Field(default=None, description="Last success time")
|
|
266
|
-
|
|
267
|
-
def can_retry(self) -> bool:
|
|
268
|
-
"""Check if retry is allowed now."""
|
|
269
|
-
return datetime.now(timezone.utc) >= self.next_retry_time
|
|
270
|
-
|
|
271
|
-
def time_until_retry(self) -> timedelta:
|
|
272
|
-
"""Get time until next retry is allowed."""
|
|
273
|
-
now = datetime.now(timezone.utc)
|
|
274
|
-
if now >= self.next_retry_time:
|
|
275
|
-
return timedelta(0)
|
|
276
|
-
return self.next_retry_time - now
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
__all__ = [
|
|
280
|
-
# Enums
|
|
281
|
-
"RateLimitStrategy",
|
|
282
|
-
"BackoffStrategy",
|
|
283
|
-
"RateLimitScope",
|
|
284
|
-
"RateLimitStatus",
|
|
285
|
-
"RateLimitEventType",
|
|
286
|
-
|
|
287
|
-
# Configuration models
|
|
288
|
-
"RateLimitConfig",
|
|
289
|
-
|
|
290
|
-
# Data models
|
|
291
|
-
"RateLimitQuota",
|
|
292
|
-
"RateLimitRequest",
|
|
293
|
-
"RateLimitStatistics",
|
|
294
|
-
"BackoffState",
|
|
295
|
-
]
|