Skip to content

Fix limit env vars unset/unlimited values #2054

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 7 commits into from
Aug 24, 2021
Merged

Conversation

owais
Copy link
Contributor

@owais owais commented Aug 18, 2021

Description

Limit env vars set to an empty value will be treated as unset/unlimited.

Fixes #2052

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Manually tests
  • Updated exsiting tests

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@owais owais requested review from a team, ocelotl and srikanthccv and removed request for a team August 18, 2021 21:36
@owais
Copy link
Contributor Author

owais commented Aug 18, 2021

Builds on top of #2044. Should be rebased and reviewed after 2044 is merged.

@owais owais changed the title Fix 2052 Fix limit env vars unset/unlimited values Aug 18, 2021
Comment on lines 46 to 47
- Its length is greater than the maximum allowed length.
- It needs to be encoded/decoded e.g, bytes to strings.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Looks like no cleaning is needed if value is not string or bytes, if this is checked first then all the remaining execution in this function can be saved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We also need to clean the string/byte value in sequences (and validate them) so can't bail out

if key is None or key == "":
_logger.warning("invalid key `%s` (empty or null)", key)
return None

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if isinstance(value, (int, float, bool)):
return True

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in #2057

if isinstance(value, bytes):
try:
value = value.decode()
except ValueError:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
except ValueError:
except UnicodeDecodeError:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ocelotl ocelotl added the Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary label Aug 19, 2021
@@ -67,7 +67,7 @@
_DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT = 128


_ENV_VALUE_UNSET = "unset"
Copy link
Member

Choose a reason for hiding this comment

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

didn't we use unset so users should define it explicitly and can avoid the sudden surprise when not setting env either by no knowledge/ignorance considered as unlimited?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We did but spec recommends using empty value as unlimited.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can try to convince others and update spec to accept "unset" as the value but for now I think we should update our SDK to make sure it is spec compatible.

@@ -609,15 +609,18 @@ def __repr__(self):
def _from_env_if_absent(
cls, value: Optional[int], env_var: str, default: Optional[int] = None
) -> Optional[int]:
if value is cls.UNSET:
if value == cls.UNSET:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm not fully understanding this scenario. When will value ever be "unset"? Isn't value supposed to be an int?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The API usage looks like the following in order to not set a limit:

SpanLimits(max_attributes=SpanLimits.UNSET)

SpanLimits.UNSET is a symbol that users can pass as a limit to set the limit to infinity. We can freely change its internal value to anything without breaking any contracts.

The reason why I used "unset" was that I thought -1 might be confusing as the spec disallows it for env vars. Internally we can still use -1 as the symbol value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it back to -1 as this is probably causing more confusion and does not respect the function contract. I wonder why mypy didn't catch it.

Co-authored-by: Leighton Chen <[email protected]>
@owais owais merged commit b5704d5 into open-telemetry:main Aug 24, 2021
@owais owais deleted the fix-2052 branch August 24, 2021 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update limits implementation to correctly deal with empty and negative values.
4 participants