[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
|
marcalff
left a comment
There was a problem hiding this comment.
LGTM in general, see minor comments.
| */ | ||
|
|
||
| virtual nostd::shared_ptr<Counter<long>> CreateLongCounter( | ||
| virtual nostd::shared_ptr<Counter<int64_t>> CreateLongCounter( |
There was a problem hiding this comment.
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.
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.
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.
Nit - this need to be double after #1665 fix. Just adding, though it would be fixed once conflict is resolved.
| */ | ||
|
|
||
| virtual nostd::shared_ptr<Counter<long>> CreateLongCounter( | ||
| virtual nostd::shared_ptr<Counter<int64_t>> CreateLongCounter( |
There was a problem hiding this comment.
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.
marcalff
left a comment
There was a problem hiding this comment.
+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.
| */ | ||
|
|
||
| virtual nostd::shared_ptr<Counter<long>> CreateLongCounter( | ||
| virtual nostd::shared_ptr<Counter<int64_t>> CreateInt64Counter( |
There was a problem hiding this comment.
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.
Yeah good point. There are two options
-
Use
Int64in method name for synchronous UpDownCounter, andUInt64for all other instruments. And use uint64_t/int64_t as appropriate accordingly for measurement value. Also inline with the specs recommendation. -
Use
Int64in 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.
First option sounds better, with strong types, and inlined with specs.
So, leaning to:
CreateUInt64Counter, using uint64_tCreateUInt64Histogram, using uint64_tCreateInt64UpDownCounter, using int64_tCreateUInt64ObservableCounterCreateUInt64ObservableGaugeCreateInt64ObservableUpDownCounter
Let's discuss in SIG meeting.
There was a problem hiding this comment.
Thanks, as discussed I renamed the functions.
| * @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.
Possibly rename to CreateUInt64Histogram, and use uint64_t, to discuss
| * @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.
Possibly rename to CreateInt64UpDownCounter, to discuss
There was a problem hiding this comment.
Thanks, renamed all the functions as suggested here #1686 (comment)
| { | ||
| 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.
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.
thanks, changed to unit64_t.
| } | ||
|
|
||
| static metrics_sdk::MetricData CreateObservableGaugeAggregationData() | ||
| static metrics_sdk::MetricData CreateUInt64ObservableGaugeAggregationData() |
There was a problem hiding this comment.
this method is creating double type values, rename as double or keep as earlier.
| * @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.
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
| { | ||
| 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.
uint64_t, as counter is always non-negative value.
| TEST(OtlpMetricSerializationTest, ObservableGauge) | ||
| { | ||
| metrics_sdk::MetricData data = CreateObservableGaugeAggregationData(); | ||
| metrics_sdk::MetricData data = CreateUInt64ObservableGaugeAggregationData(); |
There was a problem hiding this comment.
this method is creating double type values, rename as double or keep as earlier.
| 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.
As earlier comment, this can be changed to CreateInt64ObservableGauge
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include <cstdint> |
There was a problem hiding this comment.
nit - this should be after ENABLE_METRICS_PREVIEW
| } | ||
|
|
||
| nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> Meter::CreateLongObservableGauge( | ||
| nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument> Meter::CreateUInt64ObservableGauge( |
There was a problem hiding this comment.
As earlier comment on api, this should be CreateInt64ObservableGauge
| // 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.
These are for old metrics implementation :)
There was a problem hiding this comment.
Thanks, reverted old metrics 😄
| * @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.
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.
thanks, yes it's important we leave no changes needed after GA :)
changed to CreateInt64ObservableCounter
lalitb
left a comment
There was a problem hiding this comment.
LGTM. Thanks for working on it :)
…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_tinteger values, which are unambiguously 64 bit depth.For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes