unstructured-platform-plugins 0.0.2__tar.gz → 0.0.5__tar.gz
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.
- {unstructured-platform-plugins-0.0.2/unstructured_platform_plugins.egg-info → unstructured-platform-plugins-0.0.5}/PKG-INFO +1 -1
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/test_schema.py +16 -0
- unstructured-platform-plugins-0.0.5/unstructured_platform_plugins/__version__.py +1 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/etl_uvicorn/api_generator.py +29 -4
- unstructured-platform-plugins-0.0.5/unstructured_platform_plugins/etl_uvicorn/otel.py +107 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5/unstructured_platform_plugins.egg-info}/PKG-INFO +1 -1
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins.egg-info/SOURCES.txt +1 -0
- unstructured-platform-plugins-0.0.5/unstructured_platform_plugins.egg-info/requires.txt +8 -0
- unstructured-platform-plugins-0.0.2/unstructured_platform_plugins/__version__.py +0 -1
- unstructured-platform-plugins-0.0.2/unstructured_platform_plugins.egg-info/requires.txt +0 -6
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/LICENSE +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/LICENSE.md +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/README.md +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/pyproject.toml +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/setup.cfg +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/setup.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/async_typed_dict_response.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/dataclass_response.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/empty_input_and_response.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/hash_function.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/improper_function.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/pydantic_response_class_method.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/simple_hash_class.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/simple_hash_lambda.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/simple_hash_value.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/typed_dict_response.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/test_utils.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/etl_uvicorn/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/etl_uvicorn/main.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/etl_uvicorn/utils.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/schema/__init__.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/schema/json_schema.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/schema/model.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/schema/usage.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/schema/utils.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/type_hints.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins/validate_api.py +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins.egg-info/dependency_links.txt +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins.egg-info/entry_points.txt +0 -0
- {unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/unstructured_platform_plugins.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: unstructured-platform-plugins
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.5
|
|
4
4
|
Summary: A utility library that provides tools around unstructured plugin development
|
|
5
5
|
Home-page: https://github.com/Unstructured-IO/unstructured-platform-plugins
|
|
6
6
|
License: Apache-2.0
|
{unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/test_schema.py
RENAMED
|
@@ -554,6 +554,10 @@ def test_file_data():
|
|
|
554
554
|
],
|
|
555
555
|
"default": None,
|
|
556
556
|
},
|
|
557
|
+
"filesize_bytes": {
|
|
558
|
+
"anyOf": [{"type": "integer"}, {"type": "null"}],
|
|
559
|
+
"default": None,
|
|
560
|
+
},
|
|
557
561
|
},
|
|
558
562
|
"required": [],
|
|
559
563
|
},
|
|
@@ -562,6 +566,10 @@ def test_file_data():
|
|
|
562
566
|
"items": {"key": {"type": "string"}, "value": {}},
|
|
563
567
|
},
|
|
564
568
|
"reprocess": {"type": "boolean", "default": False},
|
|
569
|
+
"local_download_path": {
|
|
570
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
571
|
+
"default": None,
|
|
572
|
+
},
|
|
565
573
|
},
|
|
566
574
|
"required": ["identifier", "connector_type", "metadata", "additional_metadata"],
|
|
567
575
|
}
|
|
@@ -643,6 +651,10 @@ def test_file_data():
|
|
|
643
651
|
],
|
|
644
652
|
"default": None,
|
|
645
653
|
},
|
|
654
|
+
"filesize_bytes": {
|
|
655
|
+
"anyOf": [{"type": "integer"}, {"type": "null"}],
|
|
656
|
+
"default": None,
|
|
657
|
+
},
|
|
646
658
|
},
|
|
647
659
|
"required": [],
|
|
648
660
|
},
|
|
@@ -651,6 +663,10 @@ def test_file_data():
|
|
|
651
663
|
"items": {"key": {"type": "string"}, "value": {}},
|
|
652
664
|
},
|
|
653
665
|
"reprocess": {"type": "boolean", "default": False},
|
|
666
|
+
"local_download_path": {
|
|
667
|
+
"anyOf": [{"type": "string"}, {"type": "null"}],
|
|
668
|
+
"default": None,
|
|
669
|
+
},
|
|
654
670
|
},
|
|
655
671
|
"required": ["identifier", "connector_type", "metadata", "additional_metadata"],
|
|
656
672
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.5" # pragma: no cover
|
|
@@ -3,13 +3,17 @@ import hashlib
|
|
|
3
3
|
import inspect
|
|
4
4
|
import json
|
|
5
5
|
import logging
|
|
6
|
+
from functools import partial
|
|
6
7
|
from typing import Any, Callable, Optional
|
|
7
8
|
|
|
8
9
|
from fastapi import FastAPI, status
|
|
10
|
+
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
|
9
11
|
from pydantic import BaseModel
|
|
10
12
|
from starlette.responses import RedirectResponse
|
|
13
|
+
from uvicorn.config import LOG_LEVELS
|
|
11
14
|
from uvicorn.importer import import_from_string
|
|
12
15
|
|
|
16
|
+
from unstructured_platform_plugins.etl_uvicorn.otel import get_metric_provider, get_trace_provider
|
|
13
17
|
from unstructured_platform_plugins.etl_uvicorn.utils import (
|
|
14
18
|
get_func,
|
|
15
19
|
get_input_schema,
|
|
@@ -26,12 +30,28 @@ from unstructured_platform_plugins.schema.usage import UsageData
|
|
|
26
30
|
logger = logging.getLogger("uvicorn.error")
|
|
27
31
|
|
|
28
32
|
|
|
33
|
+
def log_func_and_body(func: Callable, body: Optional[str] = None) -> None:
|
|
34
|
+
msg = None
|
|
35
|
+
if logger.level == LOG_LEVELS.get("debug", logging.NOTSET):
|
|
36
|
+
if not body:
|
|
37
|
+
msg = f"invoking function without inputs: {func.__name__}"
|
|
38
|
+
else:
|
|
39
|
+
msg = f"invoking function {func.__name__} with body"
|
|
40
|
+
elif logger.level == LOG_LEVELS.get("trace", logging.NOTSET):
|
|
41
|
+
if not body:
|
|
42
|
+
msg = f"invoking function without inputs: {func}"
|
|
43
|
+
else:
|
|
44
|
+
msg = f"invoking function {func} with body: {body}"
|
|
45
|
+
if msg:
|
|
46
|
+
logger.log(level=logger.level, msg=msg)
|
|
47
|
+
|
|
48
|
+
|
|
29
49
|
async def invoke_func(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> Any:
|
|
30
50
|
kwargs = kwargs or {}
|
|
31
51
|
if inspect.iscoroutinefunction(func):
|
|
32
52
|
return await func(**kwargs)
|
|
33
53
|
else:
|
|
34
|
-
return func
|
|
54
|
+
return await asyncio.get_event_loop().run_in_executor(None, partial(func, **kwargs))
|
|
35
55
|
|
|
36
56
|
|
|
37
57
|
def check_precheck_func(precheck_func: Callable):
|
|
@@ -113,18 +133,19 @@ def generate_fast_api(
|
|
|
113
133
|
|
|
114
134
|
@fastapi_app.post("/invoke", response_model=InvokeResponse)
|
|
115
135
|
async def run_job(request: input_schema_model) -> InvokeResponse:
|
|
116
|
-
|
|
136
|
+
log_func_and_body(func=func, body=request.json())
|
|
117
137
|
# Create dictionary from pydantic model while preserving underlying types
|
|
118
138
|
request_dict = {f: getattr(request, f) for f in request.model_fields}
|
|
119
139
|
map_inputs(func=func, raw_inputs=request_dict)
|
|
120
|
-
logger.
|
|
140
|
+
if logger.level == LOG_LEVELS.get("trace", logging.NOTSET):
|
|
141
|
+
logger.log(level=logger.level, msg=f"passing inputs to function: {request_dict}")
|
|
121
142
|
return await wrap_fn(func=func, kwargs=request_dict)
|
|
122
143
|
|
|
123
144
|
else:
|
|
124
145
|
|
|
125
146
|
@fastapi_app.post("/invoke", response_model=InvokeResponse)
|
|
126
147
|
async def run_job() -> InvokeResponse:
|
|
127
|
-
|
|
148
|
+
log_func_and_body(func=func)
|
|
128
149
|
return await wrap_fn(
|
|
129
150
|
func=func,
|
|
130
151
|
)
|
|
@@ -170,4 +191,8 @@ def generate_fast_api(
|
|
|
170
191
|
except TypeError as e:
|
|
171
192
|
raise TypeError(f"failed to validate function schema: {e}") from e
|
|
172
193
|
|
|
194
|
+
FastAPIInstrumentor.instrument_app(
|
|
195
|
+
fastapi_app, tracer_provider=get_trace_provider(), meter_provider=get_metric_provider()
|
|
196
|
+
)
|
|
197
|
+
|
|
173
198
|
return fastapi_app
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Literal, TypedDict
|
|
3
|
+
|
|
4
|
+
from opentelemetry.environment_variables import OTEL_METRICS_EXPORTER, OTEL_TRACES_EXPORTER
|
|
5
|
+
from opentelemetry.sdk.environment_variables import OTEL_SERVICE_NAME
|
|
6
|
+
from opentelemetry.sdk.metrics import MeterProvider
|
|
7
|
+
from opentelemetry.sdk.metrics.export import (
|
|
8
|
+
ConsoleMetricExporter,
|
|
9
|
+
MetricReader,
|
|
10
|
+
PeriodicExportingMetricReader,
|
|
11
|
+
)
|
|
12
|
+
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
|
|
13
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
14
|
+
from opentelemetry.sdk.trace.export import (
|
|
15
|
+
ConsoleSpanExporter,
|
|
16
|
+
SimpleSpanProcessor,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
TraceExporterType = Literal["otlp", "jaeger", "zipkin", "console"]
|
|
20
|
+
MetricExporterType = Literal["otlp", "prometheus", "none"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class OtelSettings(TypedDict):
|
|
24
|
+
service_name: str
|
|
25
|
+
trace_exporters: list[TraceExporterType]
|
|
26
|
+
metric_exporters: list[MetricExporterType]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_settings() -> OtelSettings:
|
|
30
|
+
service_name = os.environ.get(OTEL_SERVICE_NAME, "unknown_service")
|
|
31
|
+
trace_exporters = os.environ.get(OTEL_TRACES_EXPORTER)
|
|
32
|
+
trace_exporters = trace_exporters.split(",") if trace_exporters else []
|
|
33
|
+
|
|
34
|
+
metric_exporters = os.environ.get(OTEL_METRICS_EXPORTER)
|
|
35
|
+
metric_exporters = metric_exporters.split(",") if metric_exporters else []
|
|
36
|
+
return OtelSettings(
|
|
37
|
+
service_name=service_name,
|
|
38
|
+
trace_exporters=trace_exporters,
|
|
39
|
+
metric_exporters=metric_exporters,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_trace_provider() -> TracerProvider:
|
|
44
|
+
settings = get_settings()
|
|
45
|
+
print(settings)
|
|
46
|
+
provider = TracerProvider(resource=Resource({SERVICE_NAME: settings["service_name"]}))
|
|
47
|
+
|
|
48
|
+
for trace_exporter_type in settings["trace_exporters"]:
|
|
49
|
+
_add_trace_exporter(exporter_type=trace_exporter_type, provider=provider)
|
|
50
|
+
|
|
51
|
+
return provider
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def get_metric_provider() -> MeterProvider:
|
|
55
|
+
settings = get_settings()
|
|
56
|
+
readers = []
|
|
57
|
+
for metric_exporter_type in settings["metric_exporters"]:
|
|
58
|
+
readers.append(_get_metrics_reader(exporter_type=metric_exporter_type))
|
|
59
|
+
return MeterProvider(
|
|
60
|
+
resource=Resource({SERVICE_NAME: settings["service_name"]}), metric_readers=readers
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _add_trace_exporter(exporter_type: TraceExporterType, provider: TracerProvider):
|
|
65
|
+
if exporter_type == "otlp":
|
|
66
|
+
_add_traces_otlp_exporter(
|
|
67
|
+
provider,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
elif exporter_type == "console":
|
|
71
|
+
_add_traces_console_exporter(provider)
|
|
72
|
+
else:
|
|
73
|
+
raise NotImplementedError(f"{exporter_type} implementation not supported yet")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _get_metrics_reader(exporter_type: MetricExporterType) -> MetricReader:
|
|
77
|
+
if exporter_type == "otlp":
|
|
78
|
+
return _get_metric_otlp_reader()
|
|
79
|
+
if exporter_type == "console":
|
|
80
|
+
return _get_metric_console_reader()
|
|
81
|
+
raise NotImplementedError(f"{exporter_type} implementation not supported yet")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _add_traces_console_exporter(provider: TracerProvider) -> None:
|
|
85
|
+
exporter = ConsoleSpanExporter()
|
|
86
|
+
processor = SimpleSpanProcessor(exporter)
|
|
87
|
+
provider.add_span_processor(processor)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _add_traces_otlp_exporter(provider: TracerProvider) -> None:
|
|
91
|
+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
|
92
|
+
|
|
93
|
+
exporter = OTLPSpanExporter()
|
|
94
|
+
processor = SimpleSpanProcessor(exporter)
|
|
95
|
+
provider.add_span_processor(processor)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _get_metric_otlp_reader() -> MetricReader:
|
|
99
|
+
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
|
|
100
|
+
|
|
101
|
+
exporter = OTLPMetricExporter()
|
|
102
|
+
return PeriodicExportingMetricReader(exporter)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _get_metric_console_reader() -> MetricReader:
|
|
106
|
+
exporter = ConsoleMetricExporter()
|
|
107
|
+
return PeriodicExportingMetricReader(exporter)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: unstructured-platform-plugins
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.5
|
|
4
4
|
Summary: A utility library that provides tools around unstructured plugin development
|
|
5
5
|
Home-page: https://github.com/Unstructured-IO/unstructured-platform-plugins
|
|
6
6
|
License: Apache-2.0
|
|
@@ -31,6 +31,7 @@ unstructured_platform_plugins.egg-info/top_level.txt
|
|
|
31
31
|
unstructured_platform_plugins/etl_uvicorn/__init__.py
|
|
32
32
|
unstructured_platform_plugins/etl_uvicorn/api_generator.py
|
|
33
33
|
unstructured_platform_plugins/etl_uvicorn/main.py
|
|
34
|
+
unstructured_platform_plugins/etl_uvicorn/otel.py
|
|
34
35
|
unstructured_platform_plugins/etl_uvicorn/utils.py
|
|
35
36
|
unstructured_platform_plugins/schema/__init__.py
|
|
36
37
|
unstructured_platform_plugins/schema/json_schema.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.2" # pragma: no cover
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/__init__.py
RENAMED
|
File without changes
|
{unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/assets/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{unstructured-platform-plugins-0.0.2 → unstructured-platform-plugins-0.0.5}/test/test_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|