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

Question about the new Metrics stats interface #11349

Closed
freak82 opened this issue May 14, 2024 · 3 comments
Closed

Question about the new Metrics stats interface #11349

freak82 opened this issue May 14, 2024 · 3 comments
Assignees
Labels

Comments

@freak82
Copy link
Contributor

freak82 commented May 14, 2024

Hi there,

I'm developing an ATS plugin for our company and I need few statistic counters in the plugin.
According to this page, I should use the new APIs from Metrics.h for this purpose. Correct me if I misunderstood the Note.

I glanced over the functionality in the Metrics.h and checked its usage inside the ATS core. I think, I understood how to use it.

// define the counter
ts::Metrics::Counter::AtomicType *counter_name;
...
// create/register the counter
counter_name = ts::Metrics::Counter::createPtr("the-name-of-the-counter");
...
// use the counter
ts::Metrics::Counter::increment(counter_name);

However, I'm wondering about the future binary compatibility.
So far, all of the other APIs are C functions and opaque types/pointers to hide the actual implementation.
However, this new functionality exposes lots of implementation details in the header file along with the Metrics data member.
Now if I use this functionality and for example:

  • my plugin is built against ATS version 10
  • ATS version 12 introduces some changes in the Metrics functionality which change the implementation of some of the inline functions and/or the data members of Metrics.
    It seems to me, that In the above scenario the plugin may experience some UB (Undefined Behavior) effects if run along ATS version 12.

Did I misunderstood something?
Or there is no guarantee for binary compatibility between the ATS versions and I should always rebuild the plugins against the currently used ATS version?

@bryancall
Copy link
Contributor

bryancall commented May 20, 2024

We require rebuilding plugins for new major version releases of ATS.

@zwoop
Copy link
Contributor

zwoop commented May 20, 2024

The common use case, using these APIs rather than the old APIs in ts.h (which also uses the new Metrics under the hood) would be

auto  id1  = ts::Metrics::Counter::create(name);
auto  id2  = ts::Metrics::Gauge::create(name);

If you want the pointer, you can get it from the id, e.g.

auto ptr1 = ts::Metrics::Counter::lookup(id1, nullptr);
auto ptr2 = ts::Metrics::Gauge::lookup(id2, nullptr);

or, you can also create them directly with createPtr() as above, e.g.

auto  ptr1 = ts::Metrics::Counter::createPtr(name);
auto  ptr2 = ts::Metrics::Gauge::createPtr(name);

Note that the lookup() functionalities requires locking around the lookup tables etc., so are not a good idea to do in critical code. The ID can be used to access the metric directly though, without locks, such as

static auto &instance = ts::Metrics::instance();

instance[id1].increment();
instance[id2].decrement(5);

@freak82
Copy link
Contributor Author

freak82 commented May 21, 2024

Thank you all for the clarifications.

@freak82 freak82 closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants