Skip to content
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

Add set_log_upload_error for DOs #5448

Merged
merged 3 commits into from
Jan 30, 2025
Merged

Add set_log_upload_error for DOs #5448

merged 3 commits into from
Jan 30, 2025

Conversation

CamronStaley
Copy link
Contributor

@CamronStaley CamronStaley commented Jan 29, 2025

What changes are proposed in this pull request?

Adding set_log_upload_error for DOs so that we can update that field when needed for use in delegated operations. This field will be populated if we fail to flush logs to the user provided log location after a DO finishes execution.

Also, adding an index on dataset_id so we can filter without needing to do a scan making this collection scale better as DOs get used more overtime.

How is this patch tested? If it is not, please explain why.

script:

from fiftyone.operators.delegated import DelegatedOperationService

do = DelegatedOperationService()
dos = do.get_running_operations()
do.set_log_upload_error(dos[0].id, log_upload_error="test")

Result:

{
  "_id": {
    "$oid": "671142e671e8dc3ec03dafbe"
  },
  "operator": "@voxelfiftyone/operator/foo",
  "label": "@voxelfiftyone/operator/foo",
  "delegation_target": "test_target",
  "context": {
    "request_params": {
      "foo": "bar"
    },
    "params": {},
    "executor": null,
    "user": null
  },
  "run_state": "running",
  "run_link": null,
  "queued_at": {
    "$date": "2024-10-17T17:01:26.650Z"
  },
  "updated_at": {
    "$date": "2024-10-17T17:01:26.650Z"
  },
  "status": null,
  "dataset_id": null,
  "started_at": {
    "$date": "2024-10-17T17:01:26.650Z"
  },
  "pinned": false,
  "completed_at": null,
  "failed_at": null,
  "scheduled_at": null,
  "result": null,
  "metadata": {
    "inputs_schema": {
      "inputs": {
        "type": "string"
      }
    }
  },
  "log_upload_error": "test"
}

Index created:

Screenshot 2025-01-29 at 2 46 25 PM

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Added ability to set log upload errors for delegated operations.
    • Introduced new log_upload_error attribute to track log upload issues.
  • Performance Improvements

    • Enhanced database indexing for more efficient queries on dataset operations.
  • Technical Enhancements

    • Expanded delegated operation document model to support log upload error tracking.
    • Implemented repository method for updating log upload errors across different components.

@CamronStaley CamronStaley requested a review from a team January 29, 2025 20:47
@CamronStaley CamronStaley self-assigned this Jan 29, 2025
Copy link
Contributor

coderabbitai bot commented Jan 29, 2025

Walkthrough

The pull request introduces a new method set_log_upload_error to the DelegatedOperationRepo class, which facilitates setting a log upload error for delegated operations. The MongoDelegatedOperationRepo class implements this method to update the log_upload_error field in the MongoDB collection. Additionally, the DelegatedOperationDocument class gains a new attribute, log_upload_error, initialized to None. The indexing logic for the dataset_id field is also enhanced to improve query performance.

Changes

File Change Summary
fiftyone/factory/repos/delegated_operation.py - Added set_log_upload_error method to DelegatedOperationRepo (abstract)
- Implemented set_log_upload_error in MongoDelegatedOperationRepo
- Modified _create_indexes to include index for dataset_id
fiftyone/factory/repos/delegated_operation_doc.py - Added log_upload_error attribute to DelegatedOperationDocument
- Updated __init__ and from_pymongo methods to support log_upload_error
fiftyone/operators/delegated.py - Added set_log_upload_error method to DelegatedOperationService

Possibly related PRs

  • add support for atomic state transitions #4893: The changes in this PR modify the DelegatedOperationRepo and DelegatedOperationService classes, which are directly related to the new set_log_upload_error method added in the main PR, as both involve enhancements to the handling of delegated operations within the same repository structure.

Suggested reviewers

  • swheaton

Poem

🐰 In the code where errors play,
A new log's here to save the day!
With every hop and every line,
Delegated tasks now brightly shine.
Let's celebrate this change so grand,
A rabbit's joy, a coder's hand! 🎉

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
fiftyone/operators/delegated.py (1)

255-265: Fix docstring formatting.

There's a typo in the Args section of the docstring.

Apply this diff to fix the formatting:

        Args:
            doc_id: the ID of the delegated operation
-            log status: the status of the logs to set
+            log_status: the status of the logs to set
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffd7f97 and 594538f.

📒 Files selected for processing (3)
  • fiftyone/factory/repos/delegated_operation.py (3 hunks)
  • fiftyone/factory/repos/delegated_operation_doc.py (2 hunks)
  • fiftyone/operators/delegated.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
fiftyone/factory/repos/delegated_operation_doc.py

76-76: Use doc.get("log_status") instead of doc.get("log_status", None)

Replace doc.get("log_status", None) with doc.get("log_status")

(SIM910)

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: lint / eslint
  • GitHub Check: e2e / test-e2e
  • GitHub Check: build / build
  • GitHub Check: build / changes
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.11)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.9)
  • GitHub Check: test / test-app
  • GitHub Check: build
🔇 Additional comments (4)
fiftyone/factory/repos/delegated_operation_doc.py (1)

59-59: LGTM: Added log_status attribute.

The new attribute is properly initialized as None.

fiftyone/factory/repos/delegated_operation.py (3)

120-124: LGTM: Well-defined abstract method.

The abstract method follows the established pattern with proper type hints and documentation.


176-181: LGTM: Added index for dataset_id field.

The index creation follows the established pattern and is properly guarded.


255-263: LGTM: Proper implementation of set_log_status.

The implementation follows the established pattern of other similar methods and uses atomic operations.

fiftyone/factory/repos/delegated_operation_doc.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
fiftyone/factory/repos/delegated_operation_doc.py (1)

76-76: Simplify the get() call.

The explicit None default is redundant as dict.get() returns None by default when the key is not found.

-        self.log_upload_error = doc.get("log_upload_error", None)
+        self.log_upload_error = doc.get("log_upload_error")
🧰 Tools
🪛 Ruff (0.8.2)

76-76: Use doc.get("log_upload_error") instead of doc.get("log_upload_error", None)

Replace doc.get("log_upload_error", None) with doc.get("log_upload_error")

(SIM910)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 594538f and 9571eb6.

📒 Files selected for processing (3)
  • fiftyone/factory/repos/delegated_operation.py (3 hunks)
  • fiftyone/factory/repos/delegated_operation_doc.py (2 hunks)
  • fiftyone/operators/delegated.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • fiftyone/operators/delegated.py
🧰 Additional context used
🪛 Ruff (0.8.2)
fiftyone/factory/repos/delegated_operation_doc.py

76-76: Use doc.get("log_upload_error") instead of doc.get("log_upload_error", None)

Replace doc.get("log_upload_error", None) with doc.get("log_upload_error")

(SIM910)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.11)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.9)
  • GitHub Check: test / test-app
  • GitHub Check: e2e / test-e2e
  • GitHub Check: lint / eslint
  • GitHub Check: build / build
  • GitHub Check: build
🔇 Additional comments (5)
fiftyone/factory/repos/delegated_operation_doc.py (2)

59-59: LGTM! Clear and consistent attribute initialization.

The log_upload_error attribute is properly initialized as None, following the established pattern in the class.


Line range hint 119-125: LGTM! Proper serialization of the new field.

The log_upload_error field is correctly handled by the existing __dict__ serialization in to_pymongo().

fiftyone/factory/repos/delegated_operation.py (3)

120-124: LGTM! Well-defined abstract method.

The set_log_upload_error method is properly defined with clear type hints and follows the abstract method pattern.


176-181: LGTM! Proper index creation for dataset_id field.

The index creation follows the established pattern and will improve query performance when filtering by dataset_id.


255-263: LGTM! Clean and consistent implementation.

The set_log_upload_error implementation follows the established pattern using atomic operations and proper return values.

Comment on lines +176 to +182
if "dataset_id_1" not in index_names:
indices_to_create.append(
IndexModel(
[("dataset_id", pymongo.ASCENDING)], name="dataset_id_1"
)
)

Copy link
Contributor

@swheaton swheaton Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be good to have a compound index on dataset id then other attributes we want to filter/sort by. but this (dataset_id index) is required at minimum.

@swheaton swheaton changed the title Add set_log_status for DOs Add set_log_upload_error for DOs Jan 30, 2025
Copy link
Contributor

@swheaton swheaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm; ran provided test script and works.

@CamronStaley CamronStaley merged commit 847015e into develop Jan 30, 2025
14 checks passed
@CamronStaley CamronStaley deleted the feat/log-status branch January 30, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants