nucliadb-utils 6.4.0.post4161__py3-none-any.whl → 6.4.0.post4171__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.
- nucliadb_utils/audit/stream.py +3 -2
- nucliadb_utils/cache/nats.py +14 -8
- nucliadb_utils/cache/pubsub.py +6 -4
- nucliadb_utils/nats.py +12 -17
- nucliadb_utils/transaction.py +11 -6
- {nucliadb_utils-6.4.0.post4161.dist-info → nucliadb_utils-6.4.0.post4171.dist-info}/METADATA +3 -3
- {nucliadb_utils-6.4.0.post4161.dist-info → nucliadb_utils-6.4.0.post4171.dist-info}/RECORD +9 -9
- {nucliadb_utils-6.4.0.post4161.dist-info → nucliadb_utils-6.4.0.post4171.dist-info}/WHEEL +1 -1
- {nucliadb_utils-6.4.0.post4161.dist-info → nucliadb_utils-6.4.0.post4171.dist-info}/top_level.txt +0 -0
nucliadb_utils/audit/stream.py
CHANGED
@@ -58,9 +58,9 @@ from nucliadb_protos.kb_usage_pb2 import (
|
|
58
58
|
ClientType as ClientTypeKbUsage,
|
59
59
|
)
|
60
60
|
from nucliadb_protos.resources_pb2 import FieldID
|
61
|
+
from nucliadb_telemetry.jetstream import get_traced_jetstream, get_traced_nats_client
|
61
62
|
from nucliadb_utils import logger
|
62
63
|
from nucliadb_utils.audit.audit import AuditStorage
|
63
|
-
from nucliadb_utils.nats import get_traced_jetstream
|
64
64
|
from nucliadb_utils.nuclia_usage.utils.kb_usage_report import KbUsageReportUtility
|
65
65
|
|
66
66
|
|
@@ -207,7 +207,8 @@ class StreamAuditStorage(AuditStorage):
|
|
207
207
|
if len(self.nats_servers) > 0:
|
208
208
|
options["servers"] = self.nats_servers
|
209
209
|
|
210
|
-
|
210
|
+
nc = await nats.connect(**options)
|
211
|
+
self.nc = get_traced_nats_client(nc, self.service)
|
211
212
|
|
212
213
|
self.js = get_traced_jetstream(self.nc, self.service)
|
213
214
|
self.task = asyncio.create_task(self.run())
|
nucliadb_utils/cache/nats.py
CHANGED
@@ -23,7 +23,7 @@ import functools
|
|
23
23
|
import os
|
24
24
|
import uuid
|
25
25
|
from inspect import iscoroutinefunction
|
26
|
-
from typing import Dict, List, Optional
|
26
|
+
from typing import Dict, List, Optional, Union
|
27
27
|
|
28
28
|
import nats
|
29
29
|
import nats.errors
|
@@ -34,9 +34,14 @@ from nats.aio.subscription import Subscription
|
|
34
34
|
from nats.js.client import JetStreamContext
|
35
35
|
from nats.js.manager import JetStreamManager
|
36
36
|
|
37
|
+
from nucliadb_telemetry.jetstream import (
|
38
|
+
JetStreamContextTelemetry,
|
39
|
+
NatsClientTelemetry,
|
40
|
+
get_traced_jetstream,
|
41
|
+
get_traced_nats_client,
|
42
|
+
)
|
37
43
|
from nucliadb_utils import logger
|
38
44
|
from nucliadb_utils.cache.pubsub import Callback, PubSubDriver
|
39
|
-
from nucliadb_utils.nats import get_traced_jetstream
|
40
45
|
|
41
46
|
|
42
47
|
async def wait_for_it(future: asyncio.Future, msg):
|
@@ -46,7 +51,7 @@ async def wait_for_it(future: asyncio.Future, msg):
|
|
46
51
|
# Configuration Utility
|
47
52
|
|
48
53
|
|
49
|
-
class NatsPubsub(PubSubDriver):
|
54
|
+
class NatsPubsub(PubSubDriver[Msg]):
|
50
55
|
_jetstream = None
|
51
56
|
_jsm = None
|
52
57
|
_subscriptions: Dict[str, Subscription]
|
@@ -68,11 +73,11 @@ class NatsPubsub(PubSubDriver):
|
|
68
73
|
self._uuid = os.environ.get("HOSTNAME", uuid.uuid4().hex)
|
69
74
|
self.initialized = False
|
70
75
|
self.lock = asyncio.Lock()
|
71
|
-
self.nc = None
|
76
|
+
self.nc: Union[Client, NatsClientTelemetry, None] = None
|
72
77
|
self.user_credentials_file = user_credentials_file
|
73
78
|
|
74
79
|
@property
|
75
|
-
def jetstream(self) -> JetStreamContext:
|
80
|
+
def jetstream(self) -> Union[JetStreamContext, JetStreamContextTelemetry]:
|
76
81
|
if self.nc is None:
|
77
82
|
raise AttributeError("NC not initialized")
|
78
83
|
if self._jetstream is None:
|
@@ -91,7 +96,7 @@ class NatsPubsub(PubSubDriver):
|
|
91
96
|
# No asyncio loop to run
|
92
97
|
|
93
98
|
async with self.lock:
|
94
|
-
|
99
|
+
nc = Client()
|
95
100
|
options = {
|
96
101
|
"servers": self._hosts,
|
97
102
|
"disconnected_cb": self.disconnected_cb,
|
@@ -104,11 +109,12 @@ class NatsPubsub(PubSubDriver):
|
|
104
109
|
if self.user_credentials_file is not None:
|
105
110
|
options["user_credentials"] = self.user_credentials_file
|
106
111
|
try:
|
107
|
-
await
|
112
|
+
await nc.connect(**options)
|
108
113
|
except ErrNoServers:
|
109
114
|
logger.exception("No servers found")
|
110
115
|
raise
|
111
116
|
|
117
|
+
self.nc = get_traced_nats_client(nc, "nucliadb_pubsub")
|
112
118
|
logger.info("Connected to nats")
|
113
119
|
|
114
120
|
self.initialized = True
|
@@ -199,7 +205,7 @@ class NatsPubsub(PubSubDriver):
|
|
199
205
|
else:
|
200
206
|
raise ErrConnectionClosed("Could not publish")
|
201
207
|
|
202
|
-
def parse(self, data: Msg):
|
208
|
+
def parse(self, data: Msg) -> bytes:
|
203
209
|
return data.data
|
204
210
|
|
205
211
|
|
nucliadb_utils/cache/pubsub.py
CHANGED
@@ -17,12 +17,14 @@
|
|
17
17
|
# You should have received a copy of the GNU Affero General Public License
|
18
18
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
#
|
20
|
-
from typing import
|
20
|
+
from typing import Awaitable, Callable, Generic, Optional, TypeVar
|
21
21
|
|
22
|
-
|
22
|
+
T = TypeVar("T")
|
23
23
|
|
24
|
+
Callback = Callable[[T], Awaitable[None]]
|
24
25
|
|
25
|
-
|
26
|
+
|
27
|
+
class PubSubDriver(Generic[T]):
|
26
28
|
initialized: bool = False
|
27
29
|
async_callback: bool = False
|
28
30
|
|
@@ -47,5 +49,5 @@ class PubSubDriver:
|
|
47
49
|
):
|
48
50
|
raise NotImplementedError()
|
49
51
|
|
50
|
-
def parse(self, data:
|
52
|
+
def parse(self, data: T) -> bytes:
|
51
53
|
raise NotImplementedError()
|
nucliadb_utils/nats.py
CHANGED
@@ -33,24 +33,18 @@ from nats.aio.subscription import Subscription
|
|
33
33
|
from nats.js.client import JetStreamContext
|
34
34
|
|
35
35
|
from nucliadb_telemetry.errors import capture_exception
|
36
|
-
from nucliadb_telemetry.jetstream import
|
36
|
+
from nucliadb_telemetry.jetstream import (
|
37
|
+
JetStreamContextTelemetry,
|
38
|
+
NatsClientTelemetry,
|
39
|
+
get_traced_nats_client,
|
40
|
+
)
|
37
41
|
from nucliadb_telemetry.metrics import Counter
|
38
|
-
from nucliadb_telemetry.utils import get_telemetry
|
39
42
|
|
40
43
|
logger = logging.getLogger(__name__)
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
) -> Union[JetStreamContext, JetStreamContextTelemetry]:
|
46
|
-
jetstream = nc.jetstream()
|
47
|
-
tracer_provider = get_telemetry(service_name)
|
48
|
-
|
49
|
-
if tracer_provider is not None and jetstream is not None: # pragma: no cover
|
50
|
-
logger.info(f"Configuring {service_name} jetstream with telemetry")
|
51
|
-
return JetStreamContextTelemetry(jetstream, service_name, tracer_provider)
|
52
|
-
else:
|
53
|
-
return jetstream
|
45
|
+
# Re-export for bw/c. This function was defined here but makes more sense in the
|
46
|
+
# telemetry library
|
47
|
+
from nucliadb_telemetry.jetstream import get_traced_jetstream # noqa
|
54
48
|
|
55
49
|
|
56
50
|
class MessageProgressUpdater:
|
@@ -105,7 +99,7 @@ class MessageProgressUpdater:
|
|
105
99
|
|
106
100
|
|
107
101
|
class NatsConnectionManager:
|
108
|
-
_nc: NATSClient
|
102
|
+
_nc: Union[NATSClient, NatsClientTelemetry]
|
109
103
|
_subscriptions: list[tuple[Subscription, Callable[[], Awaitable[None]]]]
|
110
104
|
_pull_subscriptions: list[
|
111
105
|
tuple[
|
@@ -169,7 +163,8 @@ class NatsConnectionManager:
|
|
169
163
|
options["servers"] = self._nats_servers
|
170
164
|
|
171
165
|
async with self._lock:
|
172
|
-
|
166
|
+
nc = await nats.connect(**options)
|
167
|
+
self._nc = get_traced_nats_client(nc, self._service_name)
|
173
168
|
|
174
169
|
self._expected_subscription_task = asyncio.create_task(self._verify_expected_subscriptions())
|
175
170
|
|
@@ -310,7 +305,7 @@ class NatsConnectionManager:
|
|
310
305
|
logger.info("Connection is closed on NATS")
|
311
306
|
|
312
307
|
@property
|
313
|
-
def nc(self) -> NATSClient:
|
308
|
+
def nc(self) -> Union[NATSClient, NatsClientTelemetry]:
|
314
309
|
return self._nc
|
315
310
|
|
316
311
|
@cached_property
|
nucliadb_utils/transaction.py
CHANGED
@@ -35,10 +35,14 @@ from nucliadb_protos.writer_pb2 import (
|
|
35
35
|
Notification,
|
36
36
|
OpStatusWriter,
|
37
37
|
)
|
38
|
-
from nucliadb_telemetry.jetstream import
|
38
|
+
from nucliadb_telemetry.jetstream import (
|
39
|
+
JetStreamContextTelemetry,
|
40
|
+
NatsClientTelemetry,
|
41
|
+
get_traced_jetstream,
|
42
|
+
get_traced_nats_client,
|
43
|
+
)
|
39
44
|
from nucliadb_utils import const, logger
|
40
45
|
from nucliadb_utils.cache.pubsub import PubSubDriver
|
41
|
-
from nucliadb_utils.nats import get_traced_jetstream
|
42
46
|
from nucliadb_utils.utilities import get_pubsub
|
43
47
|
|
44
48
|
|
@@ -95,7 +99,7 @@ class LocalTransactionUtility:
|
|
95
99
|
|
96
100
|
|
97
101
|
class TransactionUtility:
|
98
|
-
nc: Client
|
102
|
+
nc: Union[Client, NatsClientTelemetry]
|
99
103
|
js: Union[JetStreamContext, JetStreamContextTelemetry]
|
100
104
|
pubsub: PubSubDriver
|
101
105
|
|
@@ -139,8 +143,8 @@ class TransactionUtility:
|
|
139
143
|
) -> Optional[Event]:
|
140
144
|
action_type = self._get_notification_action_type()
|
141
145
|
|
142
|
-
def received(waiting_for: WaitFor, event: Event,
|
143
|
-
data = self.pubsub.parse(
|
146
|
+
def received(waiting_for: WaitFor, event: Event, msg: Any):
|
147
|
+
data = self.pubsub.parse(msg)
|
144
148
|
pb = Notification()
|
145
149
|
pb.ParseFromString(data)
|
146
150
|
if pb.uuid == waiting_for.uuid and pb.action == action_type:
|
@@ -177,7 +181,8 @@ class TransactionUtility:
|
|
177
181
|
if len(self.nats_servers) > 0:
|
178
182
|
options["servers"] = self.nats_servers
|
179
183
|
|
180
|
-
|
184
|
+
nc = await nats.connect(**options)
|
185
|
+
self.nc = get_traced_nats_client(nc, service_name or "nucliadb")
|
181
186
|
self.js = get_traced_jetstream(self.nc, service_name or "nucliadb")
|
182
187
|
|
183
188
|
async def finalize(self):
|
{nucliadb_utils-6.4.0.post4161.dist-info → nucliadb_utils-6.4.0.post4171.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nucliadb_utils
|
3
|
-
Version: 6.4.0.
|
3
|
+
Version: 6.4.0.post4171
|
4
4
|
Summary: NucliaDB util library
|
5
5
|
Author-email: Nuclia <nucliadb@nuclia.com>
|
6
6
|
License: AGPL
|
@@ -27,8 +27,8 @@ Requires-Dist: nats-py[nkeys]>=2.6.0
|
|
27
27
|
Requires-Dist: PyNaCl
|
28
28
|
Requires-Dist: pyjwt>=2.4.0
|
29
29
|
Requires-Dist: mrflagly>=0.2.9
|
30
|
-
Requires-Dist: nucliadb-protos>=6.4.0.
|
31
|
-
Requires-Dist: nucliadb-telemetry>=6.4.0.
|
30
|
+
Requires-Dist: nucliadb-protos>=6.4.0.post4171
|
31
|
+
Requires-Dist: nucliadb-telemetry>=6.4.0.post4171
|
32
32
|
Provides-Extra: cache
|
33
33
|
Requires-Dist: redis>=4.3.4; extra == "cache"
|
34
34
|
Requires-Dist: orjson>=3.6.7; extra == "cache"
|
@@ -7,14 +7,14 @@ nucliadb_utils/exceptions.py,sha256=y_3wk77WLVUtdo-5FtbBsdSkCtK_DsJkdWb5BoPn3qo,
|
|
7
7
|
nucliadb_utils/featureflagging.py,sha256=SYqr31e0_NeOMx6dZgSiDO9VJiV6xxYhM_gWkk8ITTQ,2386
|
8
8
|
nucliadb_utils/grpc.py,sha256=apu0uePnkGHCAT7GRQ9YZfRYyFj26kJ440i8jitbM3U,3314
|
9
9
|
nucliadb_utils/helpers.py,sha256=nPw8yod3hP-pxq80VF8QC36s7ygSg0dBUdfI-LatvCs,1600
|
10
|
-
nucliadb_utils/nats.py,sha256=
|
10
|
+
nucliadb_utils/nats.py,sha256=T5A_pH0koGPNH9IPNPv1LsYGnAS5hnJgN8VuNCqO_p8,15989
|
11
11
|
nucliadb_utils/partition.py,sha256=jBgy4Hu5Iwn4gjbPPcthSykwf-qNx-GcLAIwbzPd1d0,1157
|
12
12
|
nucliadb_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
13
|
nucliadb_utils/run.py,sha256=Es0_Bu5Yc-LWczvwL6gzWqSwC85RjDCk-0oFQAJi9g4,1827
|
14
14
|
nucliadb_utils/settings.py,sha256=RnGhEUvwv6faNqALiqDCivvzNOyyXVBflYh_37uNkow,8193
|
15
15
|
nucliadb_utils/signals.py,sha256=lo_Mk12NIX5Au--3H3WObvDOXq_OMurql2qiC2TnAao,2676
|
16
16
|
nucliadb_utils/store.py,sha256=kQ35HemE0v4_Qg6xVqNIJi8vSFAYQtwI3rDtMsNy62Y,890
|
17
|
-
nucliadb_utils/transaction.py,sha256=
|
17
|
+
nucliadb_utils/transaction.py,sha256=l3ZvrITYMnAs_fv1OOC-1nDZxWPG5qmbBhzvuC3DUzQ,8039
|
18
18
|
nucliadb_utils/utilities.py,sha256=w4nsdyiFgZVEq5aBhjzVg176UDJNxfhIEfDbEi8bJdA,15604
|
19
19
|
nucliadb_utils/aiopynecone/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
|
20
20
|
nucliadb_utils/aiopynecone/client.py,sha256=MPyHnDXwhukJr7U3CJh7BpsekfSuOkyM4g5b9LLtzc8,22941
|
@@ -23,11 +23,11 @@ nucliadb_utils/aiopynecone/models.py,sha256=XkNIZx4bxdbVo9zYVn8IRp70q4DWUMWN79yb
|
|
23
23
|
nucliadb_utils/audit/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
|
24
24
|
nucliadb_utils/audit/audit.py,sha256=QNrohgWcWkO0exDOi-U7wp1YY7s8ezJqJESWGx4KnYM,3493
|
25
25
|
nucliadb_utils/audit/basic.py,sha256=4NX3IkZtTM_F2jD9TGE8-1eoS-hc-_zWwFGYVahGNSs,4141
|
26
|
-
nucliadb_utils/audit/stream.py,sha256=
|
26
|
+
nucliadb_utils/audit/stream.py,sha256=XEY4wRxEPdrwaBtepT2-4fmeNSaCcyhMf4sZjiJVA6A,17261
|
27
27
|
nucliadb_utils/cache/__init__.py,sha256=itSI7dtTwFP55YMX4iK7JzdMHS5CQVUiB1XzQu4UBh8,833
|
28
28
|
nucliadb_utils/cache/exceptions.py,sha256=Zu-O_-0-yctOEgoDGI92gPzWfBMRrpiAyESA62ld6MA,975
|
29
|
-
nucliadb_utils/cache/nats.py,sha256
|
30
|
-
nucliadb_utils/cache/pubsub.py,sha256=
|
29
|
+
nucliadb_utils/cache/nats.py,sha256=3aV25374fsA_oOr9ZqLDxhNn700O7CIagJ-0Y-ojwqE,7294
|
30
|
+
nucliadb_utils/cache/pubsub.py,sha256=YvJHiEhDaMIPofgQRpGY1belN--pOPyfYO1wFTUclt4,1701
|
31
31
|
nucliadb_utils/cache/settings.py,sha256=WVeHOE6Re5i4k2hUHdFKfkoL4n83v_Z6UPBK6GHYb8g,1059
|
32
32
|
nucliadb_utils/encryption/__init__.py,sha256=oav6jFOTGgmIen88sdmy-bCK-uj1tyDt2hr7lB2YKik,2690
|
33
33
|
nucliadb_utils/encryption/settings.py,sha256=yF2AW6c_mu0yWbBn1grAERDAqDvKIpXqQnwD0OFmROI,1467
|
@@ -57,7 +57,7 @@ nucliadb_utils/tests/gcs.py,sha256=MBMzn_UHU5SU6iILuCsB5zU4umhNcaCw_MKrxZhwvOc,4
|
|
57
57
|
nucliadb_utils/tests/local.py,sha256=cxIfPrKuqs5Ef0nbrVYQQAH2mwc4E0iD9bC2sWegS-c,1934
|
58
58
|
nucliadb_utils/tests/nats.py,sha256=RWHjwqq5esuO7OFbP24yYX1cXnpPLcWJwDUdmwCpH28,1897
|
59
59
|
nucliadb_utils/tests/s3.py,sha256=DACUh3HvgH3BchKFZ9R7RFUzsrg3v9A-cxTcXx4nmvA,3734
|
60
|
-
nucliadb_utils-6.4.0.
|
61
|
-
nucliadb_utils-6.4.0.
|
62
|
-
nucliadb_utils-6.4.0.
|
63
|
-
nucliadb_utils-6.4.0.
|
60
|
+
nucliadb_utils-6.4.0.post4171.dist-info/METADATA,sha256=kcPzFKSAR8qvmsclZQgjIb33iOFL9WcO1k_zaYJ7m_s,2205
|
61
|
+
nucliadb_utils-6.4.0.post4171.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
|
62
|
+
nucliadb_utils-6.4.0.post4171.dist-info/top_level.txt,sha256=fE3vJtALTfgh7bcAWcNhcfXkNPp_eVVpbKK-2IYua3E,15
|
63
|
+
nucliadb_utils-6.4.0.post4171.dist-info/RECORD,,
|
{nucliadb_utils-6.4.0.post4161.dist-info → nucliadb_utils-6.4.0.post4171.dist-info}/top_level.txt
RENAMED
File without changes
|