-
Notifications
You must be signed in to change notification settings - Fork 54
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
Append SNOWFLAKE_CLI_TEST_RESOURCE_SUFFIX value to app and package name #1443
Conversation
@@ -129,12 +134,13 @@ def project_identifier(self) -> str: | |||
# sometimes strip out double quotes, so we try to get them back here. | |||
return to_identifier(self.definition.name) | |||
|
|||
@cached_property | |||
@property |
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.
removed caching to avoid caching the suffix in tests, since it will contain an ID that should be unique for each test
7d4c2f3
to
4a0c31a
Compare
RELEASE-NOTES.md
Outdated
@@ -31,6 +31,7 @@ | |||
* Currently only supports SQL scripts: `post_deploy: [{sql_script: script.sql}]` | |||
* Added `snow spcs service execute-job` command, which supports creating and executing a job service in the current schema. | |||
* Added `snow app events` command to fetch logs and traces from local and customer app installations | |||
* Added support for `SNOWFLAKE_CLI_RESOURCE_SUFFIX` environment variable to be used as a suffix for Native App package and app names |
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.
not sure what's the common practice on this. Since this is purely internal for testing purposes, should we skip it from release notes?
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.
i added it cause it could technically be used by end-users. I'm ok leaving it off if we want to consider this an undocumented feature
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.
I think the variable is rather misleading since it seems to imply it will cause all resources to be suffixed, but that's not the case. I'd leave this to be undocumented since we're not guaranteeing a user can build workflows on it.
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.
SNOWFLAKE_CLI_TEST_RESOURCE_SUFFIX
might convey the intention here a little more clearly? We are not in any way saying this should be used in a production setting.
if self.definition.package and self.definition.package.name: | ||
return to_identifier(self.definition.package.name) | ||
return append_to_identifier( | ||
to_identifier(self.definition.package.name), suffix |
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.
this is a bit tricky, because it assumes suffix is a safe identifier.
concat_identifiers() might be what you're looking for.
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.
oh TIL, will update
4a0c31a
to
b6c66d3
Compare
def resource_suffix() -> str: | ||
"""A suffix that should be added to account-level resources.""" | ||
return os.environ.get(SNOWFLAKE_CLI_RESOURCE_SUFFIX_VAR, "") |
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.
Should this really be part of the public API? At least we should give it a very descriptive name, I normally worry about making non-prod logic sound so prod-like.
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.
based on our discussion earlier, it seemed to me that this would indeed be part of the public API (but undocumented). Let's PL this for tomorrow morning
b6c66d3
to
23bd066
Compare
23bd066
to
4125642
Compare
def default_app_package(project_name: str): | ||
user = clean_identifier(get_env_username() or DEFAULT_USERNAME) | ||
return append_to_identifier(to_identifier(project_name), f"_pkg_{user}") |
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.
merged into the body of NativeAppProjectModel.package_name
since this was the only usage of this function (and we needed to separate the addition of the _pkg
from the addition of the username)
def default_application(project_name: str): | ||
user = clean_identifier(get_env_username() or DEFAULT_USERNAME) | ||
return append_to_identifier(to_identifier(project_name), f"_{user}") |
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.
merged into the body of NativeAppProjectModel.app_name
since this was the only usage of this function (and we needed to separate the addition of the _
from the addition of the username)
4125642
to
07a7d3f
Compare
else: | ||
return to_identifier(default_app_package(self.project_identifier)) | ||
return concat_identifiers( | ||
[to_identifier(self.definition.package.name), suffix] |
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.
to_identifier() is probably not needed.
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.
yeah you're right, it was only needed when i was using append_to_identifier
# generate a name for the package from the project identifier and | ||
# append the resource suffix | ||
# If we don't have a resource suffix specified, use the default one | ||
return concat_identifiers( |
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.
We should just append at the end. We shouldn't replace default_resource_suffix. Also this logic will not be consistent, because for PDFV1.1 we use Pydantic defaults instead.
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.
my original intention was to skip using $USER
if $SNOWFLAKE_CLI_TEST_RESOURCE_SUFFIX
is non-empty, but I can just make it a straight append too
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.
I would vote to append it, that way we keep the rest of the logic intact, and keep this as pure suffix.
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.
sounds good, updated
# append the resource suffix. | ||
# If we don't have a resource suffix specified, use the default one | ||
return concat_identifiers( | ||
[self.project_identifier, suffix or default_resource_suffix()] |
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.
ditto
0832f02
to
74556ca
Compare
…me (#1443) Prerequisite for #1437. After discussing in-person, we decided to not overwrite the `USER` environment variable in tests and instead add a new `SNOWFLAKE_CLI_TEST_RESOURCE_SUFFIX` env var that will be appended to app package and app identifiers. In #1437, we'll use this variable to generate unique names for these resources so they don't clash during concurrent tests.
Pre-review checklist
Changes description
Prerequisite for #1437. After discussing in-person, we decided to not overwrite the
USER
environment variable in tests and instead add a newSNOWFLAKE_CLI_TEST_RESOURCE_SUFFIX
env var that will be appended to app package and app identifiers. In #1437, we'll use this variable to generate unique names for these resources so they don't clash during concurrent tests.