Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-tkommineni committed Dec 31, 2024
1 parent 77d521c commit 72e4916
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/snowflake/cli/_plugins/spcs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 13 additions & 3 deletions src/snowflake/cli/_plugins/spcs/services/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
),
Expand All @@ -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()
Expand All @@ -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)


Expand Down Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/snowflake/cli/_plugins/spcs/services/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):

Expand All @@ -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 *
Expand Down

0 comments on commit 72e4916

Please sign in to comment.