port-ocean 0.23.2__py3-none-any.whl → 0.23.3__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 port-ocean might be problematic. Click here for more details.

@@ -5,11 +5,15 @@ FROM ${BASE_BUILDER_PYTHON_IMAGE} AS base
5
5
 
6
6
  ARG BUILD_CONTEXT
7
7
  ARG BUILDPLATFORM
8
+ ARG PROMETHEUS_MULTIPROC_DIR=/tmp/ocean/prometheus/metrics
8
9
 
9
10
  ENV LIBRDKAFKA_VERSION=2.8.2 \
10
11
  PYTHONUNBUFFERED=1 \
11
12
  POETRY_VIRTUALENVS_IN_PROJECT=1 \
12
- PIP_ROOT_USER_ACTION=ignore
13
+ PIP_ROOT_USER_ACTION=ignore \
14
+ PROMETHEUS_MULTIPROC_DIR=${PROMETHEUS_MULTIPROC_DIR}
15
+
16
+ RUN mkdir -p ${PROMETHEUS_MULTIPROC_DIR}
13
17
 
14
18
  WORKDIR /app
15
19
 
@@ -25,6 +25,11 @@ RUN apt-get update \
25
25
  && apt-get clean
26
26
 
27
27
  ARG BUILD_CONTEXT
28
+ ARG PROMETHEUS_MULTIPROC_DIR=/tmp/ocean/prometheus/metrics
29
+
30
+ ENV PROMETHEUS_MULTIPROC_DIR=${PROMETHEUS_MULTIPROC_DIR}
31
+
32
+ RUN mkdir -p ${PROMETHEUS_MULTIPROC_DIR}
28
33
 
29
34
  WORKDIR /app
30
35
 
@@ -1,6 +1,4 @@
1
1
  #!/bin/bash
2
- mkdir -p /tmp/prometheus_multiproc_dir
3
- export PROMETHEUS_MULTIPROC_DIR=/tmp/prometheus_multiproc_dir
4
2
  if [ -z "$BUILD_CONTEXT" ]; then
5
3
  echo "BUILD_CONTEXT is not set"
6
4
  exit 1
@@ -16,6 +16,7 @@ from port_ocean.core.handlers.port_app_config.models import ResourceConfig
16
16
  from port_ocean.core.integrations.mixins import HandlerMixin, EventsMixin
17
17
  from port_ocean.core.integrations.mixins.utils import (
18
18
  ProcessWrapper,
19
+ clear_http_client_context,
19
20
  is_resource_supported,
20
21
  unsupported_kind_response,
21
22
  resync_generator_wrapper,
@@ -594,6 +595,7 @@ class SyncRawMixin(HandlerMixin, EventsMixin):
594
595
  ) -> None:
595
596
  logger.info(f"process started successfully for {resource.kind} with index {index}")
596
597
 
598
+ clear_http_client_context()
597
599
  async def process_resource_task() -> None:
598
600
  result = await self._process_resource(
599
601
  resource, index, user_agent_type
@@ -775,3 +777,5 @@ class SyncRawMixin(HandlerMixin, EventsMixin):
775
777
  return True
776
778
  finally:
777
779
  await ocean.app.cache_provider.clear()
780
+ if ocean.app.process_execution_mode == ProcessExecutionMode.multi_process:
781
+ ocean.metrics.cleanup_prometheus_metrics()
@@ -19,6 +19,10 @@ from port_ocean.exceptions.core import (
19
19
  KindNotImplementedException,
20
20
  )
21
21
 
22
+ from port_ocean.utils.async_http import _http_client
23
+ from port_ocean.clients.port.utils import _http_client as _port_http_client
24
+
25
+ from port_ocean.context.ocean import ocean
22
26
 
23
27
  @contextmanager
24
28
  def resync_error_handling() -> Generator[None, None, None]:
@@ -76,6 +80,7 @@ def unsupported_kind_response(
76
80
  logger.error(f"Kind {kind} is not supported in this integration")
77
81
  return [], [KindNotImplementedException(kind, available_resync_kinds)]
78
82
 
83
+
79
84
  class ProcessWrapper(multiprocessing.Process):
80
85
  def __init__(self, *args, **kwargs):
81
86
  super().__init__(*args, **kwargs)
@@ -87,4 +92,18 @@ class ProcessWrapper(multiprocessing.Process):
87
92
  logger.error(f"Process {self.pid} failed with exit code {self.exitcode}")
88
93
  else:
89
94
  logger.info(f"Process {self.pid} finished with exit code {self.exitcode}")
95
+ ocean.metrics.cleanup_prometheus_metrics(self.pid)
90
96
  return super().join()
97
+
98
+ def clear_http_client_context() -> None:
99
+ try:
100
+ while _http_client.top is not None:
101
+ _http_client.pop()
102
+ except (RuntimeError, AttributeError):
103
+ pass
104
+
105
+ try:
106
+ while _port_http_client.top is not None:
107
+ _port_http_client.pop()
108
+ except (RuntimeError, AttributeError):
109
+ pass
@@ -1,9 +1,10 @@
1
+ import os
1
2
  from typing import Any, TYPE_CHECKING, Optional, Dict, List, Tuple
2
3
  from fastapi import APIRouter
3
4
  from port_ocean.exceptions.context import ResourceContextNotFoundError
4
5
  import prometheus_client
5
6
  from httpx import AsyncClient
6
-
7
+ from fastapi.responses import PlainTextResponse
7
8
  from loguru import logger
8
9
  from port_ocean.context import resource
9
10
  from prometheus_client import Gauge
@@ -193,7 +194,21 @@ class Metrics:
193
194
  """
194
195
  self.get_metric(name, labels).set(value)
195
196
 
197
+ @staticmethod
198
+ def cleanup_prometheus_metrics(pid: int | None = None) -> None:
199
+ try:
200
+ prometheus_multiproc_dir = os.environ.get("PROMETHEUS_MULTIPROC_DIR")
201
+ for file in os.listdir(prometheus_multiproc_dir):
202
+ if pid:
203
+ if file.endswith(".db") and file[0:-3].split("_")[-1] == str(pid):
204
+ os.remove(f"{prometheus_multiproc_dir}/{file}")
205
+ else:
206
+ os.remove(f"{prometheus_multiproc_dir}/{file}")
207
+ except Exception as e:
208
+ logger.error(f"Failed to cleanup prometheus metrics: {e}")
209
+
196
210
  def initialize_metrics(self, kind_blockes: list[str]) -> None:
211
+ self.cleanup_prometheus_metrics()
197
212
  for kind in kind_blockes:
198
213
  self.set_metric(MetricType.SUCCESS_NAME, [kind, MetricPhase.RESYNC], 0)
199
214
  self.set_metric(MetricType.DURATION_NAME, [kind, MetricPhase.RESYNC], 0)
@@ -241,7 +256,7 @@ class Metrics:
241
256
  return APIRouter()
242
257
  router = APIRouter()
243
258
 
244
- @router.get("/")
259
+ @router.get("/", response_class=PlainTextResponse)
245
260
  async def prom_metrics() -> str:
246
261
  return self.generate_latest()
247
262
 
port_ocean/ocean.py CHANGED
@@ -96,7 +96,6 @@ class Ocean:
96
96
  self.resync_state_updater = ResyncStateUpdater(
97
97
  self.port_client, self.config.scheduled_resync_interval
98
98
  )
99
-
100
99
  self.app_initialized = False
101
100
 
102
101
  def _get_process_execution_mode(self) -> ProcessExecutionMode:
port_ocean/utils/ipc.py CHANGED
@@ -7,7 +7,7 @@ class FileIPC:
7
7
  def __init__(self, process_id: str, name: str, default_return: Any = None):
8
8
  self.process_id = process_id
9
9
  self.name = name
10
- self.dir_path = f"/tmp/p_{self.process_id}"
10
+ self.dir_path = f"/tmp/ocean/processes/p_{self.process_id}"
11
11
  self.file_path = f"{self.dir_path}/{self.name}.pkl"
12
12
  self.default_return = default_return
13
13
  os.makedirs(self.dir_path, exist_ok=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: port-ocean
3
- Version: 0.23.2
3
+ Version: 0.23.3
4
4
  Summary: Port Ocean is a CLI tool for managing your Port projects.
5
5
  Home-page: https://app.getport.io
6
6
  Keywords: ocean,port-ocean,port
@@ -1,11 +1,11 @@
1
- integrations/_infra/Dockerfile.Deb,sha256=ruQRZwWN5qrJCecgA-rZklX1zXO8OAS78SjAqMv6dLg,1519
1
+ integrations/_infra/Dockerfile.Deb,sha256=JMyxgvJxLeo3Vcys-w6m_F6fxfu6JyAcjAMPuXsNQBM,1679
2
2
  integrations/_infra/Dockerfile.alpine,sha256=7E4Sb-8supsCcseerHwTkuzjHZoYcaHIyxiBZ-wewo0,3482
3
3
  integrations/_infra/Dockerfile.base.builder,sha256=ESe1PKC6itp_AuXawbLI75k1Kruny6NTANaTinxOgVs,743
4
4
  integrations/_infra/Dockerfile.base.runner,sha256=uAcs2IsxrAAUHGXt_qULA5INr-HFguf5a5fCKiqEzbY,384
5
5
  integrations/_infra/Dockerfile.dockerignore,sha256=CM1Fxt3I2AvSvObuUZRmy5BNLSGC7ylnbpWzFgD4cso,1163
6
- integrations/_infra/Dockerfile.local,sha256=Aqj3y4U6XFS78i5Zz3IfyZkvVmAdB7eEAe6khQaxRxI,876
6
+ integrations/_infra/Dockerfile.local,sha256=4M5wyksRcGQ0WSXfDcJsHshE8uUSQw5yf6O3JK_DyK4,1035
7
7
  integrations/_infra/Makefile,sha256=YgLKvuF_Dw4IA7X98Nus6zIW_3cJ60M1QFGs3imj5c4,2430
8
- integrations/_infra/entry_local.sh,sha256=cH2Gd82qDnLKXvjoK1MNay9vdIZzTTF_hrhmvZuYZbg,648
8
+ integrations/_infra/entry_local.sh,sha256=GIuAXACcYv4DDxH6ubDidNJboqmAJYW4OanUK_VW4nQ,547
9
9
  integrations/_infra/grpcio.sh,sha256=m924poYznoRZ6Tt7Ct8Cs5AV_cmmOx598yIZ3z4DvZE,616
10
10
  integrations/_infra/init.sh,sha256=nN8lTrOhB286UfFvD6sJ9YJ-9asT9zVSddQB-RAb7Z4,99
11
11
  port_ocean/__init__.py,sha256=uMpjg5d_cXgnyCxA_LmICR8zqBmC6Fe9Ivu9hcvJ7EY,313
@@ -120,8 +120,8 @@ port_ocean/core/integrations/mixins/events.py,sha256=2L7P3Jhp8XBqddh2_o9Cn4N261n
120
120
  port_ocean/core/integrations/mixins/handler.py,sha256=mZ7-0UlG3LcrwJttFbMe-R4xcOU2H_g33tZar7PwTv8,3771
121
121
  port_ocean/core/integrations/mixins/live_events.py,sha256=8HklZmlyffYY_LeDe8xbt3Tb08rlLkqVhFF-2NQeJP4,4126
122
122
  port_ocean/core/integrations/mixins/sync.py,sha256=Vm_898pLKBwfVewtwouDWsXoxcOLicnAy6pzyqqk6U8,4053
123
- port_ocean/core/integrations/mixins/sync_raw.py,sha256=XIVx_Y9TM8TCMzuoNowYGNtQG98n2pLTCFFHWbkIbTo,32176
124
- port_ocean/core/integrations/mixins/utils.py,sha256=0rzzFnxrFNaVLHXShfDda5zjO8WwEUBW9oPWxnDsaXQ,2878
123
+ port_ocean/core/integrations/mixins/sync_raw.py,sha256=-PpGl0rgaUHjoqCLrVziwogopfxoq5F4hJzXf1wKVFc,32397
124
+ port_ocean/core/integrations/mixins/utils.py,sha256=g1XbC12dswefQ-NpcLSCqFtd_WRp2bTL98jyZ5rRbGk,3444
125
125
  port_ocean/core/models.py,sha256=MKfq69zGbFRzo0I2HRDUvSbz_pjrtcFVsD5B4Qwa3fw,2538
126
126
  port_ocean/core/ocean_types.py,sha256=4VipWFOHEh_d9LmWewQccwx1p2dtrRYW0YURVgNsAjo,1398
127
127
  port_ocean/core/utils/entity_topological_sorter.py,sha256=MDUjM6OuDy4Xj68o-7InNN0w1jqjxeDfeY8U02vySNI,3081
@@ -138,7 +138,7 @@ port_ocean/exceptions/utils.py,sha256=gjOqpi-HpY1l4WlMFsGA9yzhxDhajhoGGdDDyGbLnq
138
138
  port_ocean/exceptions/webhook_processor.py,sha256=yQYazg53Y-ohb7HfViwq1opH_ZUuUdhHSRxcUNveFpI,114
139
139
  port_ocean/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
140
140
  port_ocean/helpers/async_client.py,sha256=SRlP6o7_FCSY3UHnRlZdezppePVxxOzZ0z861vE3K40,1783
141
- port_ocean/helpers/metric/metric.py,sha256=iktHKXQNzkLYHgCLWA5wxRDvAMJrJIMoGQYFXV83mH0,12973
141
+ port_ocean/helpers/metric/metric.py,sha256=Sj4EmkOb6ywEM2rq88ZD4yqgcu1u3G6BpLHqYD9Llnw,13725
142
142
  port_ocean/helpers/metric/utils.py,sha256=Wnr-6HwVwBtYJ3so44OkhDRs8udLMSB1oduzl2-zRHo,781
143
143
  port_ocean/helpers/retry.py,sha256=gmS4YxM6N4fboFp7GSgtOzyBJemxs46bnrz4L4rDS6Y,16136
144
144
  port_ocean/log/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -146,7 +146,7 @@ port_ocean/log/handlers.py,sha256=ncVjgqrZRh6BhyRrA6DQG86Wsbxph1yWYuEC0cWfe-Q,36
146
146
  port_ocean/log/logger_setup.py,sha256=0K3zVG0YYrYOWEV8-rCGks1o-bMRxgHXlqawu9w_tSw,2656
147
147
  port_ocean/log/sensetive.py,sha256=lVKiZH6b7TkrZAMmhEJRhcl67HNM94e56x12DwFgCQk,2920
148
148
  port_ocean/middlewares.py,sha256=9wYCdyzRZGK1vjEJ28FY_DkfwDNENmXp504UKPf5NaQ,2727
149
- port_ocean/ocean.py,sha256=h0d-lOf7FQdrRylEglD1MqNzHk-OdvwAorFWyiT6UBo,8825
149
+ port_ocean/ocean.py,sha256=83zgTEI5o2wfl8mq-iIC9DzPOZbWyCqNIy1BEjv9TOk,8824
150
150
  port_ocean/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
151
151
  port_ocean/run.py,sha256=CmKz14bxfdOooNbQ5QqH1MwX-XLYVG4NgT4KbrzFaqI,2216
152
152
  port_ocean/sonar-project.properties,sha256=X_wLzDOkEVmpGLRMb2fg9Rb0DxWwUFSvESId8qpvrPI,73
@@ -192,15 +192,15 @@ port_ocean/utils/__init__.py,sha256=KMGnCPXZJbNwtgxtyMycapkDz8tpSyw23MSYT3iVeHs,
192
192
  port_ocean/utils/async_http.py,sha256=aDsw3gQIMwt6qLegbZtkHqD8em48tKvbITnblsrTY3g,1260
193
193
  port_ocean/utils/async_iterators.py,sha256=CPXskYWkhkZtAG-ducEwM8537t3z5usPEqXR9vcivzw,3715
194
194
  port_ocean/utils/cache.py,sha256=tRwPomG2VIxx8ZNi4QYH6Yc47d9yYV1A7Hx-L_fX4Dg,4494
195
- port_ocean/utils/ipc.py,sha256=BMVUxdftf0i7Z2Xp8KMFlttUjZhTE7VUCpY4SBBnoVY,896
195
+ port_ocean/utils/ipc.py,sha256=eTjTTvsKl6IXYeOkIjP5iyrw-8gLQ9rf15WeyxCqXog,912
196
196
  port_ocean/utils/misc.py,sha256=0q2cJ5psqxn_5u_56pT7vOVQ3shDM02iC1lzyWQ_zl0,2098
197
197
  port_ocean/utils/queue_utils.py,sha256=KWWl8YVnG-glcfIHhM6nefY-2sou_C6DVP1VynQwzB4,2762
198
198
  port_ocean/utils/repeat.py,sha256=U2OeCkHPWXmRTVoPV-VcJRlQhcYqPWI5NfmPlb1JIbc,3229
199
199
  port_ocean/utils/signal.py,sha256=mMVq-1Ab5YpNiqN4PkiyTGlV_G0wkUDMMjTZp5z3pb0,1514
200
200
  port_ocean/utils/time.py,sha256=pufAOH5ZQI7gXvOvJoQXZXZJV-Dqktoj9Qp9eiRwmJ4,1939
201
201
  port_ocean/version.py,sha256=UsuJdvdQlazzKGD3Hd5-U7N69STh8Dq9ggJzQFnu9fU,177
202
- port_ocean-0.23.2.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
203
- port_ocean-0.23.2.dist-info/METADATA,sha256=VnbW8FFOYaCKz8w6PUz0nxZgkpzED3Ny8ui9qB5uXBY,6764
204
- port_ocean-0.23.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
205
- port_ocean-0.23.2.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
206
- port_ocean-0.23.2.dist-info/RECORD,,
202
+ port_ocean-0.23.3.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
203
+ port_ocean-0.23.3.dist-info/METADATA,sha256=AEHgeXhhZvZjNB1asqxeLgoCUSEBvlhJ45VJSb69f94,6764
204
+ port_ocean-0.23.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
205
+ port_ocean-0.23.3.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
206
+ port_ocean-0.23.3.dist-info/RECORD,,