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

Synchronous Metric collection (Delta , Cumulative) #1265

Merged
merged 39 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c08cf38
collector and reader
lalitb Mar 2, 2022
c729c6a
fix format, and memory corruption
lalitb Mar 2, 2022
f692e15
changes for metric flow
lalitb Mar 3, 2022
ffb54ee
fix bazel build
lalitb Mar 3, 2022
8ecf729
fix ostream exporter
lalitb Mar 3, 2022
18e4f27
Merge branch 'main' into metric-collector
lalitb Mar 3, 2022
ad471d0
build error on windows
lalitb Mar 3, 2022
9cc53a4
Merge branch 'metric-collector' of github.com:lalitb/opentelemetry-cp…
lalitb Mar 3, 2022
05c1a8d
initial commit
lalitb Mar 14, 2022
f0380a9
implement collect function
lalitb Mar 16, 2022
fc657f9
Merge branch 'main' into temporary-storage
lalitb Mar 16, 2022
e702e89
fix build
lalitb Mar 16, 2022
d12686e
Fix async test
lalitb Mar 16, 2022
884f636
fix spell
lalitb Mar 16, 2022
1874375
fix build
lalitb Mar 17, 2022
12ba367
Merge branch 'main' into temporary-storage
lalitb Mar 18, 2022
e011a2b
add comments
lalitb Mar 18, 2022
5ab4f75
comments
lalitb Mar 18, 2022
c30b234
temp add .gitpod.yml
lalitb Mar 22, 2022
618de73
fix format
lalitb Mar 22, 2022
66d7af0
fix
lalitb Mar 22, 2022
e49e7c4
remove temp files
lalitb Mar 22, 2022
da5eb93
fix gcc48 install
lalitb Mar 22, 2022
a102d7f
Merge branch 'main' into temporary-storage
lalitb Mar 22, 2022
0551aeb
comment metric exporter till MetricData is finalised
lalitb Mar 22, 2022
b5d3bd5
add gcc4.8 TODO
lalitb Mar 22, 2022
b4bac61
add gcc4.8 TODO
lalitb Mar 22, 2022
015757c
fix spelling cumulative
lalitb Mar 22, 2022
ae65b1d
add tests for sum aggregation, and fix issues
lalitb Mar 23, 2022
29ee87d
Merge branch 'main' into temporary-storage
lalitb Mar 23, 2022
4b31fd3
Fix
lalitb Mar 23, 2022
62d0e92
remove commented code
lalitb Mar 23, 2022
464abf7
Merge branch 'main' into temporary-storage
lalitb Mar 28, 2022
4c26336
fix merge conflict
lalitb Mar 29, 2022
cb1c5a4
review comments
lalitb Mar 29, 2022
0a62679
make Aggregation::Merge/Diff/ToPoint methods as const
lalitb Mar 29, 2022
6919d1d
Update sdk/src/metrics/state/sync_metric_storage.cc
lalitb Mar 29, 2022
cf3c272
more review comments
lalitb Mar 29, 2022
010d1bc
review comments
lalitb Mar 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions exporters/ostream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,35 @@ cc_library(
],
)

cc_library(
name = "ostream_metric_exporter",
srcs = [
"src/metric_exporter.cc",
],
hdrs = [
"include/opentelemetry/exporters/ostream/metric_exporter.h",
],
strip_include_prefix = "include",
tags = [
"metrics",
"ostream",
],
deps = [
"//sdk/src/metrics",
],
)
#TODO MetricData is still changing, uncomment once it is final
# srcs = [
# "src/metric_exporter.cc",
# ],
# hdrs = [
# "include/opentelemetry/exporters/ostream/metric_exporter.h",
# ],
# strip_include_prefix = "include",
# tags = [
# "metrics",
# "ostream",
# ],
# deps = [
# "//sdk/src/metrics",
# ],
#)

cc_test(
name = "ostream_metric_test",
srcs = ["test/ostream_metric_test.cc"],
tags = [
"ostream",
"test",
],
deps = [
":ostream_metric_exporter",
"@com_google_googletest//:gtest_main",
],
)
#cc_test(
# name = "ostream_metric_test",
# srcs = ["test/ostream_metric_test.cc"],
# tags = [
# "ostream",
# "test",
# ],
# deps = [
# ":ostream_metric_exporter",
# "@com_google_googletest//:gtest_main",
#],
#)

cc_test(
name = "ostream_metrics_test_deprecated",
Expand Down
40 changes: 29 additions & 11 deletions sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,42 @@ namespace sdk
{
namespace metrics
{
class InstrumentMonotonicityAwareAggregation
{
public:
InstrumentMonotonicityAwareAggregation(bool is_monotonic) : is_monotonic_(is_monotonic) {}
bool IsMonotonic() { return is_monotonic_; }

private:
bool is_monotonic_;
};

class Aggregation
{
public:
virtual void Aggregate(long value, const PointAttributes &attributes = {}) noexcept = 0;

virtual void Aggregate(double value, const PointAttributes &attributes = {}) noexcept = 0;

virtual PointType Collect() noexcept = 0;
/**
* Returns the result of the merge of the two aggregations.
*
* This should always assume that the aggregations do not overlap and merge together for a new
* cumulative report.
*
* @param delta the newly captured (delta) aggregation
* @return the result of the merge of the given aggregation.
*/

virtual std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept = 0;

/**
* Returns a new delta aggregation by comparing two cumulative measurements.
*
* @param next the newly captured (cumulative) aggregation.
* @return The resulting delta aggregation.
*/
virtual std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept = 0;

/**
* Returns the point data that the aggregation will produce.
*
* @return PointType
*/

virtual PointType ToPoint() const noexcept = 0;

virtual ~Aggregation() = default;
};

} // namespace metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class DefaultAggregation
case InstrumentType::kUpDownCounter:
case InstrumentType::kObservableUpDownCounter:
return (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
? std::move(std::unique_ptr<Aggregation>(new LongSumAggregation(true)))
: std::move(std::unique_ptr<Aggregation>(new DoubleSumAggregation(true)));
? std::move(std::unique_ptr<Aggregation>(new LongSumAggregation()))
: std::move(std::unique_ptr<Aggregation>(new DoubleSumAggregation()));
break;
case InstrumentType::kHistogram:
return (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
Expand Down Expand Up @@ -79,11 +79,11 @@ class DefaultAggregation
case AggregationType::kSum:
if (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
{
return std::unique_ptr<Aggregation>(new LongSumAggregation(true));
return std::unique_ptr<Aggregation>(new LongSumAggregation());
}
else
{
return std::unique_ptr<Aggregation>(new DoubleSumAggregation(true));
return std::unique_ptr<Aggregation>(new DoubleSumAggregation());
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace sdk
namespace metrics
{

/**
* A null Aggregation which denotes no aggregation should occur.
*/

class DropAggregation : public Aggregation
{
public:
Expand All @@ -23,7 +27,21 @@ class DropAggregation : public Aggregation

void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override {}

PointType Collect() noexcept override { return DropPointData(); }
std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override
{
return std::unique_ptr<Aggregation>(new DropAggregation());
}

std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override
{
return std::unique_ptr<Aggregation>(new DropAggregation());
}

PointType ToPoint() const noexcept override
{
static DropPointData point_data;
return point_data;
}
};
} // namespace metrics
} // namespace sdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,47 @@ namespace sdk
{
namespace metrics
{
template <class T>
static inline void PopulateHistogramDataPoint(HistogramPointData &histogram,
opentelemetry::common::SystemTimestamp epoch_nanos,
T sum,
uint64_t count,
std::vector<uint64_t> &counts,
std::vector<T> boundaries)
{
histogram.epoch_nanos_ = epoch_nanos;
histogram.boundaries_ = boundaries;
histogram.sum_ = sum;
histogram.counts_ = counts;
histogram.count_ = count;
}

class LongHistogramAggregation : public Aggregation
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be a template class as it almost the same as DoubleHistogramAggregatoin below?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was discussed in one of the earlier PR here:
--snip
Preferred overloaded methods over the template ( for double and long type) to avoid having header-only metrics sdk. The template use had a cascading effect here, forcing to make all inter-related classes as templates. Since this is not a customer-facing API, we have the flexibility to change it later.
--snap

{
public:
LongHistogramAggregation();
LongHistogramAggregation(HistogramPointData &&);

void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override;

void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override {}

PointType Collect() noexcept override;
virtual std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override;

virtual std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override;

PointType ToPoint() const noexcept override;

private:
opentelemetry::common::SpinLockMutex lock_;
std::vector<long> boundaries_;
long sum_;
std::vector<uint64_t> counts_;
uint64_t count_;
HistogramPointData point_data_;
};

class DoubleHistogramAggregation : public Aggregation
{
public:
DoubleHistogramAggregation();
DoubleHistogramAggregation(HistogramPointData &&);

void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override {}

void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override;

PointType Collect() noexcept override;
virtual std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override;

virtual std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override;

PointType ToPoint() const noexcept override;

private:
opentelemetry::common::SpinLockMutex lock_;
std::vector<double> boundaries_;
double sum_;
std::vector<uint64_t> counts_;
uint64_t count_;
mutable opentelemetry::common::SpinLockMutex lock_;
mutable HistogramPointData point_data_;
};

} // namespace metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,42 @@ class LongLastValueAggregation : public Aggregation
{
public:
LongLastValueAggregation();
LongLastValueAggregation(LastValuePointData &&);

void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override;

void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override {}

PointType Collect() noexcept override;
virtual std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override;

virtual std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override;

PointType ToPoint() const noexcept override;

private:
opentelemetry::common::SpinLockMutex lock_;
long value_;
bool is_lastvalue_valid_;
LastValuePointData point_data_;
};

class DoubleLastValueAggregation : public Aggregation
{
public:
DoubleLastValueAggregation();
DoubleLastValueAggregation(LastValuePointData &&);

void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override {}

void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override;

PointType Collect() noexcept override;
virtual std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override;

virtual std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override;

PointType ToPoint() const noexcept override;

private:
opentelemetry::common::SpinLockMutex lock_;
double value_;
bool is_lastvalue_valid_;
mutable opentelemetry::common::SpinLockMutex lock_;
mutable LastValuePointData point_data_;
};

} // namespace metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,46 @@ namespace sdk
namespace metrics
{

template <class T>
static inline void PopulateSumPointData(SumPointData &sum,
opentelemetry::common::SystemTimestamp start_ts,
opentelemetry::common::SystemTimestamp end_ts,
T value,
bool is_monotonic)
{
sum.start_epoch_nanos_ = start_ts;
sum.end_epoch_nanos_ = end_ts;
sum.value_ = value;
sum.is_monotonic_ = is_monotonic;
sum.aggregation_temporality_ = AggregationTemporality::kDelta;
}

class LongSumAggregation : public Aggregation, InstrumentMonotonicityAwareAggregation
class LongSumAggregation : public Aggregation
{
public:
LongSumAggregation(bool is_monotonic);
LongSumAggregation();
LongSumAggregation(SumPointData &&);

void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override;

void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override {}

PointType Collect() noexcept override;
virtual std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override;

virtual std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override;

PointType ToPoint() const noexcept override;

private:
opentelemetry::common::SpinLockMutex lock_;
opentelemetry::common::SystemTimestamp start_epoch_nanos_;
long sum_;
SumPointData point_data_;
};

class DoubleSumAggregation : public Aggregation, InstrumentMonotonicityAwareAggregation
class DoubleSumAggregation : public Aggregation
{
public:
DoubleSumAggregation(bool is_monotonic);
DoubleSumAggregation();
DoubleSumAggregation(SumPointData &&);

void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override {}

void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override;

PointType Collect() noexcept override;
virtual std::unique_ptr<Aggregation> Merge(const Aggregation &delta) const noexcept override;

virtual std::unique_ptr<Aggregation> Diff(const Aggregation &next) const noexcept override;

PointType ToPoint() const noexcept override;

private:
opentelemetry::common::SpinLockMutex lock_;
opentelemetry::common::SystemTimestamp start_epoch_nanos_;
double sum_;
mutable opentelemetry::common::SpinLockMutex lock_;
SumPointData point_data_;
};

} // namespace metrics
Expand Down
Loading