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

Enable Event Sharing V2 in SnowCLI #1823

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-melnacouzi
Copy link
Contributor

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

Enable Event Sharing V2 in SnowCLI.
Example:

  app:
    type: application
    from:
      target: pkg
    telemetry:
      authorize_event_sharing: true
      optional_shared_events:
        - DEBUG_LOGS
        - ERRORS_AND_WARNINGS

Above example authorize telemetry to be shared to provider. In addition to required telemetry by the provider, consumer can specify a list of extra events to share with the provider.
There are 2 flags introduced to control the BCR in the backend. One to enable telemetry on consumer for same-account applications, and another to enforce that the consumer authorize event sharing when the provider has mandatory events.

  • Added unit tests.
  • Tested manually - optional events not recognized - reached out to corresponding team.
  • Integ tests will be added as a follow up PR.


@field_validator("optional_shared_events")
@classmethod
def transform_artifacts(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def transform_artifacts(
def validate_optional_shared_events(

?

Comment on lines +9 to +13
authorize_event_sharing: Optional[bool] = Field(
title="Whether to authorize Snowflake to share application usage data with application package provider. This automatically enables the sharing of required telemetry events.",
default=None,
)
optional_shared_events: Optional[List[str]] = Field(
Copy link
Contributor

Choose a reason for hiding this comment

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

do these need to be optional to have a default? do we handle these fields differently if they're None vs False/[]?

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 am not sure if optional [] as default will have any side effect (I know it's not recommended in function params)


# make sure that each event is made of letters and underscores:
for event in original_shared_events:
if not event.isalpha() and not event.replace("_", "").isalpha():
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if not event.isalpha() and not event.replace("_", "").isalpha():
if not re.fullmatch(r"[a-zA-Z_]", event):

?

Copy link
Contributor

Choose a reason for hiding this comment

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

if you don't want the regex, then you only need

Suggested change
if not event.isalpha() and not event.replace("_", "").isalpha():
if not event.replace("_", "").isalpha():

Comment on lines +457 to +459
workspace_ctx = self._workspace_ctx
console = workspace_ctx.console
project_root = workspace_ctx.project_root
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
workspace_ctx = self._workspace_ctx
console = workspace_ctx.console
project_root = workspace_ctx.project_root
console = self._workspace_ctx.console

is_dev_mode = install_method.is_dev_mode

mandatory_events_found = (
len(find_mandatory_events_in_manifest_file(project_root / deploy_root)) > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
len(find_mandatory_events_in_manifest_file(project_root / deploy_root)) > 0
len(find_mandatory_events_in_manifest_file(self.project_root / deploy_root)) > 0

manifest_contents=manifest_contents,
authorize_event_sharing=authorize_event_sharing,
)
assert not mock_diff_result.has_changes()
Copy link
Contributor

Choose a reason for hiding this comment

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

mock_diff_result is never passed anywhere, how can this assertion fail? (also found in other tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea it doesn't make sense - i'll remove it from this new file at least.

Comment on lines +64 to +66
allow_always_policy = AllowAlwaysPolicy()
ask_always_policy = AskAlwaysPolicy()
deny_always_policy = DenyAlwaysPolicy()
Copy link
Contributor

Choose a reason for hiding this comment

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

these are unused in this file. your _create_or_upgrade_app takes in a policy param, did you mean to use them there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no it's a left-over copy from another file.

Comment on lines +632 to +638
mock_console.warning.assert_has_calls(
[
mock.call(
"WARNING: Mandatory events are present in the manifest file, but event sharing is not authorized in the application telemetry field. This will soon be required to set in order to deploy applications."
)
]
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
mock_console.warning.assert_has_calls(
[
mock.call(
"WARNING: Mandatory events are present in the manifest file, but event sharing is not authorized in the application telemetry field. This will soon be required to set in order to deploy applications."
)
]
)
mock_console.warning.assert_called_with(
"WARNING: Mandatory events are present in the manifest file, but event sharing is not authorized in the application telemetry field. This will soon be required to set in order to deploy applications."
)

)


def setup_project_file(current_working_directory: str, pdf=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

let's use project factories in here

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 would like to keep this for a separate PR if possible.

Comment on lines +326 to +327
print(mock_execute.mock_calls)
raise e
Copy link
Contributor

Choose a reason for hiding this comment

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

?

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