From 72e4916342eb764382a822c104688efe31854ca1 Mon Sep 17 00:00:00 2001 From: Teja Kommineni Date: Tue, 31 Dec 2024 10:59:04 -0800 Subject: [PATCH] fix comments --- src/snowflake/cli/_plugins/spcs/common.py | 4 ++-- .../cli/_plugins/spcs/services/commands.py | 16 +++++++++++++--- .../cli/_plugins/spcs/services/manager.py | 8 ++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/snowflake/cli/_plugins/spcs/common.py b/src/snowflake/cli/_plugins/spcs/common.py index 770803e717..6855a34419 100644 --- a/src/snowflake/cli/_plugins/spcs/common.py +++ b/src/snowflake/cli/_plugins/spcs/common.py @@ -201,7 +201,7 @@ def format_event_row(event_dict: dict) -> dict: "DATABASE NAME": database_name, "SCHEMA NAME": schema_name, "SERVICE NAME": service_name, - "INSTANCE NAME": instance_name, + "INSTANCE ID": instance_name, "CONTAINER NAME": container_name, "SEVERITY": severity, "EVENT NAME": event_name, @@ -232,7 +232,7 @@ def format_metric_row(metric_dict: dict) -> dict: "DATABASE NAME": database_name, "SCHEMA NAME": schema_name, "SERVICE NAME": service_name, - "INSTANCE NAME": instance_name, + "INSTANCE ID": instance_name, "CONTAINER NAME": container_name, "METRIC NAME": metric_name, "METRIC VALUE": metric_value, diff --git a/src/snowflake/cli/_plugins/spcs/services/commands.py b/src/snowflake/cli/_plugins/spcs/services/commands.py index 9f0c343f93..bda84bd59d 100644 --- a/src/snowflake/cli/_plugins/spcs/services/commands.py +++ b/src/snowflake/cli/_plugins/spcs/services/commands.py @@ -322,12 +322,12 @@ def events( help="Fetch events that are older than this time ago, in Snowflake interval syntax.", ), first: int = typer.Option( - default=-1, + default=None, show_default=False, help="Fetch only the first N events. Cannot be used with --last.", ), last: int = typer.Option( - default=-1, + default=None, show_default=False, help="Fetch only the last N events. Cannot be used with --first.", ), @@ -339,13 +339,16 @@ def events( ), **options, ): + """ + Retrieve platform events for a service container. + """ if FeatureFlag.ENABLE_SPCS_SERVICE_EVENTS.is_disabled(): raise FeatureNotEnabledError( "ENABLE_SPCS_SERVICE_EVENTS", "Service events collection from SPCS event table is disabled.", ) - if first >= 0 and last >= 0: + if first is not None and last is not None: raise IncompatibleParametersError(["--first", "--last"]) manager = ServiceManager() @@ -359,6 +362,10 @@ def events( last=last, show_all_columns=show_all_columns, ) + + if not events: + return MessageResult("No events found.") + return CollectionResult(events) @@ -393,6 +400,9 @@ def metrics( ), **options, ): + """ + Retrieve platform metrics for a service container. + """ if FeatureFlag.ENABLE_SPCS_SERVICE_METRICS.is_disabled(): raise FeatureNotEnabledError( "ENABLE_SPCS_SERVICE_METRICS", diff --git a/src/snowflake/cli/_plugins/spcs/services/manager.py b/src/snowflake/cli/_plugins/spcs/services/manager.py index ed53c3d87c..86d8dad9a5 100644 --- a/src/snowflake/cli/_plugins/spcs/services/manager.py +++ b/src/snowflake/cli/_plugins/spcs/services/manager.py @@ -223,8 +223,8 @@ def get_events( container_name: str, since: str | datetime | None = None, until: str | datetime | None = None, - first: int = -1, - last: int = -1, + first: Optional[int] = None, + last: Optional[int] = None, show_all_columns: bool = False, ): @@ -234,8 +234,8 @@ def get_events( ) since_clause, until_clause = build_time_clauses(since, until) - first_clause = f"limit {first}" if first >= 0 else "" - last_clause = f"limit {last}" if last >= 0 else "" + first_clause = f"limit {first}" if first is not None else "" + last_clause = f"limit {last}" if last is not None else "" query = f"""\ select *