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

Update Statsd tag serializer to allow falsy values #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joseph-hughes
Copy link

Problem

If we provide a tag which has a boolean value, we are unable to properly track the false case, since the "true" string appears with the tag name, but the "false" string does not show up. This is because of this logic, which checks for tag value presence:

def to_tags_list(tags)
case tags
when Hash
tags.map do |name, value|
if value
escape_tag_content("#{name}:#{value}")
else
escape_tag_content(name)
end

true is evaluated to present, so we would add that tag name and value; however, false is evaluated to not present, so we would only add that tag name (not the value).

Solution

First convert the tag value to a string before checking for presence. This does result in other values being deemed "present" now which were not previously though, such as [] and {}. Is this a problem though?

@joseph-hughes joseph-hughes requested a review from a team as a code owner February 5, 2024 15:41
@joseph-hughes joseph-hughes force-pushed the joseph-hughes-allow-false-as-tag-value branch from a7c8e5e to ad053c0 Compare December 12, 2024 19:59
This instead now ensures that we skip including the tag value only if:
- it is equal to 'nil'
- it when stringified is equal to 'nil'

The reasoning for this was to make it so falsy values (e.g. false) will now be
included in our tag content, instead of skipped.
@joseph-hughes joseph-hughes force-pushed the joseph-hughes-allow-false-as-tag-value branch from ad053c0 to 0c67365 Compare December 12, 2024 20:28
@@ -75,7 +75,7 @@ def to_tags_list(tags)
def escape_tag_content(tag)
tag = tag.to_s
return tag unless tag.include?('|')
tag.delete('|,')
tag.delete('|,')
Copy link
Author

Choose a reason for hiding this comment

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

Looks like my editor chose to remove some whitespace here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant