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

SNOW-1846319: Add Feature Flag for log streaming #1925

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
## Fixes and improvements
* Fixed crashes with older x86_64 Intel CPUs.
* Fixed inability to add patches to lowercase quoted versions
* Added a feature flag for log streaming to support staged rollouts

# v3.2.0

Expand Down
11 changes: 10 additions & 1 deletion src/snowflake/cli/_plugins/spcs/services/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
)
sfc-gh-ashen marked this conversation as resolved.
Show resolved Hide resolved
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
from snowflake.cli.api.constants import ObjectType
from snowflake.cli.api.exceptions import IncompatibleParametersError
from snowflake.cli.api.exceptions import (
FeatureNotEnabledError,
IncompatibleParametersError,
)
from snowflake.cli.api.feature_flags import FeatureFlag
from snowflake.cli.api.identifiers import FQN
from snowflake.cli.api.output.types import (
CommandResult,
Expand Down Expand Up @@ -250,6 +254,11 @@ def logs(
Retrieves local logs from a service container.
"""
if follow:
if FeatureFlag.ENABLE_SPCS_LOG_STREAMING.is_disabled():
raise FeatureNotEnabledError(
"ENABLE_SPCS_LOG_STREAMING",
"Streaming logs from spcs containers is disabled.",
)
if num_lines != DEFAULT_NUM_LINES:
raise IncompatibleParametersError(["--follow", "--num-lines"])
if previous_logs:
Expand Down
10 changes: 10 additions & 0 deletions src/snowflake/cli/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,13 @@ def __init__(self, show_obj_query: str):
super().__init__(
f"Received multiple rows from result of SQL statement: {show_obj_query}. Usage of 'show_specific_object' may not be properly scoped."
)


class FeatureNotEnabledError(ClickException):
def __init__(self, feature_name: str, custom_message: Optional[str] = None):
base_message = f"To enable it, add '{feature_name} = true' to '[cli.features]' section of your configuration file."
if custom_message:
message = f"{custom_message} {base_message}"
else:
message = base_message
super().__init__(message)
1 change: 1 addition & 0 deletions src/snowflake/cli/api/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ class FeatureFlag(FeatureFlagMixin):
ENABLE_STREAMLIT_VERSIONED_STAGE = BooleanFlag(
"ENABLE_STREAMLIT_VERSIONED_STAGE", False
)
ENABLE_SPCS_LOG_STREAMING = BooleanFlag("ENABLE_SPCS_LOG_STREAMING", False)
50 changes: 48 additions & 2 deletions tests/spcs/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,11 @@ def test_stream_logs_with_include_timestamps_true(mock_sleep, mock_logs):


@patch("snowflake.cli._plugins.spcs.services.manager.ServiceManager.execute_query")
def test_logs_incompatible_flags(mock_execute_query, runner):
@patch(
"snowflake.cli.api.feature_flags.FeatureFlag.ENABLE_SPCS_LOG_STREAMING.is_disabled"
)
def test_logs_incompatible_flags(mock_is_disabled, mock_execute_query, runner):
mock_is_disabled.return_value = False
result = runner.invoke(
[
"spcs",
Expand All @@ -628,7 +632,13 @@ def test_logs_incompatible_flags(mock_execute_query, runner):


@patch("snowflake.cli._plugins.spcs.services.manager.ServiceManager.execute_query")
def test_logs_incompatible_flags_follow_previous_logs(mock_execute_query, runner):
@patch(
"snowflake.cli.api.feature_flags.FeatureFlag.ENABLE_SPCS_LOG_STREAMING.is_disabled"
)
def test_logs_incompatible_flags_follow_previous_logs(
mock_is_disabled, mock_execute_query, runner
):
mock_is_disabled.return_value = False
result = runner.invoke(
[
"spcs",
Expand All @@ -653,6 +663,42 @@ def test_logs_incompatible_flags_follow_previous_logs(mock_execute_query, runner
)


@patch(
"snowflake.cli.api.feature_flags.FeatureFlag.ENABLE_SPCS_LOG_STREAMING.is_disabled"
)
def test_logs_streaming_disabled(mock_is_disabled, runner):
mock_is_disabled.return_value = True
result = runner.invoke(
[
"spcs",
"service",
"logs",
"test_service",
"--container-name",
"test_container",
"--instance-id",
"0",
"--follow",
"--num-lines",
"100",
]
)
assert (
result.exit_code != 0
), "Expected a non-zero exit code due to feature flag disabled"

expected_output = (
"+- Error ----------------------------------------------------------------------+\n"
"| Streaming logs from spcs containers is disabled. To enable it, add |\n"
"| 'ENABLE_SPCS_LOG_STREAMING = true' to '[cli.features]' section of your |\n"
"| configuration file. |\n"
"+------------------------------------------------------------------------------+\n"
)
assert (
result.output == expected_output
), f"Expected formatted output not found: {result.output}"


def test_read_yaml(other_directory):
tmp_dir = Path(other_directory)
spec_path = tmp_dir / "spec.yml"
Expand Down
Loading