Skip to content

Improved Kubernetes orchestrator pod caching #3719

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

Merged
merged 25 commits into from
Jun 27, 2025

Conversation

schustmi
Copy link
Contributor

@schustmi schustmi commented Jun 2, 2025

Describe changes

This PR

  • enables orchestrator pod caching for scheduled runs.
  • delays the caching decision to run right before the actual step pod starts, not at orchestrator pod startup. This means the caching decision will be made with the latest state of all step runs available in the server, which might differ from the step runs available at orchestrator pod startup.
  • adds metadata to the Kubernetes orchestrator.
  • improves pod labels when using the Kubernetes orchestrator.

Changes to what we consider placeholder runs:
Previously, a run without an orchestrator_run_id in the database was considered a placeholder run. This PR changes that behaviour and instead uses the status of a run to decide whether the run is a placeholder run (runs with state initializing are placeholder runs). This change was necessary so that the orchestrator pod can create a pipeline run (with orchestrator run ID) for scheduled runs to enable the orchestrator pod caching.

Pre-requisites

Please ensure you have done the following:

  • I have read the CONTRIBUTING.md document.
  • I have added tests to cover my changes.
  • I have based my new branch on develop and the open PR is targeting develop. If your branch wasn't based on develop read Contribution guide on rebasing branch to develop.
  • IMPORTANT: I made sure that my changes are reflected properly in the following resources:
    • ZenML Docs
    • Dashboard: Needs to be communicated to the frontend team.
    • Templates: Might need adjustments (that are not reflected in the template tests) in case of non-breaking changes and deprecations.
    • Projects: Depending on the version dependencies, different projects might get affected.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Other (add details above)

Copy link
Contributor

coderabbitai bot commented Jun 2, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@github-actions github-actions bot added internal To filter out internal PRs and issues enhancement New feature or request labels Jun 2, 2025
Copy link
Contributor

github-actions bot commented Jun 3, 2025

Documentation Link Check Results

Absolute links check passed
Relative links check passed
Last checked: 2025-06-05 07:30:49 UTC

@schustmi schustmi requested a review from stefannica June 3, 2025 15:03
@schustmi schustmi changed the base branch from main to develop June 5, 2025 08:24
Copy link
Contributor

@stefannica stefannica left a comment

Choose a reason for hiding this comment

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

Mostly questions, looks good overall.

Comment on lines +5860 to +5869
# In very rare cases, there can be multiple placeholder runs for
# the same deployment. By ordering by the orchestrator_run_id, we
# make sure that we use the placeholder run with the matching
# orchestrator_run_id if it exists, before falling back to the
# placeholder run without any orchestrator_run_id provided.
# Note: This works because both SQLite and MySQL consider NULLs
# to be lower than any other value. If we add support for other
# databases (e.g. PostgreSQL, which considers NULLs to be greater
# than any other value), we need to potentially adjust this.
.order_by(desc(PipelineRunSchema.orchestrator_run_id))
Copy link
Contributor

Choose a reason for hiding this comment

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

good to know !

Comment on lines +155 to +163
# As a last resort, we try to reuse the docstring/source code
# from the cached step run. This is part of the cache key
# computation, so it must be identical to the one we would have
# computed ourselves.
if request.source_code is None:
request.source_code = cached_step_run.source_code
if request.docstring is None:
request.docstring = cached_step_run.docstring

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain this part a bit ? This wasn't necessary before and the _get_docstring_and_source_code already attempts to fetch these from various sources (the step instance and run template). Why is it absolutely necessary now that these be populated in the request, if it wasn't necessary before ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was never necessary (both of those fields are optional). It just now occurred to me that we can simply reuse the code/docstring of the cached step if we can't figure it out in any other way, so I added it. Otherwise, all steps that got cached from the orchestrator pod would not have any code/docstring associated with them, as

  • the code to import the step instance most likely doesn't exist in the orchestrator pod
  • there is no run template involved

Comment on lines 302 to 306
step_runs = Client().list_run_steps(
size=1,
pipeline_run_id=pipeline_run.id,
name=step_name,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

this will scale badly, I know it. For 1000 steps, it will make 1000 calls to the API. I think we might need a new endpoint that fetches the status of all steps in one go. Or maybe move this whole thing behind the REST API.

Copy link
Contributor

Choose a reason for hiding this comment

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

On second thought, this whole thing feels like something that should happen server-side when the pipeline run status is updated... this whole thing needs to be reconsidered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My change here only improves upon the previous implementation, which fetched all steps of the pipeline run. My solution instead only fetches the steps for which the pod is actually in a failed state. However, I definitely agree that we could batch this into some requests, instead of fetching each step separately. I'll change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm now fetching only relevant steps, and doing so in batched chunks.

@schustmi schustmi requested a review from stefannica June 26, 2025 07:42
@schustmi schustmi merged commit 331eaef into develop Jun 27, 2025
48 of 49 checks passed
@schustmi schustmi deleted the feature/kubernetes-pod-caching-v2 branch June 27, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request internal To filter out internal PRs and issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants