dory-processor-sdk 0.0.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.
Files changed (86) hide show
  1. dory/__init__.py +101 -0
  2. dory/auth/__init__.py +10 -0
  3. dory/auth/oauth2.py +153 -0
  4. dory/auto_instrument.py +142 -0
  5. dory/cli/__init__.py +5 -0
  6. dory/cli/main.py +137 -0
  7. dory/cli/templates.py +123 -0
  8. dory/config/__init__.py +23 -0
  9. dory/config/defaults.py +24 -0
  10. dory/config/loader.py +430 -0
  11. dory/config/presets.py +73 -0
  12. dory/config/schema.py +84 -0
  13. dory/core/__init__.py +27 -0
  14. dory/core/app.py +434 -0
  15. dory/core/context.py +209 -0
  16. dory/core/lifecycle.py +214 -0
  17. dory/core/meta.py +121 -0
  18. dory/core/modes.py +479 -0
  19. dory/core/processor.py +564 -0
  20. dory/core/signals.py +122 -0
  21. dory/decorators.py +142 -0
  22. dory/edge/__init__.py +88 -0
  23. dory/edge/adaptive.py +644 -0
  24. dory/edge/detector.py +546 -0
  25. dory/edge/fencing.py +488 -0
  26. dory/edge/heartbeat.py +598 -0
  27. dory/edge/role.py +419 -0
  28. dory/errors/__init__.py +139 -0
  29. dory/errors/classification.py +362 -0
  30. dory/errors/codes.py +498 -0
  31. dory/geo/__init__.py +40 -0
  32. dory/geo/geolocalizer.py +1034 -0
  33. dory/health/__init__.py +12 -0
  34. dory/health/probes.py +210 -0
  35. dory/health/server.py +635 -0
  36. dory/k8s/__init__.py +80 -0
  37. dory/k8s/annotation_watcher.py +184 -0
  38. dory/k8s/client.py +251 -0
  39. dory/k8s/labels.py +505 -0
  40. dory/k8s/pod_metadata.py +182 -0
  41. dory/logging/__init__.py +9 -0
  42. dory/logging/logger.py +148 -0
  43. dory/metrics/__init__.py +7 -0
  44. dory/metrics/collector.py +301 -0
  45. dory/middleware/__init__.py +46 -0
  46. dory/middleware/connection_tracker.py +608 -0
  47. dory/middleware/request_id.py +325 -0
  48. dory/middleware/request_tracker.py +511 -0
  49. dory/migration/__init__.py +33 -0
  50. dory/migration/configmap.py +232 -0
  51. dory/migration/s3_store.py +594 -0
  52. dory/migration/serialization.py +135 -0
  53. dory/migration/state_manager.py +286 -0
  54. dory/migration/transfer.py +382 -0
  55. dory/monitoring/__init__.py +29 -0
  56. dory/monitoring/opentelemetry.py +489 -0
  57. dory/output/__init__.py +31 -0
  58. dory/output/envelope.py +137 -0
  59. dory/output/formatter.py +113 -0
  60. dory/output/rabbitmq.py +632 -0
  61. dory/output/routing.py +318 -0
  62. dory/output/validator.py +199 -0
  63. dory/py.typed +2 -0
  64. dory/recovery/__init__.py +60 -0
  65. dory/recovery/golden_image.py +487 -0
  66. dory/recovery/golden_snapshot.py +713 -0
  67. dory/recovery/golden_validator.py +518 -0
  68. dory/recovery/partial_recovery.py +482 -0
  69. dory/recovery/recovery_decision.py +242 -0
  70. dory/recovery/restart_detector.py +142 -0
  71. dory/recovery/state_validator.py +183 -0
  72. dory/resilience/__init__.py +45 -0
  73. dory/resilience/circuit_breaker.py +457 -0
  74. dory/resilience/retry.py +389 -0
  75. dory/simple.py +342 -0
  76. dory/types.py +68 -0
  77. dory/utils/__init__.py +31 -0
  78. dory/utils/errors.py +59 -0
  79. dory/utils/retry.py +115 -0
  80. dory/utils/timeout.py +80 -0
  81. dory_processor_sdk-0.0.1.dist-info/METADATA +424 -0
  82. dory_processor_sdk-0.0.1.dist-info/RECORD +86 -0
  83. dory_processor_sdk-0.0.1.dist-info/WHEEL +5 -0
  84. dory_processor_sdk-0.0.1.dist-info/entry_points.txt +2 -0
  85. dory_processor_sdk-0.0.1.dist-info/licenses/LICENSE +201 -0
  86. dory_processor_sdk-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,113 @@
1
+ """
2
+ Output formatting for processor results.
3
+
4
+ Provides pluggable formatters for serializing data before publishing.
5
+ """
6
+
7
+ import dataclasses
8
+ import json
9
+ import logging
10
+ from abc import ABC, abstractmethod
11
+ from datetime import datetime, date
12
+ from enum import Enum
13
+ from typing import Any
14
+ from uuid import UUID
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+
19
+ class OutputFormatter(ABC):
20
+ """Abstract base class for output formatters."""
21
+
22
+ @abstractmethod
23
+ def format(self, data: Any) -> bytes:
24
+ """Serialize data to bytes.
25
+
26
+ Args:
27
+ data: Data to serialize.
28
+
29
+ Returns:
30
+ Serialized bytes.
31
+ """
32
+ raise NotImplementedError
33
+
34
+ @property
35
+ @abstractmethod
36
+ def content_type(self) -> str:
37
+ """MIME type for the formatted output."""
38
+ raise NotImplementedError
39
+
40
+
41
+ class JSONFormatter(OutputFormatter):
42
+ """JSON output formatter with support for common Python types.
43
+
44
+ Handles serialization of datetime, UUID, Enum, and dataclass objects
45
+ via a custom default handler.
46
+
47
+ Args:
48
+ indent: JSON indentation level (None for compact).
49
+ sort_keys: Whether to sort dictionary keys.
50
+ max_size_bytes: Maximum allowed output size in bytes (0 = unlimited).
51
+ """
52
+
53
+ def __init__(
54
+ self,
55
+ indent: int | None = None,
56
+ sort_keys: bool = False,
57
+ max_size_bytes: int = 0,
58
+ ):
59
+ self._indent = indent
60
+ self._sort_keys = sort_keys
61
+ self._max_size_bytes = max_size_bytes
62
+
63
+ @property
64
+ def content_type(self) -> str:
65
+ return "application/json"
66
+
67
+ def format(self, data: Any) -> bytes:
68
+ """Serialize data to UTF-8 encoded JSON bytes.
69
+
70
+ Args:
71
+ data: Data to serialize. Must be JSON-serializable
72
+ (with support for datetime, UUID, Enum, dataclass).
73
+
74
+ Returns:
75
+ UTF-8 encoded JSON bytes.
76
+
77
+ Raises:
78
+ TypeError: If data contains non-serializable types.
79
+ ValueError: If serialized output exceeds max_size_bytes.
80
+ """
81
+ encoded = json.dumps(
82
+ data,
83
+ default=self._default_handler,
84
+ indent=self._indent,
85
+ sort_keys=self._sort_keys,
86
+ ensure_ascii=False,
87
+ ).encode("utf-8")
88
+
89
+ if self._max_size_bytes > 0 and len(encoded) > self._max_size_bytes:
90
+ raise ValueError(
91
+ f"Serialized output size {len(encoded)} bytes exceeds "
92
+ f"max_size_bytes limit of {self._max_size_bytes}"
93
+ )
94
+
95
+ return encoded
96
+
97
+ @staticmethod
98
+ def _default_handler(obj: Any) -> Any:
99
+ """Handle non-standard JSON types.
100
+
101
+ Supports: datetime, date, UUID, Enum, dataclass.
102
+ """
103
+ if isinstance(obj, datetime):
104
+ return obj.isoformat()
105
+ if isinstance(obj, date):
106
+ return obj.isoformat()
107
+ if isinstance(obj, UUID):
108
+ return str(obj)
109
+ if isinstance(obj, Enum):
110
+ return obj.value
111
+ if dataclasses.is_dataclass(obj) and not isinstance(obj, type):
112
+ return dataclasses.asdict(obj)
113
+ raise TypeError(f"Object of type {type(obj).__name__} is not JSON serializable")