-
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
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1686 +/- ##
==========================================
+ Coverage 86.31% 86.35% +0.04%
==========================================
Files 169 169
Lines 5156 5154 -2
==========================================
Hits 4450 4450
+ Misses 706 704 -2
|
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.
LGTM in general, see minor comments.
@@ -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>> CreateLongCounter( |
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.
When "long" is compiled as a 32bit int, this change is an API and ABI breaking change.
This is ok as only metrics are affected, which are not GA yet.
Still, please add a CHANGELOG section to indicate this is a breaking change compared to 1.6.1
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.
Do we need to rename the method to CreateInt64Counter
to be in consistent with the argument type?
If later we want to support 32bit integers at API level (say for embedded devices where memory is constraint), would it be confusing, or we can just add CreateShortCounter
for it.
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, CHANGELOG updated and the functions renamed as was suggested here #1686 (comment).
const opentelemetry::sdk::metrics::HistogramAggregationConfig<long> *>( | ||
aggregation_config)))) | ||
static_cast<const opentelemetry::sdk::metrics::HistogramAggregationConfig< | ||
int64_t> *>(aggregation_config)))) |
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.
Nit - this need to be double after #1665 fix. Just adding, though it would be fixed once conflict is resolved.
@@ -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>> CreateLongCounter( |
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.
Do we need to rename the method to CreateInt64Counter
to be in consistent with the argument type?
If later we want to support 32bit integers at API level (say for embedded devices where memory is constraint), would it be confusing, or we can just add CreateShortCounter
for it.
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.
+1 on replacing "long" with a a 64bit int.
Given the impact on all the method names, and questions about signed vs unsigned,
I suggest we all agree first on final names and types,
to avoid changing the patch many times, it is tedious enough.
@@ -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( |
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.
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly rename to CreateUInt64Histogram, and use uint64_t, to discuss
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, renamed all the functions as suggested here #1686 (comment)
} | ||
|
||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, changed to unit64_t
.
@@ -78,7 +78,7 @@ static metrics_sdk::MetricData CreateHistogramAggregationData() | |||
return data; | |||
} | |||
|
|||
static metrics_sdk::MetricData CreateObservableGaugeAggregationData() | |||
static metrics_sdk::MetricData CreateUInt64ObservableGaugeAggregationData() |
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.
this method is creating double type values, rename as double or keep as earlier.
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, fixed
@@ -90,7 +90,7 @@ class Meter | |||
* @param description a brief description of what the Observable Gauge is used for. | |||
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. | |||
*/ | |||
virtual nostd::shared_ptr<ObservableInstrument> CreateLongObservableGauge( | |||
virtual nostd::shared_ptr<ObservableInstrument> CreateUInt64ObservableGauge( |
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.
It's not explicit in specs that the recorded gauge values should be only positive. Which means it can be both positive and negative. Also, as an example - recorded temperature can be negative.
Sorry for creating confusion, I should have seen it earlier. I think we should change it to CreateInt64ObservableGauge
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, fixed
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, fixed
@@ -140,7 +140,7 @@ TEST(OtlpMetricSerializationTest, Histogram) | |||
|
|||
TEST(OtlpMetricSerializationTest, ObservableGauge) | |||
{ | |||
metrics_sdk::MetricData data = CreateObservableGaugeAggregationData(); | |||
metrics_sdk::MetricData data = CreateUInt64ObservableGaugeAggregationData(); |
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.
this method is creating double type values, rename as double or keep as earlier.
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, fixed
@@ -65,7 +65,7 @@ class Meter final : public opentelemetry::metrics::Meter | |||
nostd::string_view description = "", | |||
nostd::string_view unit = "") noexcept override; | |||
|
|||
nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateLongObservableGauge( | |||
nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> CreateUInt64ObservableGauge( |
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.
As earlier comment, this can be changed to CreateInt64ObservableGauge
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, fixed
sdk/src/metrics/meter.cc
Outdated
@@ -1,12 +1,13 @@ | |||
// Copyright The OpenTelemetry Authors | |||
// SPDX-License-Identifier: Apache-2.0 | |||
|
|||
#include <cstdint> |
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.
nit - this should be after ENABLE_METRICS_PREVIEW
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, fixed
sdk/src/metrics/meter.cc
Outdated
@@ -115,7 +117,7 @@ nostd::shared_ptr<metrics::Histogram<double>> Meter::CreateDoubleHistogram( | |||
new DoubleHistogram(instrument_descriptor, std::move(storage))}; | |||
} | |||
|
|||
nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> Meter::CreateLongObservableGauge( | |||
nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> Meter::CreateUInt64ObservableGauge( |
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.
As earlier comment on api, this should be CreateInt64ObservableGauge
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, fixed
@@ -83,7 +83,7 @@ TEST(ExactAggregatorOrdered, Types) | |||
// This test verifies that we do not encounter any errors when | |||
// using various numeric types. | |||
ExactAggregator<int> agg_int(metrics_api::InstrumentKind::Counter); | |||
ExactAggregator<long> agg_long(metrics_api::InstrumentKind::Counter); | |||
ExactAggregator<int64_t> agg_long(metrics_api::InstrumentKind::Counter); |
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.
These are for old metrics implementation :)
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, reverted old metrics 😄
@@ -54,7 +54,7 @@ class Meter | |||
* @param description a brief description of what the Observable Counter is used for. | |||
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. | |||
*/ | |||
virtual nostd::shared_ptr<ObservableInstrument> CreateLongObservableCounter( | |||
virtual nostd::shared_ptr<ObservableInstrument> CreateUInt64ObservableCounter( |
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.
Hate to do this, but Observable Counter can be negative also, so this should be CreateInt64ObservableCounter
:(. I confirmed offline with specs author. Sorry about multiple iterations here, but this is important to do it right before GA.
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, yes it's important we leave no changes needed after GA :)
changed to CreateInt64ObservableCounter
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.
LGTM. Thanks for working on it :)
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.
LGTM, thanks for the fix.
…ad-local-stack * commit '9acde87b08b225ce511fa8a20c6cba14f2921518': (36 commits) Prepare v1.7.0 release with Metrics API/SDK GA. (open-telemetry#1721) Fix: 1712 - Validate Instrument meta data (name, unit, description) (open-telemetry#1713) Document libthrift 0.12.0 doesn't work with Jaeger exporter (open-telemetry#1714) Fix:1674, Add Monotonic Property to Sum Aggregation, and unit tests for Up Down Counter (open-telemetry#1675) [Metrics SDK] Move Metrics Exemplar processing behind feature flag (open-telemetry#1710) [Metrics API/SDK] Change Meter API/SDK to return nostd::unique_ptr for Sync Instruments (open-telemetry#1707) [Metrics] Switch to explicit 64 bit integers (open-telemetry#1686) Add metrics e2e test to asan & tsan CI (open-telemetry#1670) Add otlp-grpc example bazel (open-telemetry#1708) [Metrics SDK] Add support for Pull Metric Reader (open-telemetry#1701) Fix debug log of OTLP HTTP exporter and ES log exporter (open-telemetry#1703) [SEMANTIC CONVENTIONS] Upgrade to version 1.14.0 (open-telemetry#1697) Fix a potential precision loss on integer in ReservoirCellIndexFor (open-telemetry#1696) fix Histogram crash (open-telemetry#1685) Fix:1676 Segfault when short export period is used for metrics (open-telemetry#1682) Add timeout support to MeterContext::ForceFlush (open-telemetry#1673) Add CMake OTELCPP_MAINTAINER_MODE (open-telemetry#1650) [DOCS] - Minor updates to OStream Metrics exporter documentation (open-telemetry#1679) Fix:open-telemetry#1575 API Documentation for Metrics SDK and API (open-telemetry#1678) Fixes open-telemetry#249 (open-telemetry#1677) ...
Fixes #1639 (issue)
Changes
"Long" instruments changed to accept
int64_t
integer values, which are unambiguously 64 bit depth.For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes