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

Count inflight workload as pending #1936

Merged

Conversation

mimowo
Copy link
Contributor

@mimowo mimowo commented Apr 2, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #1937

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fix the counter of pending workloads in cluster queue status. 

The counter would not count the head workload for StrictFIFO queues, if the workload cannot get admitted.

This change also includes the blocked workload in the metrics and the visibility API for the list of pending workloads.

@k8s-ci-robot k8s-ci-robot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 2, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 2, 2024
Copy link

netlify bot commented Apr 2, 2024

Deploy Preview for kubernetes-sigs-kueue canceled.

Name Link
🔨 Latest commit f95af59
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-kueue/deploys/660d5e6e5101a00008b8cf7e

@mimowo mimowo changed the title Test StrictFiFO misreporting metrics [DO NOT MERGE, EXPERIMENT] Test StrictFiFO flaking when reporting metrics [DO NOT MERGE, EXPERIMENT] Apr 2, 2024
@mimowo
Copy link
Contributor Author

mimowo commented Apr 2, 2024

/hold
Experimentation for now

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 2, 2024
@mimowo mimowo force-pushed the main-pending-metric-experiment branch from 4fe6430 to a829ccf Compare April 2, 2024 11:13
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 2, 2024
@mimowo mimowo force-pushed the main-pending-metric-experiment branch 2 times, most recently from e579455 to dc25ca6 Compare April 2, 2024 11:22
@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 2, 2024
@mimowo mimowo force-pushed the main-pending-metric-experiment branch from dc25ca6 to aff3522 Compare April 2, 2024 15:33
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 2, 2024
@mimowo mimowo force-pushed the main-pending-metric-experiment branch 2 times, most recently from 2508913 to 0aec355 Compare April 3, 2024 08:49
@mimowo mimowo changed the title Test StrictFiFO flaking when reporting metrics [DO NOT MERGE, EXPERIMENT] Fix StrictFiFO undercounting pending workloads when blocked Apr 3, 2024
@mimowo mimowo changed the title Fix StrictFiFO undercounting pending workloads when blocked Fix StrictFiFO undercounting pending workloads Apr 3, 2024
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 3, 2024
@mimowo mimowo force-pushed the main-pending-metric-experiment branch 2 times, most recently from bad5983 to 6ea1e82 Compare April 3, 2024 09:36
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 3, 2024
@mimowo mimowo changed the title Fix StrictFiFO undercounting pending workloads Count inflight workload as pending Apr 3, 2024
@mimowo
Copy link
Contributor Author

mimowo commented Apr 3, 2024

/hold cancel
Ready for review

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 3, 2024
@mimowo mimowo force-pushed the main-pending-metric-experiment branch from 6ea1e82 to 119b2e1 Compare April 3, 2024 12:49
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 3, 2024
@mimowo mimowo force-pushed the main-pending-metric-experiment branch 3 times, most recently from a610da2 to 78163a4 Compare April 3, 2024 13:25
@mimowo
Copy link
Contributor Author

mimowo commented Apr 3, 2024

/assign @alculquicondor

@mimowo mimowo force-pushed the main-pending-metric-experiment branch from 78163a4 to f95af59 Compare April 3, 2024 13:49
@@ -153,6 +157,7 @@ func (c *clusterQueueBase) Delete(w *kueue.Workload) {
key := workload.Key(w)
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 did we forget to lock the mutex? Or is it locked by all callers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is locked by the only called currently, that is DeleteFromLocalQueue

Copy link
Contributor

Choose a reason for hiding this comment

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

can we rename it to delete instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, it's also called from the queue Manager, via the ClusterQueue interface.

But we already access the manager through a mutex. Now I'm wondering why we added a dedicated mutex to the ClusterQueue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh it was for the status snapshoter #1069

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right, sorry for confusion, somehow I missed it in vs-code when using the "all references" option.

IIRC we added the mutex to ClusterQueue so that the Snapshot operation (needed for visibility) only requires cq-scoped mutex, and this operation could be expensive.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose there might still be problematic scenarios, for example, the event handlers triggering a Workload deletion while the snapshoter is running.

So we should always be locking the mutex. However, maybe we can get rid of the snapshotter in the near future in favor of the visibility API.

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 suppose there might still be problematic scenarios, for example, the event handlers triggering a Workload deletion while the snapshoter is running.

The main purpose of the cs-scoped mutex is to make sure the heap structure can be iterated and copied so that we don't miss any element due to concurrent modifications.

So we should always be locking the mutex.

yes

However, maybe we can get rid of the snapshotter in the near future in favor of the visibility API.

I think we can get rid of the snapshotter that persists data in etcd, but the Snapshot() function itself is used by the visibility API to get consistent view of the workloads, so I don't see a way of dropping the cq-scoped mutex, unless:

  • we use the manager-scoped mutex, but this would impact performance
  • don't use mutex for Snapshot() at all, but this would impact consistency of results during updates

@@ -235,7 +247,11 @@ func (c *clusterQueueBase) Pending() int {
}

func (c *clusterQueueBase) PendingActive() int {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ever called without locking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it is called from two places:

  • cq.Pending() - this is using read lock scoped to the cq
  • manager.reportPendingWorkloads(), but all invocations of this function take manager lock, which is broader range than cq

Copy link
Contributor

@alculquicondor alculquicondor left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 3, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 787aa61cb564ef774a812027fb97db41299f7826

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alculquicondor, mimowo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit b0a02c6 into kubernetes-sigs:main Apr 3, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v0.7 milestone Apr 3, 2024
@tenzen-y
Copy link
Member

tenzen-y commented Apr 3, 2024

@alculquicondor @mimowo Isn't this a bug?

@mimowo
Copy link
Contributor Author

mimowo commented Apr 4, 2024

@alculquicondor @mimowo Isn't this a bug?

yes, it is, let me update the labels:

/kind-remove cleanup
/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Apr 4, 2024
@tenzen-y
Copy link
Member

tenzen-y commented Apr 4, 2024

@alculquicondor @mimowo Isn't this a bug?

yes, it is, let me update the labels:

/kind-remove cleanup /kind bug

Also, should we do cherry-pick to v0.6.

@mimowo
Copy link
Contributor Author

mimowo commented Apr 4, 2024

Also, should we do cherry-pick to v0.6.

I would vote in favor of cherry-picking, the risk seems small. On the other hand it wasn't reported by users, but me when I was working on the feature: #1873, so may not be critical.

I checked that there is a small conflict with #1815, if we include #1815, then it cherry-picks without conflict.

@alculquicondor
Copy link
Contributor

This doesn't seem urgent enough for a cherry-pick IMO

@tenzen-y
Copy link
Member

tenzen-y commented Apr 4, 2024

Considering conflicts, I'm ok without cherry-pick.

vsoch pushed a commit to researchapps/kueue that referenced this pull request Apr 18, 2024
* Test StrictFiFO misreporting metrics

* Cleanup and expand the integration test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In some scenarios the ClusterQueue status shows wrong count for PendingWorkloads
4 participants