-
Notifications
You must be signed in to change notification settings - Fork 438
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
[Metrics] Switch to explicit 64 bit integers #1686
Changes from 10 commits
215a043
e3283a8
222f6af
f6654ac
4f6049c
ae642d9
1f467f6
f5237e3
d42179b
1e1ee23
0eb1465
36b80e4
10ae974
2c0189f
5674bf7
3b84aa8
ff1229d
40f1fb8
23ea59c
22cac63
5ea4784
e5c2ea6
b7c50ef
7bf9130
cf7f873
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ class Meter | |
* @return a shared pointer to the created Counter. | ||
*/ | ||
|
||
virtual nostd::shared_ptr<Counter<long>> CreateLongCounter( | ||
virtual nostd::shared_ptr<Counter<int64_t>> CreateInt64Counter( | ||
nostd::string_view name, | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept = 0; | ||
|
@@ -72,7 +72,7 @@ class Meter | |
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. | ||
* @return a shared pointer to the created Histogram. | ||
*/ | ||
virtual nostd::shared_ptr<Histogram<long>> CreateLongHistogram( | ||
virtual nostd::shared_ptr<Histogram<int64_t>> CreateLongHistogram( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly rename to CreateUInt64Histogram, and use uint64_t, to discuss |
||
nostd::string_view name, | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept = 0; | ||
|
@@ -109,7 +109,7 @@ class Meter | |
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. | ||
* @return a shared pointer to the created UpDownCounter. | ||
*/ | ||
virtual nostd::shared_ptr<UpDownCounter<long>> CreateLongUpDownCounter( | ||
virtual nostd::shared_ptr<UpDownCounter<int64_t>> CreateLongUpDownCounter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly rename to CreateInt64UpDownCounter, to discuss There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, renamed all the functions as suggested here #1686 (comment) |
||
nostd::string_view name, | ||
nostd::string_view description = "", | ||
nostd::string_view unit = "") noexcept = 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,42 +9,42 @@ | |
|
||
TEST(Counter, Add) | ||
{ | ||
std::shared_ptr<opentelemetry::metrics::Counter<long>> counter{ | ||
new opentelemetry::metrics::NoopCounter<long>("test", "none", "unitless")}; | ||
std::shared_ptr<opentelemetry::metrics::Counter<int64_t>> counter{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uint64_t, as counter is always non-negative value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, fixed |
||
new opentelemetry::metrics::NoopCounter<int64_t>("test", "none", "unitless")}; | ||
|
||
std::map<std::string, std::string> labels = {{"k1", "v1"}}; | ||
counter->Add(10l, labels); | ||
counter->Add(10l, labels, opentelemetry::context::Context{}); | ||
counter->Add(2l); | ||
counter->Add(2l, opentelemetry::context::Context{}); | ||
counter->Add(10l, {{"k1", "1"}, {"k2", 2}}); | ||
counter->Add(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); | ||
counter->Add((int64_t)10, labels); | ||
marcalff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
counter->Add((int64_t)10, labels, opentelemetry::context::Context{}); | ||
counter->Add((int64_t)2); | ||
counter->Add((int64_t)2, opentelemetry::context::Context{}); | ||
counter->Add((int64_t)10, {{"k1", "1"}, {"k2", 2}}); | ||
counter->Add((int64_t)10, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); | ||
} | ||
|
||
TEST(histogram, Record) | ||
{ | ||
std::shared_ptr<opentelemetry::metrics::Histogram<long>> counter{ | ||
new opentelemetry::metrics::NoopHistogram<long>("test", "none", "unitless")}; | ||
std::shared_ptr<opentelemetry::metrics::Histogram<int64_t>> counter{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uint64_t, as histogram is always non-negative value? Not related to this PR, but while you are here, can you rename variable name to histogram :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, changed to |
||
new opentelemetry::metrics::NoopHistogram<int64_t>("test", "none", "unitless")}; | ||
|
||
std::map<std::string, std::string> labels = {{"k1", "v1"}}; | ||
counter->Record(10l, labels, opentelemetry::context::Context{}); | ||
counter->Record(2l, opentelemetry::context::Context{}); | ||
counter->Record((int64_t)10, labels, opentelemetry::context::Context{}); | ||
counter->Record((int64_t)2, opentelemetry::context::Context{}); | ||
|
||
counter->Record(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); | ||
counter->Record((int64_t)10, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); | ||
} | ||
|
||
TEST(UpDownCountr, Record) | ||
{ | ||
std::shared_ptr<opentelemetry::metrics::UpDownCounter<long>> counter{ | ||
new opentelemetry::metrics::NoopUpDownCounter<long>("test", "none", "unitless")}; | ||
std::shared_ptr<opentelemetry::metrics::UpDownCounter<int64_t>> counter{ | ||
new opentelemetry::metrics::NoopUpDownCounter<int64_t>("test", "none", "unitless")}; | ||
|
||
std::map<std::string, std::string> labels = {{"k1", "v1"}}; | ||
counter->Add(10l, labels); | ||
counter->Add(10l, labels, opentelemetry::context::Context{}); | ||
counter->Add(2l); | ||
counter->Add(2l, opentelemetry::context::Context{}); | ||
counter->Add(10l, {{"k1", "1"}, {"k2", 2}}); | ||
counter->Add(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); | ||
counter->Add((int64_t)10, labels); | ||
counter->Add((int64_t)10, labels, opentelemetry::context::Context{}); | ||
counter->Add((int64_t)2); | ||
counter->Add((int64_t)2, opentelemetry::context::Context{}); | ||
counter->Add((int64_t)10, {{"k1", "1"}, {"k2", 2}}); | ||
counter->Add((int64_t)10, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); | ||
} | ||
|
||
#endif |
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.
In the spec
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#meter
the spec suggests UInt64 for counter and histogram (unsigned 64 bit), and Int64 (signed) for up down counters.
Not sure if we should have all "long" metrics use Int64, or have UInt64 / Int64 depending on the type of counter.
Possibly rename to CreateUInt64Counter, and use uint64_t, to discuss
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.
Yeah good point. There are two options
Use
Int64
in method name for synchronous UpDownCounter, andUInt64
for all other instruments. And use uint64_t/int64_t as appropriate accordingly for measurement value. Also inline with the specs recommendation.Use
Int64
in method name for all the instruments, and int64_t as measurement value, and do extra validation in the method whether passed value is positive or negative. So if negative value is passed for Counter instrument, drop the value.First option looks better to me. Irrespective of what we choose, the aggregation will always use
int64_t
type for the aggregated value.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.
First option sounds better, with strong types, and inlined with specs.
So, leaning to:
CreateUInt64Counter
, using uint64_tCreateUInt64Histogram
, using uint64_tCreateInt64UpDownCounter
, using int64_tCreateUInt64ObservableCounter
CreateUInt64ObservableGauge
CreateInt64ObservableUpDownCounter
Let's discuss in SIG meeting.
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.
Thanks, as discussed I renamed the functions.