sovereign 1.0.0a4__py3-none-any.whl → 1.0.0b148__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.
Potentially problematic release.
This version of sovereign might be problematic. Click here for more details.
- sovereign/__init__.py +2 -2
- sovereign/app.py +3 -6
- sovereign/cache/__init__.py +12 -85
- sovereign/cache/backends/__init__.py +1 -1
- sovereign/cache/backends/s3.py +6 -24
- sovereign/cache/filesystem.py +5 -6
- sovereign/cache/types.py +0 -2
- sovereign/configuration.py +8 -42
- sovereign/context.py +9 -8
- sovereign/dynamic_config/__init__.py +4 -3
- sovereign/dynamic_config/deser.py +1 -1
- sovereign/dynamic_config/loaders.py +3 -3
- sovereign/error_info.py +3 -2
- sovereign/events.py +3 -3
- sovereign/logging/access_logger.py +1 -1
- sovereign/logging/application_logger.py +1 -1
- sovereign/logging/bootstrapper.py +1 -1
- sovereign/modifiers/lib.py +1 -1
- sovereign/rendering.py +90 -22
- sovereign/response_class.py +2 -2
- sovereign/server.py +26 -45
- sovereign/sources/__init__.py +3 -0
- sovereign/sources/file.py +21 -0
- sovereign/sources/inline.py +39 -0
- sovereign/sources/lib.py +41 -0
- sovereign/sources/poller.py +537 -0
- sovereign/statistics.py +1 -2
- sovereign/testing/loaders.py +0 -1
- sovereign/tracing.py +5 -6
- sovereign/types.py +10 -15
- sovereign/utils/auth.py +2 -3
- sovereign/utils/crypto/suites/disabled_cipher.py +2 -2
- sovereign/utils/dictupdate.py +1 -1
- sovereign/utils/eds.py +1 -3
- sovereign/utils/entry_point_loader.py +2 -2
- sovereign/utils/mock.py +3 -4
- sovereign/utils/resources.py +1 -1
- sovereign/utils/templates.py +2 -4
- sovereign/utils/timer.py +3 -5
- sovereign/utils/weighted_clusters.py +1 -2
- sovereign/views/__init__.py +3 -6
- sovereign/views/api.py +7 -28
- sovereign/views/crypto.py +1 -1
- sovereign/views/discovery.py +5 -20
- sovereign/views/healthchecks.py +27 -45
- sovereign/views/interface.py +10 -70
- sovereign/worker.py +31 -20
- {sovereign-1.0.0a4.dist-info → sovereign-1.0.0b148.dist-info}/METADATA +3 -4
- sovereign-1.0.0b148.dist-info/RECORD +77 -0
- {sovereign-1.0.0a4.dist-info → sovereign-1.0.0b148.dist-info}/entry_points.txt +0 -8
- sovereign/rendering_common.py +0 -91
- sovereign/v2/__init__.py +0 -0
- sovereign/v2/data/data_store.py +0 -621
- sovereign/v2/data/render_discovery_response.py +0 -24
- sovereign/v2/data/repositories.py +0 -90
- sovereign/v2/data/utils.py +0 -33
- sovereign/v2/data/worker_queue.py +0 -273
- sovereign/v2/jobs/refresh_context.py +0 -117
- sovereign/v2/jobs/render_discovery_job.py +0 -145
- sovereign/v2/logging.py +0 -81
- sovereign/v2/types.py +0 -41
- sovereign/v2/web.py +0 -101
- sovereign/v2/worker.py +0 -199
- sovereign-1.0.0a4.dist-info/RECORD +0 -85
- {sovereign-1.0.0a4.dist-info → sovereign-1.0.0b148.dist-info}/WHEEL +0 -0
sovereign/__init__.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
from contextvars import ContextVar
|
|
2
2
|
from importlib.metadata import version
|
|
3
3
|
|
|
4
|
-
from sovereign.
|
|
4
|
+
from sovereign.utils.crypto.suites import EncryptionType
|
|
5
5
|
from sovereign.logging.bootstrapper import LoggerBootstrapper
|
|
6
|
+
from sovereign.configuration import config, EncryptionConfig
|
|
6
7
|
from sovereign.statistics import configure_statsd
|
|
7
8
|
from sovereign.utils.crypto.crypto import CipherContainer
|
|
8
|
-
from sovereign.utils.crypto.suites import EncryptionType
|
|
9
9
|
|
|
10
10
|
_request_id_ctx_var: ContextVar[str] = ContextVar("request_id", default="")
|
|
11
11
|
|
sovereign/app.py
CHANGED
|
@@ -7,12 +7,12 @@ from fastapi.responses import FileResponse, JSONResponse, RedirectResponse, Resp
|
|
|
7
7
|
from starlette_context.middleware import RawContextMiddleware
|
|
8
8
|
|
|
9
9
|
from sovereign import __version__, logs
|
|
10
|
-
from sovereign.configuration import
|
|
10
|
+
from sovereign.configuration import config, ConfiguredResourceTypes
|
|
11
|
+
from sovereign.response_class import json_response_class
|
|
11
12
|
from sovereign.error_info import ErrorInfo
|
|
12
13
|
from sovereign.middlewares import LoggingMiddleware, RequestContextLogMiddleware
|
|
13
|
-
from sovereign.response_class import json_response_class
|
|
14
14
|
from sovereign.utils.resources import get_package_file
|
|
15
|
-
from sovereign.views import
|
|
15
|
+
from sovereign.views import crypto, discovery, healthchecks, interface, api
|
|
16
16
|
|
|
17
17
|
Router = namedtuple("Router", "module tags prefix")
|
|
18
18
|
|
|
@@ -68,10 +68,7 @@ def init_app() -> FastAPI:
|
|
|
68
68
|
|
|
69
69
|
if dsn := config.sentry_dsn.get_secret_value():
|
|
70
70
|
try:
|
|
71
|
-
# noinspection PyUnusedImports
|
|
72
71
|
import sentry_sdk
|
|
73
|
-
|
|
74
|
-
# noinspection PyUnusedImports
|
|
75
72
|
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
|
|
76
73
|
|
|
77
74
|
sentry_sdk.init(dsn)
|
sovereign/cache/__init__.py
CHANGED
|
@@ -6,23 +6,20 @@ to configure their own remote cache backends through entry points.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
import asyncio
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import time
|
|
9
|
+
from typing import Any
|
|
10
|
+
from typing_extensions import final
|
|
12
11
|
|
|
13
12
|
import requests
|
|
14
|
-
from typing_extensions import final
|
|
15
13
|
|
|
16
|
-
from sovereign import WORKER_URL, stats
|
|
17
|
-
from sovereign import
|
|
14
|
+
from sovereign import WORKER_URL, stats, application_logger as log
|
|
15
|
+
from sovereign.types import DiscoveryRequest, RegisterClientRequest
|
|
16
|
+
from sovereign.configuration import config
|
|
17
|
+
from sovereign.cache.types import Entry, CacheResult
|
|
18
18
|
from sovereign.cache.backends import CacheBackend, get_backend
|
|
19
19
|
from sovereign.cache.filesystem import FilesystemCache
|
|
20
|
-
|
|
21
|
-
from sovereign.configuration import config
|
|
22
|
-
from sovereign.types import DiscoveryRequest, RegisterClientRequest
|
|
20
|
+
|
|
23
21
|
|
|
24
22
|
CACHE_READ_TIMEOUT = config.cache.read_timeout
|
|
25
|
-
REMOTE_TTL = 300 # 5 minutes - TTL for entries read from remote cache
|
|
26
23
|
|
|
27
24
|
|
|
28
25
|
class CacheManagerBase:
|
|
@@ -81,27 +78,12 @@ class CacheReader(CacheManagerBase):
|
|
|
81
78
|
return None
|
|
82
79
|
|
|
83
80
|
def get(self, req: DiscoveryRequest) -> Entry | None:
|
|
84
|
-
"""Read from cache, writing back from remote with short TTL if needed.
|
|
85
|
-
|
|
86
|
-
Flow:
|
|
87
|
-
1. Entry read from remote → cached with 300s TTL
|
|
88
|
-
2. Background registration triggers worker to generate fresh config
|
|
89
|
-
3. Remote entry expires after 300s
|
|
90
|
-
4. Next request gets worker-generated config (cached infinitely)
|
|
91
|
-
"""
|
|
92
81
|
id = client_id(req)
|
|
93
82
|
if result := self.try_read(id):
|
|
94
83
|
if result.from_remote:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
f"Cache writeback from remote: client_id={id} version={result.value.version} "
|
|
99
|
-
f"ttl={REMOTE_TTL} type=remote pid={os.getpid()}"
|
|
100
|
-
)
|
|
101
|
-
stats.increment("cache.fs.writeback", tags=["type:remote"])
|
|
102
|
-
|
|
103
|
-
# Background thread triggers worker to generate fresh config
|
|
104
|
-
self.register_async(req)
|
|
84
|
+
self.register(req)
|
|
85
|
+
# Write back to filesystem
|
|
86
|
+
self.local.set(id, result.value)
|
|
105
87
|
return result.value
|
|
106
88
|
return None
|
|
107
89
|
|
|
@@ -158,49 +140,6 @@ class CacheReader(CacheManagerBase):
|
|
|
158
140
|
log.exception(f"Error while registering client: {e}")
|
|
159
141
|
return False
|
|
160
142
|
|
|
161
|
-
def register_async(self, req: DiscoveryRequest):
|
|
162
|
-
"""Register client async to trigger worker to generate fresh config.
|
|
163
|
-
|
|
164
|
-
Registration tells the worker about this client so it generates fresh config.
|
|
165
|
-
"""
|
|
166
|
-
|
|
167
|
-
def job():
|
|
168
|
-
start_time = time.time()
|
|
169
|
-
attempts = 5
|
|
170
|
-
backoff = 1.0
|
|
171
|
-
attempt_num = 0
|
|
172
|
-
|
|
173
|
-
while attempts:
|
|
174
|
-
attempt_num += 1
|
|
175
|
-
if self.register_over_http(req):
|
|
176
|
-
duration_ms = (time.time() - start_time) * 1000
|
|
177
|
-
stats.increment(
|
|
178
|
-
"client.registration.async",
|
|
179
|
-
tags=["status:success", f"attempts:{attempt_num}"],
|
|
180
|
-
)
|
|
181
|
-
stats.timing("client.registration.async.duration_ms", duration_ms)
|
|
182
|
-
log.debug(f"Async registration succeeded: attempts={attempt_num}")
|
|
183
|
-
return
|
|
184
|
-
attempts -= 1
|
|
185
|
-
if attempts:
|
|
186
|
-
log.debug(
|
|
187
|
-
f"Async registration failed: retrying_in={backoff}s remaining={attempts}"
|
|
188
|
-
)
|
|
189
|
-
time.sleep(backoff)
|
|
190
|
-
backoff *= 2
|
|
191
|
-
|
|
192
|
-
# Registration failed - entry stays at REMOTE_TTL, will expire and retry
|
|
193
|
-
duration_ms = (time.time() - start_time) * 1000
|
|
194
|
-
stats.increment("client.registration.async", tags=["status:exhausted"])
|
|
195
|
-
stats.timing("client.registration.async.duration_ms", duration_ms)
|
|
196
|
-
log.warning(
|
|
197
|
-
f"Async registration exhausted for {req}: remote entry will expire "
|
|
198
|
-
f"in {REMOTE_TTL}s and retry"
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
t = threading.Thread(target=job)
|
|
202
|
-
t.start()
|
|
203
|
-
|
|
204
143
|
|
|
205
144
|
@final
|
|
206
145
|
class CacheWriter(CacheManagerBase):
|
|
@@ -211,31 +150,19 @@ class CacheWriter(CacheManagerBase):
|
|
|
211
150
|
cached = False
|
|
212
151
|
try:
|
|
213
152
|
self.local.set(key, value, timeout)
|
|
214
|
-
log.info(
|
|
215
|
-
f"Cache write to filesystem: client_id={key} version={value.version} "
|
|
216
|
-
f"ttl={timeout} pid={os.getpid()} thread_id={threading.get_ident()}"
|
|
217
|
-
)
|
|
218
153
|
stats.increment("cache.fs.write.success")
|
|
219
154
|
cached = True
|
|
220
155
|
except Exception as e:
|
|
221
|
-
log.warning(
|
|
222
|
-
f"Failed to write to filesystem cache: client_id={key} error={e}"
|
|
223
|
-
)
|
|
156
|
+
log.warning(f"Failed to write to filesystem cache: {e}")
|
|
224
157
|
msg.append(("warning", f"Failed to write to filesystem cache: {e}"))
|
|
225
158
|
stats.increment("cache.fs.write.error")
|
|
226
159
|
if self.remote:
|
|
227
160
|
try:
|
|
228
161
|
self.remote.set(key, value, timeout)
|
|
229
|
-
log.info(
|
|
230
|
-
f"Cache write to remote: client_id={key} version={value.version} "
|
|
231
|
-
f"ttl={timeout} pid={os.getpid()} thread_id={threading.get_ident()}"
|
|
232
|
-
)
|
|
233
162
|
stats.increment("cache.remote.write.success")
|
|
234
163
|
cached = True
|
|
235
164
|
except Exception as e:
|
|
236
|
-
log.warning(
|
|
237
|
-
f"Failed to write to remote cache: client_id={key} error={e}"
|
|
238
|
-
)
|
|
165
|
+
log.warning(f"Failed to write to remote cache: {e}")
|
|
239
166
|
msg.append(("warning", f"Failed to write to remote cache: {e}"))
|
|
240
167
|
stats.increment("cache.remote.write.error")
|
|
241
168
|
return cached, msg
|
|
@@ -7,7 +7,7 @@ the loading mechanism for extensible cache backends via entry points.
|
|
|
7
7
|
|
|
8
8
|
from collections.abc import Sequence
|
|
9
9
|
from importlib.metadata import EntryPoints
|
|
10
|
-
from typing import
|
|
10
|
+
from typing import Protocol, Any, runtime_checkable
|
|
11
11
|
|
|
12
12
|
from sovereign import application_logger as log
|
|
13
13
|
from sovereign.utils.entry_point_loader import EntryPointLoader
|
sovereign/cache/backends/s3.py
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import pickle
|
|
2
|
-
import
|
|
3
|
-
from datetime import datetime, timedelta, timezone
|
|
4
|
-
from importlib.util import find_spec
|
|
2
|
+
from datetime import datetime, timezone, timedelta
|
|
5
3
|
from typing import Any
|
|
6
|
-
from urllib.parse import quote
|
|
7
|
-
|
|
8
4
|
from typing_extensions import override
|
|
5
|
+
from urllib.parse import quote
|
|
6
|
+
from importlib.util import find_spec
|
|
9
7
|
|
|
10
8
|
from sovereign import application_logger as log
|
|
11
9
|
from sovereign.cache.backends import CacheBackend
|
|
12
10
|
|
|
13
11
|
try:
|
|
14
|
-
# noinspection PyUnusedImports
|
|
15
12
|
import boto3
|
|
16
|
-
|
|
17
|
-
# noinspection PyUnusedImports
|
|
18
13
|
from botocore.exceptions import ClientError
|
|
19
14
|
except ImportError:
|
|
20
15
|
pass
|
|
@@ -71,10 +66,9 @@ class S3Client:
|
|
|
71
66
|
class S3Backend(CacheBackend):
|
|
72
67
|
"""S3 cache backend implementation"""
|
|
73
68
|
|
|
74
|
-
# noinspection PyMissingConstructor,PyProtocol
|
|
75
69
|
@override
|
|
76
|
-
def __init__(self, config: dict[str, Any]
|
|
77
|
-
"""
|
|
70
|
+
def __init__(self, config: dict[str, Any]) -> None: # pyright: ignore[reportMissingSuperCall]
|
|
71
|
+
"""Initialize S3 backend
|
|
78
72
|
|
|
79
73
|
Args:
|
|
80
74
|
config: Configuration dictionary containing S3 connection parameters
|
|
@@ -91,7 +85,6 @@ class S3Backend(CacheBackend):
|
|
|
91
85
|
self.prefix = config.get("prefix", "sovereign-cache")
|
|
92
86
|
self.registration_prefix = config.get("registration_prefix", "registrations-")
|
|
93
87
|
self.role = config.get("assume_role")
|
|
94
|
-
self.remote_cache_key_suffix = config.get("remote_cache_key_suffix")
|
|
95
88
|
|
|
96
89
|
client_args: dict[str, Any] = {}
|
|
97
90
|
if endpoint_url := config.get("endpoint_url"):
|
|
@@ -104,24 +97,13 @@ class S3Backend(CacheBackend):
|
|
|
104
97
|
self.s3.head_bucket(Bucket=self.bucket_name)
|
|
105
98
|
log.info(f"S3 cache backend connected to bucket '{self.bucket_name}'")
|
|
106
99
|
except Exception as e:
|
|
107
|
-
if attempts == 0:
|
|
108
|
-
# wait 5 seconds and then try to access the bucket again
|
|
109
|
-
time.sleep(5)
|
|
110
|
-
self.__init__(config, attempts + 1)
|
|
111
|
-
return
|
|
112
|
-
|
|
113
100
|
log.error(
|
|
114
101
|
f"Failed to access S3 bucket '{self.bucket_name}' with current credentials: {e}"
|
|
115
102
|
)
|
|
116
103
|
raise
|
|
117
104
|
|
|
118
105
|
def _make_key(self, key: str) -> str:
|
|
119
|
-
|
|
120
|
-
if self.remote_cache_key_suffix:
|
|
121
|
-
encoded_key = quote(f"{key}-{self.remote_cache_key_suffix}", safe="")
|
|
122
|
-
log.info(f"Using remote cache key: {encoded_key}")
|
|
123
|
-
else:
|
|
124
|
-
encoded_key = quote(key, safe="")
|
|
106
|
+
encoded_key = quote(key, safe="")
|
|
125
107
|
return f"{self.prefix}/{encoded_key}"
|
|
126
108
|
|
|
127
109
|
def get(self, key: str) -> Any | None:
|
sovereign/cache/filesystem.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import sqlite3
|
|
3
|
-
from hashlib import sha256
|
|
4
3
|
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
from cachelib import FileSystemCache
|
|
4
|
+
from hashlib import sha256
|
|
7
5
|
from typing_extensions import final
|
|
6
|
+
from cachelib import FileSystemCache
|
|
8
7
|
|
|
9
|
-
from sovereign.configuration import config
|
|
10
8
|
from sovereign.types import DiscoveryRequest
|
|
9
|
+
from sovereign.configuration import config
|
|
10
|
+
|
|
11
11
|
|
|
12
12
|
INIT = """
|
|
13
13
|
CREATE TABLE IF NOT EXISTS registered_clients (
|
|
@@ -24,8 +24,7 @@ SEARCH = "SELECT 1 FROM registered_clients WHERE client_id = ?"
|
|
|
24
24
|
class FilesystemCache:
|
|
25
25
|
def __init__(self, cache_path: str | None = None, default_timeout: int = 0):
|
|
26
26
|
self.cache_path = cache_path or config.cache.local_fs_path
|
|
27
|
-
self.default_timeout = default_timeout
|
|
28
|
-
|
|
27
|
+
self.default_timeout = default_timeout
|
|
29
28
|
self._cache = FileSystemCache(
|
|
30
29
|
cache_dir=self.cache_path,
|
|
31
30
|
default_timeout=self.default_timeout,
|
sovereign/cache/types.py
CHANGED
sovereign/configuration.py
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import multiprocessing
|
|
1
|
+
from collections import defaultdict
|
|
3
2
|
import os
|
|
4
3
|
import warnings
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import importlib
|
|
5
|
+
import multiprocessing
|
|
6
|
+
from pathlib import Path
|
|
7
7
|
from enum import Enum
|
|
8
8
|
from os import getenv
|
|
9
|
-
from
|
|
9
|
+
from dataclasses import dataclass
|
|
10
10
|
from typing import (
|
|
11
11
|
Any,
|
|
12
|
-
Callable,
|
|
13
12
|
Dict,
|
|
14
13
|
Mapping,
|
|
15
14
|
Optional,
|
|
16
15
|
Self,
|
|
17
16
|
Union,
|
|
17
|
+
Callable,
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
from croniter import CroniterBadCronError, croniter
|
|
@@ -22,15 +22,15 @@ from pydantic import (
|
|
|
22
22
|
BaseModel,
|
|
23
23
|
Field,
|
|
24
24
|
SecretStr,
|
|
25
|
-
field_validator,
|
|
26
25
|
model_validator,
|
|
26
|
+
field_validator,
|
|
27
27
|
)
|
|
28
28
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
29
29
|
|
|
30
30
|
from sovereign.dynamic_config import Loadable
|
|
31
31
|
from sovereign.types import XdsTemplate
|
|
32
|
-
from sovereign.utils import dictupdate
|
|
33
32
|
from sovereign.utils.crypto.suites import EncryptionType
|
|
33
|
+
from sovereign.utils import dictupdate
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
class CacheStrategy(str, Enum):
|
|
@@ -48,7 +48,6 @@ class ConfiguredSource(BaseModel):
|
|
|
48
48
|
scope: str = "default" # backward compatibility
|
|
49
49
|
|
|
50
50
|
|
|
51
|
-
# noinspection DuplicatedCode
|
|
52
51
|
class StatsdConfig(BaseModel):
|
|
53
52
|
host: str = "127.0.0.1"
|
|
54
53
|
port: Union[int, str] = 8125
|
|
@@ -217,7 +216,6 @@ class AccessLogConfiguration(BaseSettings):
|
|
|
217
216
|
)
|
|
218
217
|
|
|
219
218
|
|
|
220
|
-
# noinspection PyArgumentList
|
|
221
219
|
class LoggingConfiguration(BaseSettings):
|
|
222
220
|
application_logs: ApplicationLogConfiguration = ApplicationLogConfiguration()
|
|
223
221
|
access_logs: AccessLogConfiguration = AccessLogConfiguration()
|
|
@@ -303,7 +301,6 @@ class SourcesConfiguration(BaseSettings):
|
|
|
303
301
|
)
|
|
304
302
|
|
|
305
303
|
|
|
306
|
-
# noinspection DuplicatedCode
|
|
307
304
|
class TracingConfig(BaseSettings):
|
|
308
305
|
enabled: bool = Field(False)
|
|
309
306
|
collector: str = Field("notset")
|
|
@@ -463,10 +460,6 @@ class CacheConfiguration(BaseModel):
|
|
|
463
460
|
default_factory=default_hash_rules,
|
|
464
461
|
description="The set of JMES expressions against incoming Discovery Requests used to form a cache key.",
|
|
465
462
|
)
|
|
466
|
-
poll_interval_secs: float = Field(
|
|
467
|
-
0.5,
|
|
468
|
-
description="How many seconds to wait between each read attempt from the cache",
|
|
469
|
-
)
|
|
470
463
|
read_timeout: float = Field(
|
|
471
464
|
5.0,
|
|
472
465
|
description="How long to block when trying to read from the cache before giving up",
|
|
@@ -480,7 +473,6 @@ class CacheConfiguration(BaseModel):
|
|
|
480
473
|
)
|
|
481
474
|
|
|
482
475
|
|
|
483
|
-
# noinspection PyArgumentList
|
|
484
476
|
class SovereignConfigv2(BaseSettings):
|
|
485
477
|
# Config generation
|
|
486
478
|
templates: TemplateConfiguration
|
|
@@ -496,32 +488,6 @@ class SovereignConfigv2(BaseSettings):
|
|
|
496
488
|
worker_host: Optional[str] = Field("localhost", alias="SOVEREIGN_WORKER_HOST")
|
|
497
489
|
worker_port: Optional[int] = Field(9080, alias="SOVEREIGN_WORKER_PORT")
|
|
498
490
|
|
|
499
|
-
# Worker v2
|
|
500
|
-
|
|
501
|
-
# only used for sqlite file path
|
|
502
|
-
worker_v2_data_store_path: Optional[str] = Field(
|
|
503
|
-
"/tmp/sovereign_v2_data_store.db",
|
|
504
|
-
alias="SOVEREIGN_WORKER_V2_DATA_STORE_PATH",
|
|
505
|
-
)
|
|
506
|
-
worker_v2_data_store_provider: Optional[str] = Field(
|
|
507
|
-
"sqlite",
|
|
508
|
-
alias="SOVEREIGN_WORKER_V2_DATA_STORE_PROVIDER",
|
|
509
|
-
)
|
|
510
|
-
worker_v2_queue_path: Optional[str] = Field(
|
|
511
|
-
"/tmp/sovereign_v2_queue.db",
|
|
512
|
-
alias="SOVEREIGN_WORKER_V2_QUEUE_PATH",
|
|
513
|
-
)
|
|
514
|
-
worker_v2_queue_provider: Optional[str] = Field(
|
|
515
|
-
"sqlite",
|
|
516
|
-
alias="SOVEREIGN_WORKER_V2_QUEUE_PROVIDER",
|
|
517
|
-
)
|
|
518
|
-
worker_v2_enabled: Optional[bool] = Field(
|
|
519
|
-
False, alias="SOVEREIGN_WORKER_V2_ENABLED"
|
|
520
|
-
)
|
|
521
|
-
worker_v2_queue_invsibility_time: Optional[int] = Field(
|
|
522
|
-
None, alias="SOVEREIGN_WORKER_V2_QUEUE_INVISIBILITY_TIME"
|
|
523
|
-
)
|
|
524
|
-
|
|
525
491
|
# Supervisord settings
|
|
526
492
|
supervisord: SupervisordConfig = SupervisordConfig()
|
|
527
493
|
|
sovereign/context.py
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import datetime
|
|
3
|
-
import heapq
|
|
4
|
-
import inspect
|
|
5
1
|
import time
|
|
2
|
+
import heapq
|
|
6
3
|
import zlib
|
|
4
|
+
import datetime
|
|
5
|
+
import asyncio
|
|
6
|
+
import inspect
|
|
7
7
|
from enum import Enum
|
|
8
8
|
from typing import Any, Callable, Optional, Union
|
|
9
|
+
from typing_extensions import final, override
|
|
9
10
|
|
|
10
11
|
import pydantic
|
|
11
12
|
from croniter import croniter
|
|
12
|
-
from typing_extensions import final, override
|
|
13
13
|
|
|
14
14
|
from sovereign import application_logger as log
|
|
15
|
+
from sovereign.types import DiscoveryRequest
|
|
15
16
|
from sovereign.configuration import config
|
|
16
|
-
from sovereign.dynamic_config import Loadable
|
|
17
|
-
from sovereign.events import Event, Topic, bus
|
|
18
17
|
from sovereign.statistics import configure_statsd
|
|
19
|
-
from sovereign.types import DiscoveryRequest
|
|
20
18
|
from sovereign.utils.timer import wait_until
|
|
19
|
+
from sovereign.dynamic_config import Loadable
|
|
20
|
+
from sovereign.events import bus, Event, Topic
|
|
21
|
+
|
|
21
22
|
|
|
22
23
|
stats = configure_statsd()
|
|
23
24
|
DEFAULT_RETRY_INTERVAL = config.template_context.refresh_retry_interval_secs
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
from typing import Any
|
|
3
3
|
|
|
4
|
-
from pydantic import BaseModel,
|
|
4
|
+
from pydantic import BaseModel, Field, ConfigDict
|
|
5
5
|
|
|
6
|
-
from sovereign.dynamic_config.deser import ConfigDeserializer
|
|
7
|
-
from sovereign.dynamic_config.loaders import CustomLoader
|
|
8
6
|
from sovereign.utils.entry_point_loader import EntryPointLoader
|
|
7
|
+
from sovereign.dynamic_config.loaders import CustomLoader
|
|
8
|
+
from sovereign.dynamic_config.deser import ConfigDeserializer
|
|
9
|
+
|
|
9
10
|
|
|
10
11
|
LOADERS: dict[str, CustomLoader] = {}
|
|
11
12
|
DESERIALIZERS: dict[str, ConfigDeserializer] = {}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import importlib
|
|
2
1
|
import os
|
|
3
|
-
|
|
4
|
-
from pathlib import Path
|
|
2
|
+
import importlib
|
|
5
3
|
from typing import Any, Protocol
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from importlib.machinery import SourceFileLoader
|
|
6
6
|
|
|
7
7
|
import requests
|
|
8
8
|
|
sovereign/error_info.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import json
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
from typing import Union, Optional, Any
|
|
4
|
+
from dataclasses import dataclass, field, asdict
|
|
3
5
|
from functools import singledispatchmethod
|
|
4
|
-
from typing import Any, Optional, Union
|
|
5
6
|
|
|
6
7
|
from sovereign import get_request_id
|
|
7
8
|
|
sovereign/events.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import pydantic
|
|
2
|
+
from enum import IntEnum
|
|
1
3
|
from asyncio import Queue, gather
|
|
2
4
|
from collections import defaultdict
|
|
3
|
-
from
|
|
4
|
-
from typing import Sequence, final
|
|
5
|
+
from typing import final, Sequence
|
|
5
6
|
|
|
6
|
-
import pydantic
|
|
7
7
|
|
|
8
8
|
Primitives = str | int | float | bool | Sequence[str]
|
|
9
9
|
|
|
@@ -6,9 +6,9 @@ import structlog
|
|
|
6
6
|
from starlette_context import context
|
|
7
7
|
from structlog.stdlib import BoundLogger
|
|
8
8
|
|
|
9
|
-
from sovereign.configuration import SovereignConfigv2
|
|
10
9
|
from sovereign.logging.base_logger import BaseLogger
|
|
11
10
|
from sovereign.logging.types import EventDict, LoggingType, ProcessedMessage
|
|
11
|
+
from sovereign.configuration import SovereignConfigv2
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class AccessLogger(BaseLogger):
|
|
@@ -4,9 +4,9 @@ from typing import Any, Dict
|
|
|
4
4
|
import structlog
|
|
5
5
|
from structlog.stdlib import BoundLogger
|
|
6
6
|
|
|
7
|
-
from sovereign.configuration import SovereignConfigv2
|
|
8
7
|
from sovereign.logging.base_logger import BaseLogger
|
|
9
8
|
from sovereign.logging.types import EventDict, LoggingType, ProcessedMessage
|
|
9
|
+
from sovereign.configuration import SovereignConfigv2
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class ApplicationLogger(BaseLogger):
|
|
@@ -2,10 +2,10 @@ import structlog
|
|
|
2
2
|
from structlog.exceptions import DropEvent
|
|
3
3
|
from structlog.stdlib import BoundLogger
|
|
4
4
|
|
|
5
|
-
from sovereign.configuration import SovereignConfigv2
|
|
6
5
|
from sovereign.logging.access_logger import AccessLogger
|
|
7
6
|
from sovereign.logging.application_logger import ApplicationLogger
|
|
8
7
|
from sovereign.logging.types import EventDict, ProcessedMessage
|
|
8
|
+
from sovereign.configuration import SovereignConfigv2
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class LoggerBootstrapper:
|