Fix issue when metrics are not available#1207
Merged
codeboten merged 3 commits intoopen-telemetry:masterfrom Oct 6, 2020
Merged
Fix issue when metrics are not available#1207codeboten merged 3 commits intoopen-telemetry:masterfrom
codeboten merged 3 commits intoopen-telemetry:masterfrom
Conversation
added 2 commits
October 5, 2020 20:55
Not all configured metrics are available on all operating systems, added a hasattr call before calling the observer.
owais
approved these changes
Oct 6, 2020
| observer.observe( | ||
| getattr(times, metric), self._system_cpu_time_labels | ||
| ) | ||
| if hasattr(times, metric): |
Contributor
There was a problem hiding this comment.
How about getattr here followed by a check for None? Would save one attribute lookup if/when on hotpath.
Contributor
Author
There was a problem hiding this comment.
This would be a good optimization, I thought about it but then I remembered the default interval for this instrumentation was to collect metrics every 30 seconds. Can definitely be improved when it becomes an issue
lzchen
approved these changes
Oct 6, 2020
Contributor
lzchen
left a comment
There was a problem hiding this comment.
Curious which operating system did not have these metrics?
Contributor
Author
The bug has more details regarding which metrics, but MacOS had a few metrics unavailable, so I just added a check for hasattr everywhere. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Not all configured metrics are available on all operating systems, added a hasattr call before calling the observer.
Fixes #1206
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Ran the instrumentation manually again after the change, error messages were gone.
Checklist: