-
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
instrument NADE commands using metric spans #1844
Changes from 6 commits
a2a833e
46a3028
cf3a339
d26af10
6b3d12e
ca990d4
4edd8b2
f99a275
db00d94
84209f0
506bae2
7846c43
ec44e0c
d5e2376
15955f7
1b1d99a
a32a21b
b77d135
cef9f19
8a45192
bf8cf5b
ae43f25
93e5dc9
bfc4f21
5e1e38c
348aac2
c618da6
2fbdcb6
05d81a9
e96a0ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
from snowflake.cli._plugins.nativeapp.sf_facade import get_snowflake_facade | ||
from snowflake.cli._plugins.nativeapp.utils import needs_confirmation | ||
from snowflake.cli._plugins.workspace.context import ActionContext | ||
from snowflake.cli.api.cli_global_context import start_cli_metrics_span | ||
from snowflake.cli.api.entities.common import EntityBase, get_sql_executor | ||
from snowflake.cli.api.entities.utils import ( | ||
drop_generic_object, | ||
|
@@ -420,6 +421,7 @@ def get_objects_owned_by_application(self) -> List[ApplicationOwnedObject]: | |
).fetchall() | ||
return [{"name": row[1], "type": row[2]} for row in results] | ||
|
||
@start_cli_metrics_span("create_or_upgrade_app") | ||
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. spans shouldn't be implementation-specific, but rather represent a logic step in the overall operation being performed. 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. Adjusted the names and locations of all the spans to better encapsulate this, let me know if they work for you! |
||
def create_or_upgrade_app( | ||
self, | ||
package: ApplicationPackageEntity, | ||
|
@@ -513,10 +515,10 @@ def create_or_upgrade_app( | |
create_cursor = sql_executor.execute_query( | ||
dedent( | ||
f"""\ | ||
create application {self.name} | ||
from application package {package.name} {using_clause} {debug_mode_clause} | ||
comment = {SPECIAL_COMMENT} | ||
""" | ||
create application {self.name} | ||
from application package {package.name} {using_clause} {debug_mode_clause} | ||
comment = {SPECIAL_COMMENT} | ||
""" | ||
), | ||
) | ||
print_messages(console, create_cursor) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
from snowflake.cli._plugins.stage.diff import DiffResult | ||
from snowflake.cli._plugins.stage.manager import StageManager | ||
from snowflake.cli._plugins.workspace.context import ActionContext | ||
from snowflake.cli.api.cli_global_context import start_cli_metrics_span | ||
from snowflake.cli.api.entities.common import EntityBase, get_sql_executor | ||
from snowflake.cli.api.entities.utils import ( | ||
drop_generic_object, | ||
|
@@ -915,6 +916,7 @@ def validate_setup_script( | |
if validation_result["status"] == "FAIL": | ||
raise SetupScriptFailedValidation() | ||
|
||
@start_cli_metrics_span("get_validation_result") | ||
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. ditto, let's not name things according to the implementation. That can change over time. |
||
def get_validation_result( | ||
self, use_scratch_stage: bool, interactive: bool, force: bool | ||
): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from contextlib import contextmanager | ||
from contextvars import ContextVar | ||
from dataclasses import dataclass, field, replace | ||
from functools import wraps | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING, Iterator | ||
|
||
|
@@ -157,7 +158,7 @@ def enable_tracebacks(self) -> bool: | |
return self._manager.enable_tracebacks | ||
|
||
@property | ||
def metrics(self): | ||
def metrics(self) -> CLIMetrics: | ||
return self._manager.metrics | ||
|
||
@property | ||
|
@@ -213,6 +214,26 @@ def get_cli_context() -> _CliGlobalContextAccess: | |
return _CliGlobalContextAccess(get_cli_context_manager()) | ||
|
||
|
||
def start_cli_metrics_span(span_name: str): | ||
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. I don't think "start" makes sense here, since this both starts and stops the span at the appropriate time. Let's workshop the name of this + the 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. +1, I feel @span would suffice 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. Changed both the method name and the decorator name to just |
||
""" | ||
Decorator to start a command metrics span that encompasses a whole function | ||
|
||
Must be used instead of directly calling @get_cli_context().metrics.start_span(span_name) | ||
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. it's |
||
as a decorator to ensure that the cli context is grabbed at run time instead of at | ||
module load time, which would not reflect forking | ||
""" | ||
|
||
def decorator(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
with get_cli_context().metrics.start_span(span_name): | ||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorator | ||
|
||
|
||
@contextmanager | ||
def fork_cli_context( | ||
connection_overrides: dict | None = None, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ def phase( | |
self, | ||
enter_message: str, | ||
exit_message: Optional[str] = None, | ||
span_name: Optional[str] = None, | ||
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. not sure if this is truly needed, since we can use multiple context managers on the same line. Thoughts? 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. I forgot about that feature, I adjusted these instances, thanks for the reminder |
||
) -> Iterator[Callable[[str], None]]: | ||
"""A context manager for organising steps into logical group.""" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,12 @@ | |
|
||
from __future__ import annotations | ||
|
||
from contextlib import contextmanager | ||
from contextlib import contextmanager, nullcontext | ||
from typing import Optional | ||
|
||
from rich.style import Style | ||
from rich.text import Text | ||
from snowflake.cli.api.cli_global_context import get_cli_context | ||
from snowflake.cli.api.console.abc import AbstractConsole | ||
from snowflake.cli.api.console.enum import Output | ||
|
||
|
@@ -68,7 +69,12 @@ def _format_message(self, message: str, output: Output) -> Text: | |
return text | ||
|
||
@contextmanager | ||
def phase(self, enter_message: str, exit_message: Optional[str] = None): | ||
def phase( | ||
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. you're no longer touching this, I'd revert the file entirely |
||
self, | ||
enter_message: str, | ||
exit_message: Optional[str] = None, | ||
span_name: Optional[str] = None, | ||
): | ||
"""A context manager for organising steps into logical group.""" | ||
if self.in_phase: | ||
raise CliConsoleNestingProhibitedError("Only one phase allowed at a time.") | ||
|
@@ -81,7 +87,10 @@ def phase(self, enter_message: str, exit_message: Optional[str] = None): | |
self._in_phase = True | ||
|
||
try: | ||
yield self.step | ||
with get_cli_context().metrics.start_span( | ||
span_name | ||
) if span_name else nullcontext(): | ||
yield self.step | ||
finally: | ||
self._in_phase = False | ||
if exit_message: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
to_stage_path, | ||
) | ||
from snowflake.cli._plugins.stage.utils import print_diff_to_console | ||
from snowflake.cli.api.cli_global_context import get_cli_context | ||
from snowflake.cli.api.cli_global_context import get_cli_context, start_cli_metrics_span | ||
from snowflake.cli.api.console.abc import AbstractConsole | ||
from snowflake.cli.api.entities.common import get_sql_executor | ||
from snowflake.cli.api.errno import ( | ||
|
@@ -76,6 +76,7 @@ def _get_stage_paths_to_sync( | |
return stage_paths | ||
|
||
|
||
@start_cli_metrics_span("sync_deploy_root_with_stage") | ||
def sync_deploy_root_with_stage( | ||
console: AbstractConsole, | ||
deploy_root: Path, | ||
|
@@ -219,7 +220,10 @@ def execute_post_deploy_hooks( | |
|
||
get_cli_context().metrics.set_counter(CLICounterField.POST_DEPLOY_SCRIPTS, 1) | ||
|
||
with console.phase(f"Executing {deployed_object_type} post-deploy actions"): | ||
with console.phase( | ||
f"Executing {deployed_object_type} post-deploy actions", | ||
span_name="execute_post_deploy_hooks", | ||
): | ||
sql_scripts_paths = [] | ||
display_paths = [] | ||
for hook in post_deploy_hooks: | ||
|
@@ -304,6 +308,7 @@ def validation_item_to_str(item: dict[str, str | int]): | |
return s | ||
|
||
|
||
@start_cli_metrics_span("drop_generic_object") | ||
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. same here |
||
def drop_generic_object( | ||
console: AbstractConsole, | ||
object_type: str, | ||
|
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.
there's no compilation happening. How about simply "artifact_processors"? We should probably also have individual processors as sub-spans.