Skip to content

Commit

Permalink
[Metrics] Switch to explicit 64 bit integers (open-telemetry#1686)
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo authored and yxue committed Dec 5, 2022
1 parent e640b89 commit b7ce332
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Increment the:
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
## [1.8.1] 2022-12-04

* [ETW Exporter] Tail based sampling support [#1780](https://github.com/open-telemetry/opentelemetry-cpp/pull/1780)
Expand Down Expand Up @@ -281,6 +282,8 @@ update the semantic convention in instrumentation library is needed.
>>>>>>> cf9ebb02 (Add CMake OTELCPP_MAINTAINER_MODE (#1650))
=======
>>>>>>> c6552dca ([Metrics SDK] Add support for Pull Metric Reader (#1701))
=======
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
* [TRACE SDK] Add trace sdk builders (#1393)
[#1471](https://github.com/open-telemetry/opentelemetry-cpp/pull/1471)
* [EXAMPLE] Fix memory ownership of InMemorySpanExporter (#1473)
Expand All @@ -303,6 +306,10 @@ update the semantic convention in instrumentation library is needed.
=======
=======
=======
=======
* [Metrics] Switch to explicit 64 bit integers [#1686](https://github.com/open-telemetry/opentelemetry-cpp/pull/1686)
which includes breaking change in the Metrics api and sdk.
>>>>>>> 7fd76eec ([Metrics] Switch to explicit 64 bit integers (#1686))
* [Metrics SDK] Add support for Pull Metric Exporter [#1701](https://github.com/open-telemetry/opentelemetry-cpp/pull/1701)
which includes breaking change in the Metrics api.
>>>>>>> 70777ef9 ([Metrics SDK] Add support for Pull Metric Reader (#1701))
Expand Down
12 changes: 12 additions & 0 deletions api/include/opentelemetry/metrics/meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class Meter
* @return a shared pointer to the created Counter.
*/

<<<<<<< HEAD
virtual nostd::unique_ptr<Counter<uint64_t>> CreateUInt64Counter(
=======
virtual nostd::shared_ptr<Counter<uint64_t>> CreateUInt64Counter(
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
Expand Down Expand Up @@ -72,7 +76,11 @@ class Meter
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @return a shared pointer to the created Histogram.
*/
<<<<<<< HEAD
virtual nostd::unique_ptr<Histogram<uint64_t>> CreateUInt64Histogram(
=======
virtual nostd::shared_ptr<Histogram<uint64_t>> CreateUInt64Histogram(
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
Expand Down Expand Up @@ -109,7 +117,11 @@ class Meter
* @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
* @return a shared pointer to the created UpDownCounter.
*/
<<<<<<< HEAD
virtual nostd::unique_ptr<UpDownCounter<int64_t>> CreateInt64UpDownCounter(
=======
virtual nostd::shared_ptr<UpDownCounter<int64_t>> CreateInt64UpDownCounter(
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept = 0;
Expand Down
31 changes: 31 additions & 0 deletions api/include/opentelemetry/metrics/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,27 @@ class NoopObservableInstrument : public ObservableInstrument
class NoopMeter final : public Meter
{
public:
<<<<<<< HEAD
nostd::unique_ptr<Counter<uint64_t>> CreateUInt64Counter(
=======
nostd::shared_ptr<Counter<uint64_t>> CreateUInt64Counter(
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
return nostd::shared_ptr<Counter<uint64_t>>{new NoopCounter<uint64_t>(name, description, unit)};
}

nostd::shared_ptr<Counter<double>> CreateDoubleCounter(
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
return nostd::unique_ptr<Counter<uint64_t>>{new NoopCounter<uint64_t>(name, description, unit)};
}

<<<<<<< HEAD
nostd::unique_ptr<Counter<double>> CreateDoubleCounter(
nostd::string_view name,
nostd::string_view description = "",
Expand All @@ -102,6 +115,8 @@ class NoopMeter final : public Meter
return nostd::unique_ptr<Counter<double>>{new NoopCounter<double>(name, description, unit)};
}

=======
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
nostd::shared_ptr<ObservableInstrument> CreateInt64ObservableCounter(
nostd::string_view name,
nostd::string_view description = "",
Expand All @@ -120,12 +135,20 @@ class NoopMeter final : public Meter
new NoopObservableInstrument(name, description, unit));
}

<<<<<<< HEAD
nostd::unique_ptr<Histogram<uint64_t>> CreateUInt64Histogram(
=======
nostd::shared_ptr<Histogram<uint64_t>> CreateUInt64Histogram(
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
<<<<<<< HEAD
return nostd::unique_ptr<Histogram<uint64_t>>{
=======
return nostd::shared_ptr<Histogram<uint64_t>>{
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
new NoopHistogram<uint64_t>(name, description, unit)};
}

Expand Down Expand Up @@ -155,12 +178,20 @@ class NoopMeter final : public Meter
new NoopObservableInstrument(name, description, unit));
}

<<<<<<< HEAD
nostd::unique_ptr<UpDownCounter<int64_t>> CreateInt64UpDownCounter(
=======
nostd::shared_ptr<UpDownCounter<int64_t>> CreateInt64UpDownCounter(
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override
{
<<<<<<< HEAD
return nostd::unique_ptr<UpDownCounter<int64_t>>{
=======
return nostd::shared_ptr<UpDownCounter<int64_t>>{
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
new NoopUpDownCounter<int64_t>(name, description, unit)};
}

Expand Down
19 changes: 17 additions & 2 deletions exporters/otlp/src/otlp_metric_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ void OtlpMetricUtils::ConvertSumMetric(const metric_sdk::MetricData &metric_data

if ((nostd::holds_alternative<int64_t>(sum_data.value_)))
{
<<<<<<< HEAD
<<<<<<< HEAD
proto_sum_point_data->set_as_int(nostd::get<int64_t>(sum_data.value_));
=======
proto_sum_point_data->set_as_int(nostd::get<long>(sum_data.value_));
>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))
=======
proto_sum_point_data->set_as_int(nostd::get<int64_t>(sum_data.value_));
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
}
else
{
Expand Down Expand Up @@ -100,11 +104,15 @@ void OtlpMetricUtils::ConvertHistogramMetric(
// sum
if ((nostd::holds_alternative<int64_t>(histogram_data.sum_)))
{
<<<<<<< HEAD
<<<<<<< HEAD
proto_histogram_point_data->set_sum(nostd::get<int64_t>(histogram_data.sum_));
=======
proto_histogram_point_data->set_sum(nostd::get<long>(histogram_data.sum_));
>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))
=======
proto_histogram_point_data->set_sum(nostd::get<int64_t>(histogram_data.sum_));
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
}
else
{
Expand All @@ -122,6 +130,9 @@ void OtlpMetricUtils::ConvertHistogramMetric(
if (nostd::holds_alternative<int64_t>(histogram_data.min_))
{
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
proto_histogram_point_data->set_min(nostd::get<int64_t>(histogram_data.min_));
}
else
Expand All @@ -130,7 +141,11 @@ void OtlpMetricUtils::ConvertHistogramMetric(
}
if (nostd::holds_alternative<int64_t>(histogram_data.max_))
{
<<<<<<< HEAD
proto_histogram_point_data->set_max(nostd::get<int64_t>(histogram_data.max_));
=======
proto_histogram_point_data->set_min(nostd::get<int64_t>(histogram_data.max_));
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
}
else
{
Expand Down Expand Up @@ -183,9 +198,9 @@ void OtlpMetricUtils::ConvertGaugeMetric(const opentelemetry::sdk::metrics::Metr
auto gauge_data =
nostd::get<sdk::metrics::LastValuePointData>(point_data_with_attributes.point_data);

if ((nostd::holds_alternative<long>(gauge_data.value_)))
if ((nostd::holds_alternative<int64_t>(gauge_data.value_)))
{
proto_gauge_point_data->set_as_int(nostd::get<long>(gauge_data.value_));
proto_gauge_point_data->set_as_int(nostd::get<int64_t>(gauge_data.value_));
}
else
{
Expand Down
14 changes: 14 additions & 0 deletions exporters/otlp/test/otlp_http_metric_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,15 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
last_value_point_data.is_lastvalue_valid_ = true;
last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{};
opentelemetry::sdk::metrics::LastValuePointData last_value_point_data2{};
<<<<<<< HEAD
<<<<<<< HEAD
last_value_point_data2.value_ = (int64_t)20;
=======
last_value_point_data2.value_ = 20l;
>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))
=======
last_value_point_data2.value_ = (int64_t)20;
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
last_value_point_data2.is_lastvalue_valid_ = true;
last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{};
opentelemetry::sdk::metrics::MetricData metric_data{
Expand Down Expand Up @@ -659,11 +663,15 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
last_value_point_data.is_lastvalue_valid_ = true;
last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{};
opentelemetry::sdk::metrics::LastValuePointData last_value_point_data2{};
<<<<<<< HEAD
<<<<<<< HEAD
last_value_point_data2.value_ = (int64_t)20;
=======
last_value_point_data2.value_ = 20l;
>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))
=======
last_value_point_data2.value_ = (int64_t)20;
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
last_value_point_data2.is_lastvalue_valid_ = true;
last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{};
opentelemetry::sdk::metrics::MetricData metric_data{
Expand Down Expand Up @@ -812,6 +820,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
histogram_point_data2.count_ = 3;
histogram_point_data2.counts_ = {200, 300, 400, 500};
histogram_point_data2.sum_ = (int64_t)900;
<<<<<<< HEAD
=======
histogram_point_data.boundaries_ = std::list<double>{10.1, 20.2, 30.2};
histogram_point_data.count_ = 3;
Expand All @@ -823,6 +832,8 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
histogram_point_data2.counts_ = {200, 300, 400, 500};
histogram_point_data2.sum_ = 900l;
>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))
=======
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))

opentelemetry::sdk::metrics::MetricData metric_data{
opentelemetry::sdk::metrics::InstrumentDescriptor{
Expand Down Expand Up @@ -1038,12 +1049,15 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test
histogram_point_data2.count_ = 3;
histogram_point_data2.counts_ = {200, 300, 400, 500};
histogram_point_data2.sum_ = (int64_t)900;
<<<<<<< HEAD
=======
histogram_point_data2.boundaries_ = std::list<long>{10, 20, 30};
histogram_point_data2.count_ = 3;
histogram_point_data2.counts_ = {200, 300, 400, 500};
histogram_point_data2.sum_ = 900l;
>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))
=======
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))

opentelemetry::sdk::metrics::MetricData metric_data{
opentelemetry::sdk::metrics::InstrumentDescriptor{
Expand Down
12 changes: 12 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ class Meter final : public opentelemetry::metrics::Meter
std::unique_ptr<opentelemetry::sdk::instrumentationscope::InstrumentationScope> scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("")) noexcept;

<<<<<<< HEAD
nostd::unique_ptr<opentelemetry::metrics::Counter<uint64_t>> CreateUInt64Counter(
=======
nostd::shared_ptr<opentelemetry::metrics::Counter<uint64_t>> CreateUInt64Counter(
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;
Expand All @@ -76,7 +80,11 @@ class Meter final : public opentelemetry::metrics::Meter
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

<<<<<<< HEAD
nostd::unique_ptr<opentelemetry::metrics::Histogram<uint64_t>> CreateUInt64Histogram(
=======
nostd::shared_ptr<opentelemetry::metrics::Histogram<uint64_t>> CreateUInt64Histogram(
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;
Expand All @@ -96,8 +104,12 @@ class Meter final : public opentelemetry::metrics::Meter
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;

<<<<<<< HEAD
<<<<<<< HEAD
nostd::unique_ptr<opentelemetry::metrics::UpDownCounter<int64_t>> CreateInt64UpDownCounter(
=======
nostd::shared_ptr<opentelemetry::metrics::UpDownCounter<int64_t>> CreateInt64UpDownCounter(
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
nostd::string_view name,
nostd::string_view description = "",
nostd::string_view unit = "") noexcept override;
Expand Down
10 changes: 10 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/sync_instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once
<<<<<<< HEAD
=======
#ifndef ENABLE_METRICS_PREVIEW
# include "opentelemetry/common/key_value_iterable.h"
# include "opentelemetry/metrics/sync_instruments.h"
# include "opentelemetry/nostd/string_view.h"
# include "opentelemetry/sdk/metrics/instruments.h"
# include "opentelemetry/sdk/metrics/state/metric_storage.h"
# include "opentelemetry/sdk_config.h"
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))

<<<<<<< HEAD
#include "opentelemetry/common/key_value_iterable.h"
Expand Down
16 changes: 16 additions & 0 deletions sdk/src/metrics/aggregation/sum_aggregation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ namespace metrics

LongSumAggregation::LongSumAggregation(bool is_monotonic)
{
<<<<<<< HEAD
point_data_.value_ = (int64_t)0;
point_data_.is_monotonic_ = is_monotonic;
=======
point_data_.value_ = (int64_t)0;
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
}

LongSumAggregation::LongSumAggregation(SumPointData &&data) : point_data_{std::move(data)} {}
Expand Down Expand Up @@ -46,19 +50,31 @@ std::unique_ptr<Aggregation> LongSumAggregation::Merge(const Aggregation &delta)
nostd::get<SumPointData>((static_cast<const LongSumAggregation &>(delta).ToPoint()))
.value_) +
nostd::get<int64_t>(nostd::get<SumPointData>(ToPoint()).value_);
<<<<<<< HEAD
std::unique_ptr<Aggregation> aggr(new LongSumAggregation(point_data_.is_monotonic_));
=======
std::unique_ptr<Aggregation> aggr(new LongSumAggregation());
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
static_cast<LongSumAggregation *>(aggr.get())->point_data_.value_ = merge_value;
return aggr;
}

std::unique_ptr<Aggregation> LongSumAggregation::Diff(const Aggregation &next) const noexcept
{
<<<<<<< HEAD
=======

>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
int64_t diff_value =
nostd::get<int64_t>(
nostd::get<SumPointData>((static_cast<const LongSumAggregation &>(next).ToPoint()))
.value_) -
nostd::get<int64_t>(nostd::get<SumPointData>(ToPoint()).value_);
<<<<<<< HEAD
std::unique_ptr<Aggregation> aggr(new LongSumAggregation(point_data_.is_monotonic_));
=======
std::unique_ptr<Aggregation> aggr(new LongSumAggregation());
>>>>>>> 16c5d000 ([Metrics] Switch to explicit 64 bit integers (#1686))
static_cast<LongSumAggregation *>(aggr.get())->point_data_.value_ = diff_value;
return aggr;
}
Expand Down
Loading

0 comments on commit b7ce332

Please sign in to comment.