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

Add Asynchronous Metric Instruments SDK #191

Merged
merged 10 commits into from
Aug 5, 2020

Conversation

ankit-bhargava
Copy link
Contributor

@ankit-bhargava ankit-bhargava commented Jul 20, 2020

This PR implements the asynchronous instrument classes described in the Metric Instruments API (PR #161). These classes are capable of actually collecting telemetry data unlike no-op implementations included with the API. Instruments employ Aggregators (pending approval in PR #178 and PR #181 ) to combine the updates they receive into meaningful values.

A test suite which validates each instrument’s ability to record values in single-threaded and concurrent scenarios is included. Functions necessary for the metrics pipeline as a whole such as reference counting are tested as well.

This PR in conjunction with (PR #179) provides support for all metric instruments listed in the spec. This PR will not compile without all the other PRs mentioned in this description.

Note: We templated instruments to support a wider array of scalar types. Templating prevents us from using out of line declarations as we normally would. As a result, we left all implementation code in the header file. If there are any suggestions to remedy this we will gladly make the change. Code for the base classes which asynchronous instruments inherit from is in PR #161.

@codecov
Copy link

codecov bot commented Jul 20, 2020

Codecov Report

Merging #191 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #191   +/-   ##
=======================================
  Coverage   93.63%   93.63%           
=======================================
  Files         134      134           
  Lines        5345     5345           
=======================================
  Hits         5005     5005           
  Misses        340      340           

@ankit-bhargava ankit-bhargava marked this pull request as ready for review July 27, 2020 02:05
@ankit-bhargava ankit-bhargava requested a review from a team July 27, 2020 02:05
}

/*
* Activate the intsrument's callback function to record a measurement. This
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Activate the intsrument's callback function to record a measurement. This
* Activate the instrument's callback function to record a measurement. This

#include <map>
#include <sstream>
#include <vector>
#include <memory>
Copy link
Member

Choose a reason for hiding this comment

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

Minor: would you sort includes alphabetically unless there is a good reason not to do so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The format tools reorder the includes but I sorted them where I could.

}

// Public mapping from labels (stored as strings) to their respective aggregators
std::unordered_map<std::string, std::shared_ptr<Aggregator<T>>> boundAggregators_;
Copy link
Member

Choose a reason for hiding this comment

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

There seems to be indentation issue.

else
{
if (value < 0){
throw std::invalid_argument("Counter instrument updates must be non-negative.");
Copy link
Member

Choose a reason for hiding this comment

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

@pyohannes do you think we should check __EXCEPTIONS and call std::terminate?
I think we shouldn't throw if exception is disabled, however we don't want to kill the process as this is not a critical failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a check and call to terminate :)

return ret;
}

// Public mapping from labels (stored as strings) to their respective aggregators
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be another indentation issue, would you rebase and check if the formatter CI would pass?

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

Please rebase, resolve conflicts and make sure all the GitHub Actions CI would pass.

@ankit-bhargava ankit-bhargava force-pushed the metrics-sdk-asyncinstr branch from d608f83 to 6e4cb4d Compare August 4, 2020 14:04
@ankit-bhargava
Copy link
Contributor Author

ankit-bhargava commented Aug 4, 2020

@reyang Thanks for the review! I rebased and addressed your comments. Additionally, we discovered a bug related to the way we were dealing with concurrency in our synchronous instruments. I added fixes in this PR out of convenience (you can see the changes in the sync_instruments.h file) but I can remove them and open a new PR if you would prefer that.

@ankit-bhargava ankit-bhargava requested a review from reyang August 4, 2020 19:27
@ankit-bhargava ankit-bhargava force-pushed the metrics-sdk-asyncinstr branch from e984a9c to 7b76bc4 Compare August 4, 2020 19:28
@ankit-bhargava
Copy link
Contributor Author

@reyang This should be ready to merge unless there are any further concerns

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM.

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.

2 participants