-
Notifications
You must be signed in to change notification settings - Fork 907
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 typing to proto converters and fix breaks #4544
Closed
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3b65a33
Add typing to proto converters and fix breaks
inlined a1fd035
Fix comment typos
inlined bc10de5
Merge branch 'master' into inlined.well-typed-converters
bkendall 2fbb816
PR feedback
inlined 3b2ce55
Merge remote-tracking branch 'origin/master' into inlined.well-typed-…
inlined File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,12 +211,12 @@ const BYTES_PER_UNIT: Record<MemoryUnit, number> = { | |
}; | ||
|
||
/** | ||
* Returns the float-precision number of Mega(not Mebi)bytes in a | ||
* Returns the float-precision number of Mebibytes in a | ||
* Kubernetes-style quantity | ||
* Must serve the same results as | ||
* https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go | ||
*/ | ||
export function mebibytes(memory: string): number { | ||
export function mebibytes(memory: string): backend.MemoryOptions { | ||
const re = /^([0-9]+(\.[0-9]*)?)(Ki|Mi|Gi|Ti|k|M|G|T|([eE]([0-9]+)))?$/; | ||
const matches = re.exec(memory); | ||
if (!matches) { | ||
|
@@ -230,7 +230,12 @@ export function mebibytes(memory: string): number { | |
const suffix = matches[3] || ""; | ||
bytes = quantity * BYTES_PER_UNIT[suffix as MemoryUnit]; | ||
} | ||
return bytes / (1 << 20); | ||
bytes = bytes / (1 << 20); | ||
const typed = bytes as backend.MemoryOptions; | ||
if (backend.AllMemoryOptions.includes(typed)) { | ||
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. should there be a 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. yup |
||
logger.warn(`Got a non-standard memory option ${memory}; this may break tools`); | ||
} | ||
return typed; | ||
} | ||
|
||
/** | ||
|
@@ -454,10 +459,16 @@ export function functionFromEndpoint(endpoint: backend.Endpoint, source: Storage | |
"ingressSettings", | ||
"timeoutSeconds" | ||
); | ||
// Memory must be set because the default value of GCF gen 2 is Megabytes and | ||
// we use mebibytes | ||
const mem: number = endpoint.availableMemoryMb || backend.DEFAULT_MEMORY; | ||
gcfFunction.serviceConfig.availableMemory = mem > 1024 ? `${mem / 1024}Gi` : `${mem}Mi`; | ||
// Due to reverse compatibility with GCF gen 1, GCF defaults to 256MB instead | ||
// of 256MiB. This is despite the fact that it seems like GCF gen 1's "MB" is | ||
// GCF gen 2's "MiB" (or at least we interpreted it that way in the past). | ||
// 128MiB functions break if we use MB instead of MiB so we always use MiB. | ||
// This means though that we need to default explicitly to 256MiB over 256MB | ||
// otherwise we read 256MB as 244.1MiB on update and break Pantheon which | ||
// expects an enum of memories and doesn't care that 244.1MiB == 256MB. | ||
const mb = endpoint.availableMemoryMb || backend.DEFAULT_MEMORY; | ||
gcfFunction.serviceConfig.availableMemory = mb > 1024 ? `${mb / 1024}Gi` : `${mb}Mi`; | ||
|
||
proto.renameIfPresent(gcfFunction.serviceConfig, endpoint, "minInstanceCount", "minInstances"); | ||
proto.renameIfPresent(gcfFunction.serviceConfig, endpoint, "maxInstanceCount", "maxInstances"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Isn't this identical to L374?
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.
yup