omnata-plugin-runtime 0.8.0a192__tar.gz → 0.8.0a194__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/PKG-INFO +1 -1
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/pyproject.toml +1 -1
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/src/omnata_plugin_runtime/logging.py +2 -1
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/src/omnata_plugin_runtime/omnata_plugin.py +59 -54
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/src/omnata_plugin_runtime/plugin_entrypoints.py +1 -1
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/LICENSE +0 -0
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/README.md +0 -0
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/src/omnata_plugin_runtime/__init__.py +0 -0
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/src/omnata_plugin_runtime/api.py +0 -0
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/src/omnata_plugin_runtime/configuration.py +0 -0
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/src/omnata_plugin_runtime/forms.py +0 -0
- {omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/src/omnata_plugin_runtime/rate_limiting.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "omnata-plugin-runtime"
|
3
|
-
version = "0.8.0-
|
3
|
+
version = "0.8.0-a194"
|
4
4
|
description = "Classes and common runtime components for building and running Omnata Plugins"
|
5
5
|
authors = ["James Weakley <james.weakley@omnata.com>"]
|
6
6
|
readme = "README.md"
|
@@ -8,6 +8,7 @@ from logging import Logger, getLogger
|
|
8
8
|
from typing import Dict, List, Optional
|
9
9
|
from snowflake.snowpark import Session
|
10
10
|
from pydantic import ValidationError
|
11
|
+
from snowflake import telemetry
|
11
12
|
from opentelemetry import trace
|
12
13
|
|
13
14
|
|
@@ -34,7 +35,7 @@ class CustomLoggerAdapter(logging.LoggerAdapter):
|
|
34
35
|
kwargs["extra"] = extra
|
35
36
|
return msg, kwargs
|
36
37
|
|
37
|
-
logger = CustomLoggerAdapter(getLogger("
|
38
|
+
logger = CustomLoggerAdapter(getLogger("omnata_plugin"), {})
|
38
39
|
|
39
40
|
def log_exception(exception: Exception, logger_instance: Logger):
|
40
41
|
"""
|
@@ -47,7 +47,7 @@ from snowflake.snowpark import Session
|
|
47
47
|
from snowflake.snowpark.functions import col
|
48
48
|
from tenacity import Retrying, stop_after_attempt, wait_fixed, retry_if_exception_message
|
49
49
|
|
50
|
-
from .logging import OmnataPluginLogHandler
|
50
|
+
from .logging import OmnataPluginLogHandler, logger
|
51
51
|
|
52
52
|
from .api import (
|
53
53
|
PluginMessage,
|
@@ -87,8 +87,9 @@ from .rate_limiting import (
|
|
87
87
|
RateLimitState,
|
88
88
|
RateLimitedSession
|
89
89
|
)
|
90
|
+
from opentelemetry import trace
|
91
|
+
tracer = trace.get_tracer('omnata_plugin_runtime')
|
90
92
|
|
91
|
-
logger = getLogger(__name__)
|
92
93
|
SortDirectionType = Literal["asc", "desc"]
|
93
94
|
|
94
95
|
|
@@ -810,22 +811,23 @@ class OutboundSyncRequest(SyncRequest):
|
|
810
811
|
logger.debug("applying results to table")
|
811
812
|
# use a random table name with a random string to avoid collisions
|
812
813
|
with self._snowflake_query_lock:
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
814
|
+
with tracer.start_as_current_span("apply_results"):
|
815
|
+
for attempt in Retrying(stop=stop_after_attempt(30),wait=wait_fixed(2),reraise=True,retry=retry_if_exception_message(match=".*(is being|was) committed.*")):
|
816
|
+
with attempt:
|
817
|
+
success, nchunks, nrows, _ = write_pandas(
|
818
|
+
conn=self._session._conn._cursor.connection, # pylint: disable=protected-access
|
819
|
+
df=self._preprocess_results_dataframe(results_df),
|
820
|
+
quote_identifiers=False,
|
821
|
+
table_name=self._full_results_table_name,
|
822
|
+
auto_create_table=False
|
823
|
+
)
|
824
|
+
if not success:
|
825
|
+
raise ValueError(
|
826
|
+
f"Failed to write results to table {self._full_results_table_name}"
|
827
|
+
)
|
828
|
+
logger.debug(
|
829
|
+
f"Wrote {nrows} rows and {nchunks} chunks to table {self._full_results_table_name}"
|
825
830
|
)
|
826
|
-
logger.debug(
|
827
|
-
f"Wrote {nrows} rows and {nchunks} chunks to table {self._full_results_table_name}"
|
828
|
-
)
|
829
831
|
|
830
832
|
def __dataframe_wrapper(
|
831
833
|
self, data_frame: pandas.DataFrame, render_jinja: bool = True
|
@@ -1465,36 +1467,37 @@ class InboundSyncRequest(SyncRequest):
|
|
1465
1467
|
"""
|
1466
1468
|
if len(results_df) > 0:
|
1467
1469
|
with self._snowflake_query_lock:
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
# try setting parquet engine here, since the engine parameter does not seem to make it through to the write_pandas function
|
1474
|
-
success, nchunks, nrows, _ = write_pandas(
|
1475
|
-
conn=self._session._conn._cursor.connection, # pylint: disable=protected-access
|
1476
|
-
df=results_df,
|
1477
|
-
table_name=self._full_results_table_name,
|
1478
|
-
quote_identifiers=False, # already done in get_temp_table_name
|
1479
|
-
# schema='INBOUND_RAW', # it seems to be ok to provide schema in the table name
|
1480
|
-
table_type="transient"
|
1481
|
-
)
|
1482
|
-
if not success:
|
1483
|
-
raise ValueError(
|
1484
|
-
f"Failed to write results to table {self._full_results_table_name}"
|
1470
|
+
with tracer.start_as_current_span("apply_results"):
|
1471
|
+
for attempt in Retrying(stop=stop_after_attempt(30),wait=wait_fixed(2),reraise=True,retry=retry_if_exception_message(match=".*(is being|was) committed.*")):
|
1472
|
+
with attempt:
|
1473
|
+
logger.debug(
|
1474
|
+
f"Applying {len(results_df)} results to {self._full_results_table_name}"
|
1485
1475
|
)
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1476
|
+
# try setting parquet engine here, since the engine parameter does not seem to make it through to the write_pandas function
|
1477
|
+
success, nchunks, nrows, _ = write_pandas(
|
1478
|
+
conn=self._session._conn._cursor.connection, # pylint: disable=protected-access
|
1479
|
+
df=results_df,
|
1480
|
+
table_name=self._full_results_table_name,
|
1481
|
+
quote_identifiers=False, # already done in get_temp_table_name
|
1482
|
+
# schema='INBOUND_RAW', # it seems to be ok to provide schema in the table name
|
1483
|
+
table_type="transient"
|
1484
|
+
)
|
1485
|
+
if not success:
|
1486
|
+
raise ValueError(
|
1487
|
+
f"Failed to write results to table {self._full_results_table_name}"
|
1488
|
+
)
|
1489
|
+
logger.debug(
|
1490
|
+
f"Wrote {nrows} rows and {nchunks} chunks to table {self._full_results_table_name}"
|
1491
|
+
)
|
1492
|
+
# temp tables aren't allowed
|
1493
|
+
# snowflake_df = self._session.create_dataframe(results_df)
|
1494
|
+
# snowflake_df.write.save_as_table(table_name=temp_table,
|
1495
|
+
# mode='append',
|
1496
|
+
# column_order='index',
|
1497
|
+
# #create_temp_table=True
|
1498
|
+
# )
|
1499
|
+
for stream_name in stream_names:
|
1500
|
+
self._results_exist[stream_name] = True
|
1498
1501
|
else:
|
1499
1502
|
logger.debug("Results dataframe is empty, not applying")
|
1500
1503
|
|
@@ -2137,14 +2140,16 @@ def __managed_inbound_processing_worker(
|
|
2137
2140
|
logger.debug(f"stream returned from queue: {stream}")
|
2138
2141
|
# restore the first argument, was originally the dataframe/generator but now it's the appropriately sized dataframe
|
2139
2142
|
try:
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
logger.
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2143
|
+
with tracer.start_as_current_span("managed_inbound_processing") as managed_inbound_processing_span:
|
2144
|
+
logger.debug(f"worker {worker_index} processing stream {stream.stream_name}, invoking plugin class method {method.__name__}")
|
2145
|
+
managed_inbound_processing_span.set_attribute("stream_name", stream.stream_name)
|
2146
|
+
result = method(plugin_class_obj, *(stream, *method_args), **method_kwargs)
|
2147
|
+
logger.debug(f"worker {worker_index} completed processing stream {stream.stream_name}")
|
2148
|
+
if result is not None and result is False:
|
2149
|
+
logger.info(f"worker {worker_index} requested that {stream.stream_name} be not marked as complete")
|
2150
|
+
else:
|
2151
|
+
logger.info(f"worker {worker_index} marking stream {stream.stream_name} as complete")
|
2152
|
+
plugin_class_obj._sync_request.mark_stream_complete(stream.stream_name)
|
2148
2153
|
except InterruptedWhileWaitingException:
|
2149
2154
|
# If an inbound run is cancelled while waiting for rate limiting, this should mean that
|
2150
2155
|
# the cancellation is handled elsewhere, so we don't need to do anything special here other than stop waiting
|
@@ -39,7 +39,7 @@ from .rate_limiting import ApiLimits, RateLimitState
|
|
39
39
|
from opentelemetry import trace
|
40
40
|
|
41
41
|
IMPORT_DIRECTORY_NAME = "snowflake_import_directory"
|
42
|
-
tracer = trace.get_tracer(
|
42
|
+
tracer = trace.get_tracer('omnata_plugin_runtime')
|
43
43
|
|
44
44
|
class PluginEntrypoint:
|
45
45
|
"""
|
File without changes
|
File without changes
|
File without changes
|
{omnata_plugin_runtime-0.8.0a192 → omnata_plugin_runtime-0.8.0a194}/src/omnata_plugin_runtime/api.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|