8000 analytics for non-prefixed env var forwarding in CLI by alexrashed · Pull Request #11946 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

analytics for non-prefixed env var forwarding in CLI #11946

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

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 22 additions & 9 deletions localstack-core/localstack/utils/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ def config_env_vars(cfg: ContainerConfiguration):
if config.LOADED_PROFILES:
load_environment(profiles=",".join(config.LOADED_PROFILES), env=profile_env)

non_prefixed_env_vars = []
for env_var in config.CONFIG_ENV_VARS:
value = os.environ.get(env_var, None)
if value is not None:
Expand All @@ -521,17 +522,29 @@ def config_env_vars(cfg: ContainerConfiguration):
and not env_var.startswith("LOCALSTACK_")
and env_var not in profile_env
):
# Show a warning here in case we are directly forwarding an environment variable from
# the system env to the container which has not been prefixed with LOCALSTACK_.
# Suppress the warning for the "CI" env var.
# Suppress the warning if the env var was set from the profile.
LOG.warning(
"Non-prefixed environment variable %(env_var)s is forwarded to the LocalStack container! "
"Please use `LOCALSTACK_%(env_var)s` instead of %(env_var)s to explicitly mark this environment variable to be forwarded form the CLI to the LocalStack Runtime.",
{"env_var": env_var},
)
# Collect all env vars that are directly forwarded from the system env
# to the container which has not been prefixed with LOCALSTACK_ here.
# Suppress the "CI" env var.
# Suppress if the env var was set from the profile.
non_prefixed_env_vars.append(env_var)
cfg.env_vars[env_var] = value

# collectively log deprecation warnings for non-prefixed sys env vars
if non_prefixed_env_vars:
from localstack.utils.analytics import log

for non_prefixed_env_var in non_prefixed_env_vars:
# Show a deprecation warning for each individual env var collected above
LOG.warning(
"Non-prefixed environment variable %(env_var)s is forwarded to the LocalStack container! "
"Please use `LOCALSTACK_%(env_var)s` instead of %(env_var)s to explicitly mark this environment variable to be forwarded form the CLI to the LocalStack Runtime.",
{"env_var": non_prefixed_env_var},
)

log.event(
event="non_prefixed_cli_env_vars", payload={"env_vars": non_prefixed_env_vars}
)
Comment on lines +544 to +546
Copy link
Member

Choose a reason for hiding this comment

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

thought: somewhat unrelated but IMO we should start also writing tests for the analytics events to make sure they work as expected 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Definitely, I thought about adding this, but then I postponed this to a follow-up to introduce unit tests for multiple log events with some utilities around it (mocking / asserting).


@staticmethod
def random_gateway_port(cfg: ContainerConfiguration):
"&qu A2AD ot;"Gets a random port on the host and maps it to the default edge port 4566."""
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap/test_container_configurators.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_container_configurator_no_deprecation_warning_on_prefix(
assert "LOCALSTACK_SERVICES" in container.config.env_vars


def test_container_configurator_no_deprecation_warning_for_CI_env_var(
def test_container_configurator_no_deprecation_warning_for_ci_env_var(
container_factory, monkeypatch, caplog
):
# set the "CI" env var indicating that we are running in a CI environment
Expand Down
Loading
0