-
Notifications
You must be signed in to change notification settings - Fork 632
UN-2771 [FEAT] Report text extraction time in API deployment metrics #2032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -619,10 +619,12 @@ def _failure(child_result: ExecutionResult) -> ExecutionResult: | |
| ) | ||
| step = 1 | ||
|
|
||
| extraction_metrics: dict = {} | ||
| try: | ||
| # ---- Step 1: Extract ---- | ||
| if not skip_extraction: | ||
| step += 1 | ||
| extraction_start = time.monotonic() | ||
| extract_ctx = ExecutionContext( | ||
| executor_name=context.executor_name, | ||
| operation=Operation.EXTRACT.value, | ||
|
|
@@ -640,6 +642,9 @@ def _failure(child_result: ExecutionResult) -> ExecutionResult: | |
| return _failure(extract_result) | ||
| _absorb(extract_result) | ||
| extracted_text = extract_result.data.get(IKeys.EXTRACTED_TEXT, "") | ||
| extraction_metrics = { | ||
| "extraction": {"time_taken(s)": time.monotonic() - extraction_start} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maintainability (distinct from the key-collision note on L647): this hardcodes the literal Minor readability: for parity with the indexing path ( extraction_time = time.monotonic() - extraction_start
extraction_metrics = {PSKeys.EXTRACTION: {"time_taken(s)": extraction_time}} |
||
| } | ||
|
Comment on lines
+645
to
+647
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid top-level metrics key collision with user prompt names
Use a reserved namespace for pipeline-level metrics (e.g., Also applies to: 804-811 🤖 Prompt for AI Agents |
||
|
|
||
| # ---- Step 2: Summarize (if enabled) ---- | ||
| if is_summarization: | ||
|
|
@@ -700,6 +705,7 @@ def _failure(child_result: ExecutionResult) -> ExecutionResult: | |
| source_file_name=source_file_name, | ||
| extracted_text=extracted_text, | ||
| index_metrics=index_metrics, | ||
| extraction_metrics=extraction_metrics, | ||
| ) | ||
|
|
||
| output_map = structured_output.get(PSKeys.OUTPUT, {}) or {} | ||
|
|
@@ -787,17 +793,21 @@ def _finalize_pipeline_result( | |
| source_file_name: str, | ||
| extracted_text: str, | ||
| index_metrics: dict, | ||
| extraction_metrics: dict | None = None, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new |
||
| ) -> None: | ||
| """Populate metadata/metrics in structured_output after pipeline completion.""" | ||
| if "metadata" not in structured_output: | ||
| structured_output["metadata"] = {} | ||
| structured_output["metadata"]["file_name"] = source_file_name | ||
| if extracted_text: | ||
| structured_output["metadata"]["extracted_text"] = extracted_text | ||
| if index_metrics: | ||
| new_metrics = self._merge_pipeline_metrics( | ||
| index_metrics or {}, extraction_metrics or {} | ||
| ) | ||
| if new_metrics: | ||
| existing_metrics = structured_output.get("metrics", {}) | ||
| structured_output["metrics"] = self._merge_pipeline_metrics( | ||
| existing_metrics, index_metrics | ||
| existing_metrics, new_metrics | ||
| ) | ||
|
|
||
| def _run_pipeline_summarize( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clock-source consistency: extraction times the step with
time.monotonic(), while the sibling indexing metric uses wall-clockdatetime.datetime.now()(L1029).time.monotonic()is the correct choice for duration measurement (immune to NTP / system-clock adjustments), so this code is right — but the two producers of"time_taken(s)"now use different clocks. Worth a follow-up to align the indexing path ontomonotonic()too.