nucliadb 6.4.0.post4279__py3-none-any.whl → 6.4.0.post4287__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.
@@ -188,7 +188,7 @@ JSON_HEADERS = {"Content-Type": "application/json"}
188
188
 
189
189
 
190
190
  class ProcessingHTTPClient:
191
- def __init__(self):
191
+ def __init__(self) -> None:
192
192
  self.session = aiohttp.ClientSession()
193
193
  self.base_url = get_processing_api_url()
194
194
  self.base_url_v2 = get_processing_api_v2_url()
@@ -31,7 +31,7 @@ from nucliadb.export_import.utils import (
31
31
  ExportStreamReader,
32
32
  TaskRetryHandler,
33
33
  import_binary,
34
- import_broker_message,
34
+ restore_broker_message,
35
35
  set_entities_groups,
36
36
  set_labels,
37
37
  )
@@ -64,7 +64,7 @@ async def import_kb(
64
64
  items_count += 1
65
65
  if item_type == ExportedItemType.RESOURCE:
66
66
  bm = cast(writer_pb2.BrokerMessage, data)
67
- await import_broker_message(context, kbid, bm)
67
+ await restore_broker_message(context, kbid, bm)
68
68
 
69
69
  elif item_type == ExportedItemType.BINARY:
70
70
  cf = cast(resources_pb2.CloudFile, data[0])
@@ -104,39 +104,32 @@ BM_FIELDS = {
104
104
  }
105
105
 
106
106
 
107
- async def import_broker_message(
108
- context: ApplicationContext, kbid: str, bm: writer_pb2.BrokerMessage
109
- ) -> None:
110
- bm.kbid = kbid
111
- partition = context.partitioning.generate_partition(kbid, bm.uuid)
112
- for pb in [get_writer_bm(bm), get_processor_bm(bm)]:
113
- await transaction_commit(context, pb, partition)
114
-
115
-
116
107
  async def restore_broker_message(
117
108
  context: ApplicationContext, kbid: str, bm: writer_pb2.BrokerMessage
118
109
  ) -> None:
110
+ bm.kbid = kbid
119
111
  await send_writer_bm(context, bm)
120
112
  await send_processor_bm(context, bm)
121
113
 
122
114
 
123
- @backoff.on_exception(backoff.expo, (Exception,), jitter=backoff.random_jitter, max_tries=8)
124
115
  async def send_writer_bm(context: ApplicationContext, bm: writer_pb2.BrokerMessage) -> None:
116
+ await process_bm_grpc(context, get_writer_bm(bm))
117
+
118
+
119
+ async def send_processor_bm(context: ApplicationContext, bm: writer_pb2.BrokerMessage) -> None:
120
+ await process_bm_grpc(context, get_processor_bm(bm))
121
+
122
+
123
+ @backoff.on_exception(backoff.expo, (Exception,), jitter=backoff.random_jitter, max_tries=8)
124
+ async def process_bm_grpc(context: ApplicationContext, bm: writer_pb2.BrokerMessage) -> None:
125
125
  async def _iterator() -> AsyncIterator[writer_pb2.BrokerMessage]:
126
- yield get_writer_bm(bm)
126
+ yield bm
127
127
 
128
128
  ingest_grpc: WriterStub = get_ingest()
129
129
  response: writer_pb2.OpStatusWriter = await ingest_grpc.ProcessMessage(_iterator()) # type: ignore
130
130
  assert response.status == writer_pb2.OpStatusWriter.Status.OK, "Failed to process broker message"
131
131
 
132
132
 
133
- async def send_processor_bm(context: ApplicationContext, bm: writer_pb2.BrokerMessage) -> None:
134
- # Then enqueue the processor part asynchronously
135
- processor_bm = get_processor_bm(bm)
136
- partition = context.partitioning.generate_partition(bm.kbid, bm.uuid)
137
- await transaction_commit(context, processor_bm, partition)
138
-
139
-
140
133
  async def transaction_commit(
141
134
  context: ApplicationContext, bm: writer_pb2.BrokerMessage, partition: int
142
135
  ) -> None:
@@ -19,6 +19,7 @@
19
19
  #
20
20
  import asyncio
21
21
  import base64
22
+ import time
22
23
  from contextlib import contextmanager
23
24
  from datetime import datetime, timezone
24
25
  from typing import Optional
@@ -41,6 +42,7 @@ from nucliadb.common.http_clients.processing import (
41
42
  )
42
43
  from nucliadb.common.maindb.driver import Driver
43
44
  from nucliadb.ingest import SERVICE_NAME, logger, logger_activity
45
+ from nucliadb.ingest.consumer.consumer import consumer_observer
44
46
  from nucliadb.ingest.orm.exceptions import ReallyStopPulling
45
47
  from nucliadb.ingest.orm.processor import Processor
46
48
  from nucliadb_protos.writer_pb2 import BrokerMessage, BrokerMessageBlobReference
@@ -52,7 +54,7 @@ from nucliadb_utils.cache.pubsub import PubSubDriver
52
54
  from nucliadb_utils.settings import nuclia_settings
53
55
  from nucliadb_utils.storages.storage import Storage
54
56
  from nucliadb_utils.transaction import MaxTransactionSizeExceededError
55
- from nucliadb_utils.utilities import get_storage, get_transaction_utility
57
+ from nucliadb_utils.utilities import get_storage, get_transaction_utility, pull_subscriber_utilization
56
58
 
57
59
  processing_pending_messages = Gauge("nucliadb_processing_pending_messages")
58
60
 
@@ -309,11 +311,13 @@ class PullV2Worker:
309
311
 
310
312
  logger.debug(f"Resource: {pb.uuid} KB: {pb.kbid} ProcessingID: {pb.processing_id}")
311
313
 
312
- await self.processor.process(
313
- pb,
314
- seq,
315
- transaction_check=False,
316
- )
314
+ source = "writer" if pb.source == pb.MessageSource.WRITER else "processor"
315
+ with consumer_observer({"source": source, "partition": "-1"}):
316
+ await self.processor.process(
317
+ pb,
318
+ seq,
319
+ transaction_check=False,
320
+ )
317
321
 
318
322
  async def loop(self):
319
323
  """
@@ -331,6 +335,7 @@ class PullV2Worker:
331
335
  await asyncio.sleep(10)
332
336
 
333
337
  async def _loop(self):
338
+ usage_metric = pull_subscriber_utilization
334
339
  headers = {}
335
340
  data = None
336
341
  if nuclia_settings.nuclia_service_account is not None:
@@ -346,6 +351,8 @@ class PullV2Worker:
346
351
  async with ProcessingHTTPClient() as processing_http_client:
347
352
  while True:
348
353
  try:
354
+ start_time = time.monotonic()
355
+
349
356
  # The code is only really prepared to pull 1 message at a time. If changing this, review MessageProgressUpdate usage
350
357
  pull = await processing_http_client.pull_v2(ack_tokens=ack_tokens, limit=1)
351
358
  ack_tokens.clear()
@@ -353,10 +360,14 @@ class PullV2Worker:
353
360
  processing_pending_messages.set(0)
354
361
  logger_activity.debug(f"No messages waiting in processing pull")
355
362
  await asyncio.sleep(self.pull_time_empty_backoff)
363
+ usage_metric.inc({"status": "waiting"}, time.monotonic() - start_time)
356
364
  continue
357
365
 
358
- logger.info("Message received from proxy", extra={"seq": [pull.messages[0].seq]})
366
+ received_time = time.monotonic()
367
+ usage_metric.inc({"status": "waiting"}, received_time - start_time)
359
368
  processing_pending_messages.set(pull.pending)
369
+
370
+ logger.info("Message received from proxy", extra={"seq": [pull.messages[0].seq]})
360
371
  try:
361
372
  for message in pull.messages:
362
373
  async with ProcessingPullMessageProgressUpdater(
@@ -365,6 +376,8 @@ class PullV2Worker:
365
376
  with run_in_span(message.headers):
366
377
  await self.handle_message(message.seq, message.payload)
367
378
  ack_tokens.append(message.ack_token)
379
+
380
+ usage_metric.inc({"status": "processing"}, time.monotonic() - received_time)
368
381
  except Exception as e:
369
382
  errors.capture_exception(e)
370
383
  logger.exception("Error while pulling and processing message/s")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nucliadb
3
- Version: 6.4.0.post4279
3
+ Version: 6.4.0.post4287
4
4
  Summary: NucliaDB
5
5
  Author-email: Nuclia <nucliadb@nuclia.com>
6
6
  License: AGPL
@@ -20,11 +20,11 @@ Classifier: Programming Language :: Python :: 3.12
20
20
  Classifier: Programming Language :: Python :: 3 :: Only
21
21
  Requires-Python: <4,>=3.9
22
22
  Description-Content-Type: text/markdown
23
- Requires-Dist: nucliadb-telemetry[all]>=6.4.0.post4279
24
- Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.4.0.post4279
25
- Requires-Dist: nucliadb-protos>=6.4.0.post4279
26
- Requires-Dist: nucliadb-models>=6.4.0.post4279
27
- Requires-Dist: nidx-protos>=6.4.0.post4279
23
+ Requires-Dist: nucliadb-telemetry[all]>=6.4.0.post4287
24
+ Requires-Dist: nucliadb-utils[cache,fastapi,storages]>=6.4.0.post4287
25
+ Requires-Dist: nucliadb-protos>=6.4.0.post4287
26
+ Requires-Dist: nucliadb-models>=6.4.0.post4287
27
+ Requires-Dist: nidx-protos>=6.4.0.post4287
28
28
  Requires-Dist: nucliadb-admin-assets>=1.0.0.post1224
29
29
  Requires-Dist: nuclia-models>=0.24.2
30
30
  Requires-Dist: uvicorn[standard]
@@ -101,7 +101,7 @@ nucliadb/common/external_index_providers/settings.py,sha256=EGHnIkwxqe6aypwKegXT
101
101
  nucliadb/common/http_clients/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
102
102
  nucliadb/common/http_clients/auth.py,sha256=srfpgAbs2wmqA9u_l-HxsV4YoO77Tse4y3gm3q2YvYM,2112
103
103
  nucliadb/common/http_clients/exceptions.py,sha256=47Y8OjkaGV_F18G07FpJhOzgWKUIexhlILyuVtICz8s,1100
104
- nucliadb/common/http_clients/processing.py,sha256=VzxzFArNsHWGmFoX0c5OrQB3vFW841aeyuP5NgzPQGo,9581
104
+ nucliadb/common/http_clients/processing.py,sha256=crLfKo_2RJr9Uo2vuq11MWFa9tV2njA_v7ZBd95tjNU,9589
105
105
  nucliadb/common/http_clients/pypi.py,sha256=VHIUjwJEJVntVUo_FRoXIo8sLmluy7sa9-iXSITcrMY,1540
106
106
  nucliadb/common/http_clients/utils.py,sha256=yGUkHNS41abHiBoHqo_Mg3QSqGsS7rUtbfGftbEC57U,1529
107
107
  nucliadb/common/maindb/__init__.py,sha256=cp15ZcFnHvpcu_5-aK2A4uUyvuZVV_MJn4bIXMa20ks,835
@@ -117,10 +117,10 @@ nucliadb/export_import/__init__.py,sha256=y-Is0Bxa8TMV6UiOW0deC_D3U465P65CQ5RjBj
117
117
  nucliadb/export_import/datamanager.py,sha256=xL8b0xvk45q6wx1l7J32JgPmpyjnF6fKiJi2F2B_UQY,6968
118
118
  nucliadb/export_import/exceptions.py,sha256=Dw8WqfG4r6MPJc5TPfbjMvCgXXWTcTOecGHRVU1h3kM,1949
119
119
  nucliadb/export_import/exporter.py,sha256=k2QVx1EjqFlDYiggriWiEJzwtMXzHbldsqWdpGQM3_U,7074
120
- nucliadb/export_import/importer.py,sha256=v5cq9Nn8c2zrY_K_00mydR52f8mdFxR7tLdtNLQ0qvk,4229
120
+ nucliadb/export_import/importer.py,sha256=GNDMt4hdjbcLWdydVq8XFQKefzNJkQ1eTzhshUX64rk,4231
121
121
  nucliadb/export_import/models.py,sha256=dbjScNkiMRv4X3Ktudy1JRliD25bfoDTy3JmEZgQSCc,2121
122
122
  nucliadb/export_import/tasks.py,sha256=DWbdqY97ffoyfipelGXz3Jqz1iam6JCjQSh367Fc3NA,2947
123
- nucliadb/export_import/utils.py,sha256=8XOVMYXXw8b4ikojG7RjQ4tKN3Xu7nfu2yCUOqD50sk,23216
123
+ nucliadb/export_import/utils.py,sha256=iutS86YblS8aLQ9PCZUyTJMN6lDV4DjcjaptQVBfBNA,22874
124
124
  nucliadb/ingest/__init__.py,sha256=fsw3C38VP50km3R-nHL775LNGPpJ4JxqXJ2Ib1f5SqE,1011
125
125
  nucliadb/ingest/app.py,sha256=Eympy8nbz09VDNPF28MuIeKMb7wgB9cTSOObS8uvL0o,8372
126
126
  nucliadb/ingest/partitions.py,sha256=2NIhMYbNT0TNBL6bX1UMSi7vxFGICstCKEqsB0TXHOE,2410
@@ -134,7 +134,7 @@ nucliadb/ingest/consumer/auditing.py,sha256=xK21DIa_ZAiOJVVbnkmT4jgCRGshNGyPyxsq
134
134
  nucliadb/ingest/consumer/consumer.py,sha256=GfdlrNlnt7PWYyk75xtyzn2SHZse7475U4U9q_9jKr0,13711
135
135
  nucliadb/ingest/consumer/materializer.py,sha256=tgD_rDI2twQzcz8kKNiW_L4YIth16IGh9mUfD5wiSD4,3858
136
136
  nucliadb/ingest/consumer/metrics.py,sha256=ji1l_4cKiHJthQd8YNem1ft4iMbw9KThmVvJmLcv3Xg,1075
137
- nucliadb/ingest/consumer/pull.py,sha256=gfdyQ8IMFA_bpGnEpmRB9qmOJywBEwxn7pGYaueZizU,16874
137
+ nucliadb/ingest/consumer/pull.py,sha256=x39G6AcNXSnw_GRPxJfafmD5pehZzMBd6v_f_yrNbUI,17594
138
138
  nucliadb/ingest/consumer/service.py,sha256=WXBN8dY7MlmYWxqQHIbIO7w_SdVJRY1RuHAWlQUXf8o,8852
139
139
  nucliadb/ingest/consumer/shard_creator.py,sha256=w0smEu01FU_2cjZnsfBRNqT_Ntho11X17zTMST-vKbc,4359
140
140
  nucliadb/ingest/consumer/utils.py,sha256=jpX8D4lKzuPCpArQLZeX_Zczq3pfen_zAf8sPJfOEZU,2642
@@ -368,8 +368,8 @@ nucliadb/writer/tus/local.py,sha256=7jYa_w9b-N90jWgN2sQKkNcomqn6JMVBOVeDOVYJHto,
368
368
  nucliadb/writer/tus/s3.py,sha256=vF0NkFTXiXhXq3bCVXXVV-ED38ECVoUeeYViP8uMqcU,8357
369
369
  nucliadb/writer/tus/storage.py,sha256=ToqwjoYnjI4oIcwzkhha_MPxi-k4Jk3Lt55zRwaC1SM,2903
370
370
  nucliadb/writer/tus/utils.py,sha256=MSdVbRsRSZVdkaum69_0wku7X3p5wlZf4nr6E0GMKbw,2556
371
- nucliadb-6.4.0.post4279.dist-info/METADATA,sha256=ISm2mlidMfyHGlEXRXBJcbnPe52rP58sBjj5NLRFf68,4223
372
- nucliadb-6.4.0.post4279.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
373
- nucliadb-6.4.0.post4279.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
374
- nucliadb-6.4.0.post4279.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
375
- nucliadb-6.4.0.post4279.dist-info/RECORD,,
371
+ nucliadb-6.4.0.post4287.dist-info/METADATA,sha256=5QNnOEzt2bbjxt2hVf853EWspV23p_WQLeNr7FL9IQk,4223
372
+ nucliadb-6.4.0.post4287.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
373
+ nucliadb-6.4.0.post4287.dist-info/entry_points.txt,sha256=XqGfgFDuY3zXQc8ewXM2TRVjTModIq851zOsgrmaXx4,1268
374
+ nucliadb-6.4.0.post4287.dist-info/top_level.txt,sha256=hwYhTVnX7jkQ9gJCkVrbqEG1M4lT2F_iPQND1fCzF80,20
375
+ nucliadb-6.4.0.post4287.dist-info/RECORD,,