Skip to content

Conversation

ViBiOh
Copy link
Contributor

@ViBiOh ViBiOh commented Oct 3, 2025

What does this PR do?

Refactor the load of the environment variables related to tags enrichment.

Motivation

Reduce number of calls to os.environ and centralize the value into the settings.

Testing Guidelines

Additional Notes

Types of changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)
  • This PR passes the unit tests
  • This PR passes the installation tests (ask a Datadog member to run the tests)

@ViBiOh ViBiOh requested a review from a team as a code owner October 3, 2025 08:55
@github-actions github-actions bot added the aws label Oct 3, 2025
@ViBiOh ViBiOh force-pushed the vibioh/refactor_tags_envvar branch from d2f4c3d to 8a29c3c Compare October 3, 2025 12:44
Signed-off-by: Vincent Boutour <vincent.boutour@datadoghq.com>
@ViBiOh ViBiOh force-pushed the vibioh/refactor_tags_envvar branch from 8a29c3c to 1eb5050 Compare October 3, 2025 12:53
)


def get_fetch_s3_tags():
Copy link
Contributor

Choose a reason for hiding this comment

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

imo, we could just import the setting directly in the cache function an use it. not a strict opinion, but it will be consistent with the other settings consts that we import.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was my first attempt, but with mocking involved, I needed to reload settings, then lambda_cache (for example), but lambda_cache was already patched with mocks and tests were deeply broken.

Using a getter allows me to only reload settings, and the rest of components will dynamically benefit from it.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I added this comment regarding consistency in settings vars imports. Otherwise, it's not really changing anything.

Regarding the patching, I think it's a workaround here to do getters. However, I think we could use a code refactor for reworking patching.

We can check that later


@patch("caching.base_tags_cache.send_forwarder_internal_metrics")
@patch("caching.lambda_cache.send_forwarder_internal_metrics")
@patch.dict(os.environ, {"DD_FETCH_LAMBDA_TAGS": "true"})
Copy link
Contributor

Choose a reason for hiding this comment

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

we can use something like

with patch.dict(os.environ, {"MY_ENV_VAR": "test_value"}):

to have local env changes, I think it would also allow not to reload settings module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used here for example but it doesn't prevent the use of reload. If I remove it, the test is broken.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, at least the local env change part still holds if we're sharing / re-setting the same env vars amongst tests

Copy link
Contributor

@ge0Aja ge0Aja left a comment

Choose a reason for hiding this comment

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

lgtm, a couple of minor comments

@ViBiOh ViBiOh merged commit 83bc051 into master Oct 6, 2025
11 checks passed
@ViBiOh ViBiOh deleted the vibioh/refactor_tags_envvar branch October 6, 2025 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants