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

[Metrics] Switch to explicit 64 bit integers #1686

Merged
merged 25 commits into from
Oct 25, 2022

Conversation

esigo
Copy link
Member

@esigo esigo commented Oct 15, 2022

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
  • Unit tests have been added
  • Changes in public API reviewed

@codecov
Copy link

codecov bot commented Oct 15, 2022

Codecov Report

Merging #1686 (cf7f873) into main (5258563) will increase coverage by 0.04%.
The diff coverage is 71.70%.

Additional details and impacted files

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
api/include/opentelemetry/metrics/meter.h 100.00% <ø> (ø)
api/include/opentelemetry/metrics/noop.h 40.75% <0.00%> (ø)
...pi/include/opentelemetry/metrics/observer_result.h 100.00% <ø> (ø)
...pentelemetry/sdk/metrics/aggregation/aggregation.h 100.00% <ø> (ø)
...ry/sdk/metrics/aggregation/histogram_aggregation.h 90.00% <0.00%> (ø)
...ry/sdk/metrics/aggregation/lastvalue_aggregation.h 0.00% <0.00%> (ø)
...elemetry/sdk/metrics/aggregation/sum_aggregation.h 0.00% <0.00%> (ø)
...nclude/opentelemetry/sdk/metrics/data/point_data.h 100.00% <ø> (ø)
...emetry/sdk/metrics/exemplar/always_sample_filter.h 100.00% <ø> (ø)
...nclude/opentelemetry/sdk/metrics/exemplar/filter.h 100.00% <ø> (ø)
... and 27 more

@esigo esigo changed the title Switch to explicit 64 bit integers [Metrics] Switch to explicit 64 bit integers Oct 15, 2022
@esigo esigo marked this pull request as ready for review October 15, 2022 14:56
@esigo esigo requested a review from a team October 15, 2022 14:56
@esigo esigo added the metrics label Oct 15, 2022
Copy link
Member

@marcalff marcalff left a 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.

api/test/metrics/noop_sync_instrument_test.cc Outdated Show resolved Hide 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(
Copy link
Member

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

Copy link
Member

@lalitb lalitb Oct 17, 2022

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.

Copy link
Member Author

@esigo esigo Oct 20, 2022

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))))
Copy link
Member

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(
Copy link
Member

@lalitb lalitb Oct 17, 2022

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.

Copy link
Member

@marcalff marcalff left a 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(
Copy link
Member

@marcalff marcalff Oct 18, 2022

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

Copy link
Member

@lalitb lalitb Oct 18, 2022

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, and UInt64 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.

Copy link
Member

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_t
  • CreateUInt64Histogram, using uint64_t
  • CreateInt64UpDownCounter, using int64_t
  • CreateUInt64ObservableCounter
  • CreateUInt64ObservableGauge
  • CreateInt64ObservableUpDownCounter

Let's discuss in SIG meeting.

Copy link
Member Author

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(
Copy link
Member

@marcalff marcalff Oct 18, 2022

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(
Copy link
Member

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

Copy link
Member Author

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{
Copy link
Member

@lalitb lalitb Oct 20, 2022

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 :)

Copy link
Member Author

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()
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, fixed

api/include/opentelemetry/metrics/meter.h Show resolved Hide resolved
@@ -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(
Copy link
Member

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

Copy link
Member Author

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{
Copy link
Member

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.

Copy link
Member Author

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();
Copy link
Member

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.

Copy link
Member Author

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(
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, fixed

@@ -1,12 +1,13 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <cstdint>
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, fixed

@@ -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(
Copy link
Member

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

Copy link
Member Author

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);
Copy link
Member

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 :)

Copy link
Member Author

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(
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

@lalitb lalitb left a 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 :)

Copy link
Member

@marcalff marcalff left a 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.

@esigo esigo merged commit 7fd76ee into open-telemetry:main Oct 25, 2022
@esigo esigo deleted the integers-1639 branch October 25, 2022 14:57
ays7 added a commit to ays7/opentelemetry-cpp that referenced this pull request Oct 29, 2022
…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)
  ...
yxue pushed a commit to yxue/opentelemetry-cpp that referenced this pull request Dec 5, 2022
yxue pushed a commit to yxue/opentelemetry-cpp that referenced this pull request Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Metrics SDK] Switch to explicit 64 bit integers
4 participants