Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

fix: add CPU field to resolvedOfferings and change QuotaRequests to use resolvedOfferings #2462

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

tylerslaton
Copy link
Contributor

This PR adjusts two main things.

  1. Removes the cpuScaler field from ResolvedOfferings in favor of a new cpu field.
  2. Updates QuotaRequests to report against the ResolvedOfferings fields for container compute.

These two things are necessary for ComputeClasses that define a requestScaler on memory as we want to quota against the requested amount, not the incoming scaled down amount.

Checklist

  • The title of this PR would make a good line in Acorn's Release Note's Changelog
  • The title of this PR ends with a link to the main issue being address in parentheses, like: This is a title (#1216). Here's an example
  • All relevant issues are referenced in the PR description. NOTE: don't use GitHub keywords that auto-close issues
  • Commits follow contributing guidance
  • Automated tests added to cover the changes. If tests couldn't be added, an explanation is provided in the Verification and Testing section
  • Changes to user-facing functionality, API, CLI, and upgrade impacts are clearly called out in PR description
  • PR has at least two approvals before merging (or a reasonable exception, like it's just a docs change)

@tylerslaton
Copy link
Contributor Author

This will have overlap with #2454. I will merge that one first but want to open this up for review.

@tylerslaton tylerslaton marked this pull request as ready for review January 26, 2024 17:03
Copy link
Contributor

@keyallis keyallis left a comment

Choose a reason for hiding this comment

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

1 quick comment but otherwise LGTM

Comment on lines 20 to 22
min: 100Mi # 1Mi
max: 200Mi # 2Mi
default: 100Mi # 1Mi
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the comments here

Copy link
Contributor

@thedadams thedadams left a comment

Choose a reason for hiding this comment

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

The resolved offerings get recalculated only when the app's generation changes. I believe that means that, after this change goes in, there will be apps that don't have CPUScaler (because it is being removed) nor CPU (because it's not being set). Are we OK with this? Should we handle this case?

Comment on lines 146 to 147
quotaRequest.Spec.Resources.CPU.Add(cpu)
quotaRequest.Spec.Resources.Memory.Add(memory)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: cal we use the Mul method here instead of this loop?

Copy link
Contributor Author

@tylerslaton tylerslaton Jan 30, 2024

Choose a reason for hiding this comment

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

We can, that change logic is being done in a different PR.

@tylerslaton
Copy link
Contributor Author

tylerslaton commented Jan 30, 2024

@thedadams The resolved offerings get recalculated only when the app's generation changes. I believe that means that, after this change goes in, there will be apps that don't have CPUScaler (because it is being removed) nor CPU (because it's not being set). Are we OK with this? Should we handle this case?

The resolvedOfferings CPUScaler is currently not utilized anywhere in our codebase, including any dependencies of runtime. Therefore, removing it will have no impact on existing applications. It's worth noting that while there will be instances where resolvedOfferings.CPU is not set for an application, this is acceptable because the scheduling section will ensure the retention of the previously defined request. Once that application updates it will go through the process of getting resolvedOfferings.CPU instead.

@tylerslaton tylerslaton requested a review from thedadams January 30, 2024 16:38
@tylerslaton tylerslaton force-pushed the quota-ro branch 2 times, most recently from b74db86 to 9926d71 Compare February 1, 2024 19:30
…se resolvedOfferings

This change makes it so that we always quota against the resolvedOfferings instead
of the scheduling for the app. This is because the scheduling for the app is always
accurate to what is actually running, but the resolvedOfferings is what the user
requested.

This change also adds a CPU field to the resolvedOfferings so that we can quota
against the CPU that the user requested from one place instead of having to calculate
it from the cpuScaler.

Signed-off-by: tylerslaton <[email protected]>
quotaRequest.Spec.Resources.Memory.Add(requirements.Requests["memory"])
}
// Multiply the memory/cpu requests by the scale of the container
cpu.Mul(replicas(container.Scale))
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 previously in the ComputeClass quota PR but I just brought it here instead.

@g-linville
Copy link
Contributor

Forgive me if my memory is failing, but even though I previously approved this PR, I find this choice confusing. I think it makes the most sense to just continue using the scheduling field for quota stuff instead of resolvedOfferings. I also don't know why we want CPU (or CPUScaler for that matter) on resolvedOfferings, because I think that is irrelevant to the user...

@tylerslaton
Copy link
Contributor Author

Forgive me if my memory is failing, but even though I previously approved this PR, I find this choice confusing. I think it makes the most sense to just continue using the scheduling field for quota stuff instead of resolvedOfferings.

This all revolves around a recent field addition that we made to defining memory in ComputeClasses, requestScaler for memory. Let's look at an example of this in action to help illustrate the need here. Say that we define a ComputeClass where it has a memory requestScaler or 0.5. If a user requests 1Gi of memory then what they will actually have scheduled here is 512Mi of memory. Since quota reads from the scheduling section this means we will quota for 512Mi of memory. However, we really want to quota for 1Gi of memory here. Our options were:

  1. Read from the limits section of scheduling (already vetoed)
  2. Read from the ResolvedOfferings section of status

I also don't know why we want CPU (or CPUScaler for that matter) on resolvedOfferings, because I think that is irrelevant to the user...

I added this mainly since it is nicer to have ResolvedOfferings field tell me what the CPU should be as opposed to using the cpuScaler to determine what the CPU should be. In either situation I need to have an additional field tell me what (or how to calculate what) the CPU should be.

@g-linville
Copy link
Contributor

Thanks for the explanation. That makes sense now. Idk why I got so confused on Saturday lol.

Copy link
Member

@njhale njhale left a comment

Choose a reason for hiding this comment

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

One non-blocking question.

CPUScaler: appInstance.Status.ResolvedOfferings.Containers[""].CPUScaler,
Class: appInstance.Status.ResolvedOfferings.Containers[""].Class,
Memory: appInstance.Spec.Memory[""],
CPU: z.Pointer(cpuQuantity.MilliValue()),
Copy link
Member

Choose a reason for hiding this comment

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

just curious: is there a behavioral difference between nil and a pointer to a zero value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talked offline. This reflects a weirder issue in quota. I'm going to make an issue for that, merge this, and come back to fix what this points to.

@tylerslaton tylerslaton merged commit 6a26e9b into acorn-io:main Feb 5, 2024
4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants