]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/sdk/src/metrics/aggregation/lastvalue_aggregation.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / sdk / src / metrics / aggregation / lastvalue_aggregation.cc
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #ifndef ENABLE_METRICS_PREVIEW
5 # include "opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h"
6 # include "opentelemetry/common/timestamp.h"
7 # include "opentelemetry/version.h"
8
9 # include <mutex>
10
11 OPENTELEMETRY_BEGIN_NAMESPACE
12 namespace sdk
13 {
14 namespace metrics
15 {
16
17 LongLastValueAggregation::LongLastValueAggregation()
18 {
19 point_data_.is_lastvalue_valid_ = false;
20 point_data_.value_ = 0l;
21 }
22
23 LongLastValueAggregation::LongLastValueAggregation(LastValuePointData &&data)
24 : point_data_{std::move(data)}
25 {}
26
27 LongLastValueAggregation::LongLastValueAggregation(const LastValuePointData &data)
28 : point_data_{data}
29 {}
30
31 void LongLastValueAggregation::Aggregate(long value, const PointAttributes &attributes) noexcept
32 {
33 const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
34 point_data_.is_lastvalue_valid_ = true;
35 point_data_.value_ = value;
36 }
37
38 std::unique_ptr<Aggregation> LongLastValueAggregation::Merge(
39 const Aggregation &delta) const noexcept
40 {
41 if (nostd::get<LastValuePointData>(ToPoint()).sample_ts_.time_since_epoch() >
42 nostd::get<LastValuePointData>(delta.ToPoint()).sample_ts_.time_since_epoch())
43 {
44 LastValuePointData merge_data = std::move(nostd::get<LastValuePointData>(ToPoint()));
45 return std::unique_ptr<Aggregation>(new LongLastValueAggregation(std::move(merge_data)));
46 }
47 else
48 {
49 LastValuePointData merge_data = std::move(nostd::get<LastValuePointData>(delta.ToPoint()));
50 return std::unique_ptr<Aggregation>(new LongLastValueAggregation(std::move(merge_data)));
51 }
52 }
53
54 std::unique_ptr<Aggregation> LongLastValueAggregation::Diff(const Aggregation &next) const noexcept
55 {
56 if (nostd::get<LastValuePointData>(ToPoint()).sample_ts_.time_since_epoch() >
57 nostd::get<LastValuePointData>(next.ToPoint()).sample_ts_.time_since_epoch())
58 {
59 LastValuePointData diff_data = std::move(nostd::get<LastValuePointData>(ToPoint()));
60 return std::unique_ptr<Aggregation>(new LongLastValueAggregation(std::move(diff_data)));
61 }
62 else
63 {
64 LastValuePointData diff_data = std::move(nostd::get<LastValuePointData>(next.ToPoint()));
65 return std::unique_ptr<Aggregation>(new LongLastValueAggregation(std::move(diff_data)));
66 }
67 }
68
69 PointType LongLastValueAggregation::ToPoint() const noexcept
70 {
71 return point_data_;
72 }
73
74 DoubleLastValueAggregation::DoubleLastValueAggregation()
75 {
76 point_data_.is_lastvalue_valid_ = false;
77 point_data_.value_ = 0.0;
78 }
79
80 DoubleLastValueAggregation::DoubleLastValueAggregation(LastValuePointData &&data)
81 : point_data_{std::move(data)}
82 {}
83
84 DoubleLastValueAggregation::DoubleLastValueAggregation(const LastValuePointData &data)
85 : point_data_{data}
86 {}
87
88 void DoubleLastValueAggregation::Aggregate(double value, const PointAttributes &attributes) noexcept
89 {
90 const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
91 point_data_.is_lastvalue_valid_ = true;
92 point_data_.value_ = value;
93 }
94
95 std::unique_ptr<Aggregation> DoubleLastValueAggregation::Merge(
96 const Aggregation &delta) const noexcept
97 {
98 if (nostd::get<LastValuePointData>(ToPoint()).sample_ts_.time_since_epoch() >
99 nostd::get<LastValuePointData>(delta.ToPoint()).sample_ts_.time_since_epoch())
100 {
101 LastValuePointData merge_data = std::move(nostd::get<LastValuePointData>(ToPoint()));
102 return std::unique_ptr<Aggregation>(new LongLastValueAggregation(std::move(merge_data)));
103 }
104 else
105 {
106 LastValuePointData merge_data = std::move(nostd::get<LastValuePointData>(delta.ToPoint()));
107 return std::unique_ptr<Aggregation>(new LongLastValueAggregation(std::move(merge_data)));
108 }
109 }
110
111 std::unique_ptr<Aggregation> DoubleLastValueAggregation::Diff(
112 const Aggregation &next) const noexcept
113 {
114 if (nostd::get<LastValuePointData>(ToPoint()).sample_ts_.time_since_epoch() >
115 nostd::get<LastValuePointData>(next.ToPoint()).sample_ts_.time_since_epoch())
116 {
117 LastValuePointData diff_data = std::move(nostd::get<LastValuePointData>(ToPoint()));
118 return std::unique_ptr<Aggregation>(new LongLastValueAggregation(std::move(diff_data)));
119 }
120 else
121 {
122 LastValuePointData diff_data = std::move(nostd::get<LastValuePointData>(next.ToPoint()));
123 return std::unique_ptr<Aggregation>(new LongLastValueAggregation(std::move(diff_data)));
124 }
125 }
126
127 PointType DoubleLastValueAggregation::ToPoint() const noexcept
128 {
129 return point_data_;
130 }
131 } // namespace metrics
132 } // namespace sdk
133 OPENTELEMETRY_END_NAMESPACE
134 #endif