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

[core] add metrics testing #81

Merged
merged 5 commits into from
Mar 6, 2017
Merged

[core] add metrics testing #81

merged 5 commits into from
Mar 6, 2017

Conversation

palazzem
Copy link
Contributor

@palazzem palazzem commented Mar 6, 2017

What it does

  • tests set_metric for valid and invalid values
  • enforces that the value used in set_metric is stored as float
  • invalid values can be safely discarded before sending the trace

@palazzem palazzem added the core Involves Datadog core libraries label Mar 6, 2017
@palazzem palazzem modified the milestone: 0.5.0 Mar 6, 2017
@metrics[key] = value
rescue StandardError => e
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that a cast will raise an ArgumentError.
A cleaner way would be to check if value.is_a?(Integer) || value.is_a?(Float).

Copy link
Contributor Author

@palazzem palazzem Mar 6, 2017

Choose a reason for hiding this comment

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

if nil is passed it will be a TypeError:

irb(main):001:0> Float(nil)
TypeError: can't convert nil into Float
	from (irb):1:in `Float'
	from (irb):1
	from .../versions/2.3.1/bin/irb:11:in `<main>'

The reason to use the Float(value) is that a string may be converted to float, as we're doing in the Python implementation. I think it was already discussed before about why we should at least try to make it work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok then.

@palazzem palazzem requested a review from ufoot March 6, 2017 12:24
assert_equal(expected, h[:metrics])
end

def test_invalid_metrics
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@palazzem palazzem merged commit d5e06ca into master Mar 6, 2017
@palazzem palazzem deleted the palazzem/metrics-testing branch March 6, 2017 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants