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

Append SNOWFLAKE_CLI_TEST_RESOURCE_SUFFIX value to app and package name #1443

Merged
merged 2 commits into from
Aug 14, 2024

Conversation

sfc-gh-fcampbell
Copy link
Contributor

@sfc-gh-fcampbell sfc-gh-fcampbell commented Aug 13, 2024

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually on MacOS.
  • I've confirmed that my changes are working by executing CLI's commands manually on Windows.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.

Changes description

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.

@@ -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
Copy link
Contributor Author

@sfc-gh-fcampbell sfc-gh-fcampbell Aug 13, 2024

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

@sfc-gh-fcampbell sfc-gh-fcampbell marked this pull request as ready for review August 13, 2024 19:46
@sfc-gh-fcampbell sfc-gh-fcampbell requested review from a team as code owners August 13, 2024 19:46
@sfc-gh-fcampbell sfc-gh-fcampbell marked this pull request as draft August 13, 2024 19:46
@sfc-gh-fcampbell sfc-gh-fcampbell force-pushed the frank-app-resource-name-suffixes branch 2 times, most recently from 7d4c2f3 to 4a0c31a Compare August 13, 2024 20:06
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
Copy link
Contributor

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?

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 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

Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh TIL, will update

Comment on lines 107 to 109
def resource_suffix() -> str:
"""A suffix that should be added to account-level resources."""
return os.environ.get(SNOWFLAKE_CLI_RESOURCE_SUFFIX_VAR, "")
Copy link
Contributor

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.

Copy link
Contributor Author

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

@sfc-gh-fcampbell sfc-gh-fcampbell changed the title Append SNOWFLAKE_CLI_RESOURCE_SUFFIX value to app and package name Append SNOWFLAKE_CLI_TEST_RESOURCE_SUFFIX value to app and package name Aug 14, 2024
Comment on lines 105 to 107
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}")
Copy link
Contributor Author

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)

Comment on lines 115 to 117
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}")
Copy link
Contributor Author

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)

@sfc-gh-fcampbell sfc-gh-fcampbell marked this pull request as ready for review August 14, 2024 17:01
else:
return to_identifier(default_app_package(self.project_identifier))
return concat_identifiers(
[to_identifier(self.definition.package.name), suffix]
Copy link
Contributor

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.

Copy link
Contributor Author

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

@sfc-gh-fcampbell sfc-gh-fcampbell Aug 14, 2024

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()]
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@sfc-gh-fcampbell sfc-gh-fcampbell removed the request for review from a team August 14, 2024 17:36
@sfc-gh-fcampbell sfc-gh-fcampbell enabled auto-merge (squash) August 14, 2024 17:48
@sfc-gh-fcampbell sfc-gh-fcampbell merged commit 760d5f8 into main Aug 14, 2024
16 checks passed
@sfc-gh-fcampbell sfc-gh-fcampbell deleted the frank-app-resource-name-suffixes branch August 14, 2024 17:54
sfc-gh-sichen pushed a commit that referenced this pull request Oct 17, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants