-
Notifications
You must be signed in to change notification settings - Fork 2
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
[CDF-23583] 👮♂️ CPU and Memory outside function limit #1309
Open
doctrino
wants to merge
27
commits into
main
Choose a base branch
from
function-redeploy-issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3e75bcd
test: extend testing
doctrino 3518dcd
fix: implemented emtpy
doctrino 3bc4d0c
tests: updated mocking
doctrino 84e9999
fix: quote version key in location filter
doctrino ca9c216
feat: added data modeling type
doctrino 59038a6
tests: updated test
doctrino d5349d2
tests: regen
doctrino 651497b
feat: support data modeling type
doctrino faa738a
tests: update mock lookup
doctrino e651803
build: changelog
doctrino 23dfbde
fix: introduced bugs
doctrino 84d0958
fix; bug bug
doctrino 9cbd3be
fix; bug bug bug
doctrino 0d02410
tests: standardize
doctrino 5530e99
tests: standardize 2
doctrino ce5129a
tests: set cpu and memory outside limits
doctrino 4413d27
tests: try to recreate issue
doctrino 9e241a4
docs: documented case
doctrino c97e2d3
fix: redeployment issue
doctrino 710e03b
feat: added warning on mistake
doctrino 729d45d
style: warning message
doctrino 6e5d94d
feat; introduce ToolkitClientConfig
doctrino d04e293
style: better return value
doctrino 3041834
refactor: renaming
doctrino c0c250a
Update cognite_toolkit/_cdf_tk/client/_toolkit_client.py
doctrino f38ff21
docs; better docs
doctrino 00d9ee8
refactor: deal with special behavior
doctrino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from ._toolkit_client import ToolkitClient | ||
from ._toolkit_client import ToolkitClient, ToolkitClientConfig | ||
|
||
__all__ = ["ToolkitClient"] | ||
__all__ = ["ToolkitClient", "ToolkitClientConfig"] |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Literal, cast | ||
|
||
from cognite.client import ClientConfig, CogniteClient | ||
|
||
from .api.dml import DMLAPI | ||
|
@@ -9,11 +11,41 @@ | |
from .api.verify import VerifyAPI | ||
|
||
|
||
class ToolkitClientConfig(ClientConfig): | ||
@property | ||
def cloud_provider(self) -> Literal["azure", "aws", "gcp", "unknown"]: | ||
cdf_cluster = self.cdf_cluster | ||
if cdf_cluster is None: | ||
return "unknown" | ||
elif cdf_cluster.startswith("az-") or cdf_cluster in {"azure-dev", "bluefield", "westeurope-1"}: | ||
return "azure" | ||
elif cdf_cluster.startswith("aws-") or cdf_cluster in {"orangefield"}: | ||
return "aws" | ||
elif cdf_cluster.startswith("gc-") or cdf_cluster in { | ||
"greenfield", | ||
"asia-northeast1-1", | ||
"cognitedata-development", | ||
"cognitedata-production", | ||
}: | ||
return "gcp" | ||
else: | ||
return "unknown" | ||
|
||
|
||
class ToolkitClient(CogniteClient): | ||
def __init__(self, config: ClientConfig | None = None) -> None: | ||
def __init__(self, config: ToolkitClientConfig | None = None) -> None: | ||
super().__init__(config=config) | ||
self.location_filters = LocationFiltersAPI(self._config, self._API_VERSION, self) | ||
self.robotics = RoboticsAPI(self._config, self._API_VERSION, self) | ||
self.dml = DMLAPI(self._config, self._API_VERSION, self) | ||
self.verify = VerifyAPI(self._config, self._API_VERSION, self) | ||
self.lookup = LookUpGroup(self._config, self._API_VERSION, self) | ||
|
||
@property | ||
def config(self) -> ToolkitClientConfig: | ||
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. Overwrites the |
||
"""Returns a config object containing the configuration for the current client. | ||
|
||
Returns: | ||
ToolkitClientConfig: The configuration object. | ||
""" | ||
return cast(ToolkitClientConfig, self._config) |
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 |
---|---|---|
|
@@ -153,6 +153,19 @@ def dump_resource(self, resource: Function, local: dict[str, Any]) -> dict[str, | |
if key not in local: | ||
# Server set default values | ||
dumped.pop(key, None) | ||
elif isinstance(local.get(key), float) and local[key] < dumped[key]: | ||
# On Azure and AWS, the server sets the CPU and Memory to the default values if the user | ||
# pass in lower values. We set this to match the local to avoid triggering a redeploy. | ||
# Note the user will get a warning about this when the function is created. | ||
if self.client.config.cloud_provider in ("azure", "aws"): | ||
dumped[key] = local[key] | ||
elif self.client.config.cloud_provider == "gcp" and key == "cpu" and local[key] < 1.0: | ||
# GCP does not allow CPU to be set to below 1.0 | ||
dumped[key] = local[key] | ||
elif self.client.config.cloud_provider == "gcp" and key == "memory" and local[key] < 1.5: | ||
# GCP does not allow Memory to be set to below 1.5 | ||
dumped[key] = local[key] | ||
|
||
for key in ["indexUrl", "extraIndexUrls"]: | ||
# Only in write (request) format of the function | ||
if key in local: | ||
|
@@ -224,9 +237,38 @@ def create(self, items: FunctionWriteList) -> FunctionList: | |
else: | ||
raise RuntimeError("Could not retrieve file from files API") | ||
item.file_id = file_id | ||
created.append(self.client.functions.create(item)) | ||
created_item = self.client.functions.create(item) | ||
self._warn_if_cpu_or_memory_changed(created_item, item) | ||
created.append(created_item) | ||
return created | ||
|
||
@staticmethod | ||
def _warn_if_cpu_or_memory_changed(created_item: Function, item: FunctionWrite) -> None: | ||
is_cpu_increased = ( | ||
isinstance(item.cpu, float) and isinstance(created_item.cpu, float) and item.cpu < created_item.cpu | ||
) | ||
is_mem_increased = ( | ||
isinstance(item.memory, float) | ||
and isinstance(created_item.memory, float) | ||
and item.memory < created_item.memory | ||
) | ||
if is_cpu_increased and is_mem_increased: | ||
prefix = "CPU and Memory" | ||
suffix = f"CPU {item.cpu} -> {created_item.cpu}, Memory {item.memory} -> {created_item.memory}" | ||
elif is_cpu_increased: | ||
prefix = "CPU" | ||
suffix = f"{item.cpu} -> {created_item.cpu}" | ||
elif is_mem_increased: | ||
prefix = "Memory" | ||
suffix = f"{item.memory} -> {created_item.memory}" | ||
else: | ||
return | ||
# The server sets the CPU and Memory to the default values, if the user pass in a lower value. | ||
# This happens on Azure and AWS. Warning the user about this. | ||
LowSeverityWarning( | ||
f"Function {prefix} is not configurable. Function {item.external_id!r} set {suffix}" | ||
).print_warning() | ||
Comment on lines
+268
to
+270
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. In addition, give the user a warning that whatever they set has no effect. |
||
|
||
def retrieve(self, ids: SequenceNotStr[str]) -> FunctionList: | ||
if not self._is_activated("retrieve"): | ||
return FunctionList([]) | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
Small extension of the
ClientConfig
to include new property.