-
Notifications
You must be signed in to change notification settings - Fork 272
fix: add test case for metric_store and metric_view #1894
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
base: main
Are you sure you want to change the base?
Conversation
def now_in_nano | ||
(Time.now.to_r * 1_000_000_000).to_i | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a helper for this now in the common gem:
opentelemetry-ruby/common/lib/opentelemetry/common/utilities.rb
Lines 45 to 51 in 3d82438
# Converts the provided timestamp to nanosecond integer | |
# | |
# @param timestamp [Time] the timestamp to convert, defaults to Time.now | |
# @return [Integer] | |
def time_in_nanoseconds(timestamp = Time.now) | |
(timestamp.to_r * 1_000_000_000).to_i | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
metrics_sdk/lib/opentelemetry/sdk/metrics/state/asynchronous_metric_stream.rb
Show resolved
Hide resolved
|
||
metric_data = nil | ||
threads = Array.new(5) do | ||
# Thread.new { thread_stream.invoke_callback(timeout, attributes) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
describe '#now_in_nano' do | ||
it 'returns current time in nanoseconds with increasing values' do | ||
nano_time = async_metric_stream.now_in_nano | ||
_(nano_time).must_be_instance_of(Integer) | ||
_(nano_time).must_be :>, 0 | ||
|
||
# Should be a reasonable timestamp (not too old, not in future) | ||
current_time_nano = (Time.now.to_r * 1_000_000_000).to_i | ||
_(nano_time).must_be_close_to(current_time_nano, 1_000_000_000) # Within 1 second | ||
|
||
# Test successive calls return increasing values | ||
sleep(0.001) # Small delay | ||
time2 = async_metric_stream.now_in_nano | ||
_(time2).must_be :>, nano_time | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you swap to using the utils method, can take these out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
metrics_sdk/lib/opentelemetry/sdk/metrics/state/asynchronous_metric_stream.rb
Show resolved
Hide resolved
# this test case is unstable as it involve thread in minitest | ||
skip if snapshot.size != 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How often do you think this is skipped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed these unstable thread-related test for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for these tests and the fix!
Closes #1890
Description
Found a couple of issues while developing the test case:
Timeout.timeout
with thread for executing the callback.Each metric_stream should be bound to its own instrument. While most functionality is tested through instruments, here we focus on fundamental correctness, which will be important when views and exemplars are updated.