-
Notifications
You must be signed in to change notification settings - Fork 373
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
[SDTEST-409] Add metrics management capabilities #3742
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3742 +/- ##
==========================================
+ Coverage 97.90% 97.91% +0.01%
==========================================
Files 1237 1241 +4
Lines 74200 74632 +432
Branches 3598 3605 +7
==========================================
+ Hits 72643 73074 +431
- Misses 1557 1558 +1 ☔ View full report in Codecov by Sentry. |
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.
Two quick suggestions, I plan to do a bigger pass in a few minutes :)
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.
So I kinda wonder if there's some simplifications we can to this -- e.g. I understand on purpose this is a very generic thing, but if this very generic thing will only be used in a more specific way, it may be worth the lower overhead/complexity of making it a bit less generic.
With that said, even in its current state I think it's in reasonable shape, so I'll leave it to you to decide how much to iterate on vs just going with it.
9d1b502
to
0cbef5a
Compare
expect(payload[:series]).to have(2).items | ||
|
||
tags = payload[:series].map { |s| s[:tags] }.sort | ||
expect(tags).to eq([['tag1:val1', 'tag2:val2'], ['tag1:val1', 'tag2:val3']]) |
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.
Static Analysis Violation (ruby-best-practices/percent-w)
⚪ Notice - Best Practices - View in Datadog
expect(tags).to eq([['tag1:val1', 'tag2:val2'], ['tag1:val1', 'tag2:val3']]) | |
expect(tags).to eq([['tag1:val1', 'tag2:val2'], %w[tag1:val1 tag2:val3]]) |
Consider using the %w syntax instead (read more)
The rule "Prefer %w
to the literal array syntax" is a Ruby style guideline that encourages the use of %w
notation instead of the traditional array syntax when defining arrays of strings. This rule is part of the Ruby community's efforts to promote readability and simplicity in Ruby code.
This rule is important because it helps to keep the code concise and easy to read. The %w
notation allows you to define an array of strings without having to use quotes and commas. This can make the code cleaner and easier to understand, especially when dealing with large arrays.
To follow this rule, replace the traditional array syntax with the %w
notation. For example, instead of writing ['foo', 'bar', 'baz']
, you should write %w[foo bar baz]
. This will create the same array, but in a more readable and concise way. By following this rule, you can help to make your Ruby code cleaner and easier to understand.
Leave feedback in #static-analysis
payload = event.payload | ||
|
||
expect(payload[:namespace]).to eq(namespace) | ||
expect(payload[:series]).to have(2).items |
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.
Static Analysis Violation (ruby-best-practices/hash-fetch)
⚪ Notice - Best Practices - View in Datadog
expect(payload[:series]).to have(2).items | |
expect(payload.fetch(:series)).to have(2).items |
Consider using fetch on hash key (read more)
The rule "Use fetch to check hash keys" encourages the use of the fetch
method over the direct hash access method []
for checking hash keys. This is because fetch
raises an error when the key does not exist in the hash, making the code more robust and fail-safe by preventing any unexpected behavior due to missing hash keys.
The significance of this rule lies in its ability to make the code more predictable and error-resistant. When a hash key is accessed directly using []
, and the key does not exist, Ruby returns nil
by default. This can lead to subtle bugs if the existence of the key is crucial for the subsequent code. Using fetch
, on the other hand, will raise a KeyError
if the key is not found, making it immediately clear that there's an issue with the code.
Adhering to this rule is straightforward. Instead of using direct hash access, use the fetch
method whenever you need to access a hash key. For example, instead of hash[:key]
, use hash.fetch(:key)
. This way, if the key does not exist in the hash, your code will raise an error, allowing you to catch and handle the problem early on.
Leave feedback in #static-analysis
expect(event).to be_a(Datadog::Core::Telemetry::Event::Distributions) | ||
payload = event.payload | ||
|
||
expect(payload[:namespace]).to eq(namespace) |
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.
Static Analysis Violation (ruby-best-practices/hash-fetch)
⚪ Notice - Best Practices - View in Datadog
expect(payload[:namespace]).to eq(namespace) | |
expect(payload.fetch(:namespace)).to eq(namespace) |
Consider using fetch on hash key (read more)
The rule "Use fetch to check hash keys" encourages the use of the fetch
method over the direct hash access method []
for checking hash keys. This is because fetch
raises an error when the key does not exist in the hash, making the code more robust and fail-safe by preventing any unexpected behavior due to missing hash keys.
The significance of this rule lies in its ability to make the code more predictable and error-resistant. When a hash key is accessed directly using []
, and the key does not exist, Ruby returns nil
by default. This can lead to subtle bugs if the existence of the key is crucial for the subsequent code. Using fetch
, on the other hand, will raise a KeyError
if the key is not found, making it immediately clear that there's an issue with the code.
Adhering to this rule is straightforward. Instead of using direct hash access, use the fetch
method whenever you need to access a hash key. For example, instead of hash[:key]
, use hash.fetch(:key)
. This way, if the key does not exist in the hash, your code will raise an error, allowing you to catch and handle the problem early on.
Leave feedback in #static-analysis
What does this PR do?
Adds entities to collect metrics and flush them to telemetry events:
MetricsCollection
aggregates metrics per namespace and on demand flushes them to a queue passed as a param - this is going to beTelemetry::Worker
. At most 2 events are created on flush: one for metrics, one for distributions. The methods ofMetricsCollection
are synchronized, protecting access to at most one thread at a time.MetricsManager
is a central piece of metrics aggregation: it manages collections, one per namespace. It synchronizes access to a hashmap with all collections, but allows concurrent access to a collection after it's fetched from the map. The methodflush!
locks access to the collections map and flushes each collection in order.The concerns of managing metrics and managing namespaces are separated for the following reasons:
Motivation:
Next small step to achieving metrics support for internal DD telemetry.
How to test the change?
Only unit tests for now (including several concurrency tests).