NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/sdk/metrics/aggregation/default_aggregation.h
Go to the documentation of this file.
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <memory>
7 
8 #include "opentelemetry/sdk/metrics/aggregation/aggregation.h"
9 #include "opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_aggregation.h"
10 #include "opentelemetry/sdk/metrics/aggregation/drop_aggregation.h"
11 #include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h"
12 #include "opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h"
13 #include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h"
14 #include "opentelemetry/sdk/metrics/data/point_data.h"
15 #include "opentelemetry/sdk/metrics/instruments.h"
16 #include "opentelemetry/version.h"
17 
19 namespace sdk
20 {
21 namespace metrics
22 {
23 class AggregationConfig;
24 
26 {
27 public:
28  static std::unique_ptr<Aggregation> CreateAggregation(
29  const opentelemetry::sdk::metrics::InstrumentDescriptor &instrument_descriptor,
30  const AggregationConfig *aggregation_config)
31  {
32  bool is_monotonic = true;
33  auto aggr_type = GetDefaultAggregationType(instrument_descriptor.type_, is_monotonic);
34  switch (aggr_type)
35  {
37  return (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
38  ? std::move(std::unique_ptr<Aggregation>(new LongSumAggregation(is_monotonic)))
39  : std::move(
40  std::unique_ptr<Aggregation>(new DoubleSumAggregation(is_monotonic)));
41  break;
43  if (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
44  {
45  return (std::unique_ptr<Aggregation>(new LongHistogramAggregation(aggregation_config)));
46  }
47  else
48  {
49  return (std::unique_ptr<Aggregation>(new DoubleHistogramAggregation(aggregation_config)));
50  }
51 
52  break;
53  }
55  return (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
56  ? std::move(std::unique_ptr<Aggregation>(new LongLastValueAggregation()))
57  : std::move(std::unique_ptr<Aggregation>(new DoubleLastValueAggregation()));
58  break;
59  default:
60  return std::unique_ptr<Aggregation>(new DropAggregation());
61  };
62  }
63 
64  static std::unique_ptr<Aggregation> CreateAggregation(
65  AggregationType aggregation_type,
66  InstrumentDescriptor instrument_descriptor,
67  const AggregationConfig *aggregation_config = nullptr)
68  {
69  switch (aggregation_type)
70  {
72  return std::unique_ptr<Aggregation>(new DropAggregation());
73  break;
75  if (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
76  {
77  return std::unique_ptr<Aggregation>(new LongHistogramAggregation(aggregation_config));
78  }
79  else
80  {
81  return std::unique_ptr<Aggregation>(new DoubleHistogramAggregation(aggregation_config));
82  }
83  break;
85  return std::unique_ptr<Aggregation>(
86  new Base2ExponentialHistogramAggregation(aggregation_config));
87  break;
89  if (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
90  {
91  return std::unique_ptr<Aggregation>(new LongLastValueAggregation());
92  }
93  else
94  {
95  return std::unique_ptr<Aggregation>(new DoubleLastValueAggregation());
96  }
97  break;
98  case AggregationType::kSum: {
99  bool is_monotonic = true;
100  if (instrument_descriptor.type_ == InstrumentType::kUpDownCounter ||
101  instrument_descriptor.type_ == InstrumentType::kObservableUpDownCounter ||
102  instrument_descriptor.type_ == InstrumentType::kHistogram)
103  {
104  is_monotonic = false;
105  }
106  if (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
107  {
108  return std::unique_ptr<Aggregation>(new LongSumAggregation(is_monotonic));
109  }
110  else
111  {
112  return std::unique_ptr<Aggregation>(new DoubleSumAggregation(is_monotonic));
113  }
114  break;
115  }
116  default:
117  return DefaultAggregation::CreateAggregation(instrument_descriptor, aggregation_config);
118  }
119  }
120 
121  static std::unique_ptr<Aggregation> CloneAggregation(
122  AggregationType aggregation_type,
123  const InstrumentDescriptor &instrument_descriptor,
124  const Aggregation &to_copy)
125  {
126  const PointType point_data = to_copy.ToPoint();
127  bool is_monotonic = true;
128  if (aggregation_type == AggregationType::kDefault)
129  {
130  aggregation_type = GetDefaultAggregationType(instrument_descriptor.type_, is_monotonic);
131  }
132  switch (aggregation_type)
133  {
135  return std::unique_ptr<Aggregation>(new DropAggregation());
137  if (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
138  {
139  return std::unique_ptr<Aggregation>(
140  new LongHistogramAggregation(nostd::get<HistogramPointData>(point_data)));
141  }
142  else
143  {
144  return std::unique_ptr<Aggregation>(
145  new DoubleHistogramAggregation(nostd::get<HistogramPointData>(point_data)));
146  }
148  return std::unique_ptr<Aggregation>(new Base2ExponentialHistogramAggregation(
149  nostd::get<Base2ExponentialHistogramPointData>(point_data)));
151  if (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
152  {
153  return std::unique_ptr<Aggregation>(
154  new LongLastValueAggregation(nostd::get<LastValuePointData>(point_data)));
155  }
156  else
157  {
158  return std::unique_ptr<Aggregation>(
159  new DoubleLastValueAggregation(nostd::get<LastValuePointData>(point_data)));
160  }
162  if (instrument_descriptor.value_type_ == InstrumentValueType::kLong)
163  {
164  return std::unique_ptr<Aggregation>(
165  new LongSumAggregation(nostd::get<SumPointData>(point_data)));
166  }
167  else
168  {
169  return std::unique_ptr<Aggregation>(
170  new DoubleSumAggregation(nostd::get<SumPointData>(point_data)));
171  }
172  default:
173  return nullptr; // won't reach here
174  }
175  }
176 
178  bool &is_monotonic)
179  {
180  is_monotonic = false;
181  switch (instrument_type)
182  {
185  is_monotonic = true;
186  return AggregationType::kSum;
189  return AggregationType::kSum;
195  default:
196  return AggregationType::kDrop;
197  }
198  }
199 };
200 
201 } // namespace metrics
202 } // namespace sdk
sdk::metrics::InstrumentDescriptor::type_
InstrumentType type_
Definition: includes/opentelemetry/sdk/metrics/instruments.h:66
sdk::metrics::AggregationType
AggregationType
Definition: includes/opentelemetry/sdk/metrics/instruments.h:44
sdk::metrics::Base2ExponentialHistogramAggregation
Definition: includes/opentelemetry/sdk/metrics/aggregation/base2_exponential_histogram_aggregation.h:24
sdk::metrics::AggregationType::kDrop
@ kDrop
sdk::metrics::DefaultAggregation::CreateAggregation
static std::unique_ptr< Aggregation > CreateAggregation(AggregationType aggregation_type, InstrumentDescriptor instrument_descriptor, const AggregationConfig *aggregation_config=nullptr)
Definition: includes/opentelemetry/sdk/metrics/aggregation/default_aggregation.h:64
sdk::metrics::InstrumentType::kObservableGauge
@ kObservableGauge
sdk::metrics::DefaultAggregation::GetDefaultAggregationType
static AggregationType GetDefaultAggregationType(InstrumentType instrument_type, bool &is_monotonic)
Definition: includes/opentelemetry/sdk/metrics/aggregation/default_aggregation.h:177
sdk::metrics::InstrumentType::kCounter
@ kCounter
sdk::metrics::AggregationConfig
Definition: includes/opentelemetry/sdk/metrics/aggregation/aggregation_config.h:16
sdk::metrics::AggregationType::kLastValue
@ kLastValue
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
sdk::metrics::DoubleHistogramAggregation
Definition: includes/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h:57
sdk::metrics::AggregationType::kHistogram
@ kHistogram
sdk::metrics::LongLastValueAggregation
Definition: includes/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h:20
sdk::metrics::InstrumentValueType::kLong
@ kLong
sdk::metrics::DoubleLastValueAggregation
Definition: includes/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h:41
sdk::metrics::InstrumentType::kHistogram
@ kHistogram
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
absl::move
constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::remove_reference_t< T > && move(T &&t) noexcept
Definition: includes/opentelemetry/nostd/internal/absl/utility/utility.h:199
sdk::metrics::DoubleSumAggregation
Definition: includes/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h:42
sdk::metrics::LongSumAggregation
Definition: includes/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h:21
sdk::metrics::Aggregation
Definition: includes/opentelemetry/sdk/metrics/aggregation/aggregation.h:16
sdk::metrics::InstrumentType::kGauge
@ kGauge
sdk::metrics::AggregationType::kBase2ExponentialHistogram
@ kBase2ExponentialHistogram
sdk::metrics::Aggregation::ToPoint
virtual PointType ToPoint() const noexcept=0
Returns the point data that the aggregation will produce.
sdk::metrics::InstrumentType::kUpDownCounter
@ kUpDownCounter
sdk::metrics::DefaultAggregation::CloneAggregation
static std::unique_ptr< Aggregation > CloneAggregation(AggregationType aggregation_type, const InstrumentDescriptor &instrument_descriptor, const Aggregation &to_copy)
Definition: includes/opentelemetry/sdk/metrics/aggregation/default_aggregation.h:121
sdk
Definition: includes/opentelemetry/sdk/common/atomic_shared_ptr.h:13
sdk::metrics::AggregationType::kSum
@ kSum
metrics
Definition: includes/opentelemetry/metrics/async_instruments.h:10
sdk::metrics::InstrumentType::kObservableUpDownCounter
@ kObservableUpDownCounter
sdk::metrics::InstrumentDescriptor
Definition: includes/opentelemetry/sdk/metrics/instruments.h:61
sdk::metrics::AggregationType::kDefault
@ kDefault
sdk::metrics::PointType
opentelemetry::nostd::variant< SumPointData, HistogramPointData, Base2ExponentialHistogramPointData, LastValuePointData, DropPointData > PointType
Definition: includes/opentelemetry/sdk/metrics/data/metric_data.h:25
sdk::metrics::DefaultAggregation::CreateAggregation
static std::unique_ptr< Aggregation > CreateAggregation(const opentelemetry::sdk::metrics::InstrumentDescriptor &instrument_descriptor, const AggregationConfig *aggregation_config)
Definition: includes/opentelemetry/sdk/metrics/aggregation/default_aggregation.h:28
sdk::metrics::DefaultAggregation
Definition: includes/opentelemetry/sdk/metrics/aggregation/default_aggregation.h:25
sdk::metrics::InstrumentType
InstrumentType
Definition: includes/opentelemetry/sdk/metrics/instruments.h:19
sdk::metrics::InstrumentDescriptor::value_type_
InstrumentValueType value_type_
Definition: includes/opentelemetry/sdk/metrics/instruments.h:67
sdk::metrics::LongHistogramAggregation
Definition: includes/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h:27
sdk::metrics::DropAggregation
A null Aggregation which denotes no aggregation should occur.
Definition: includes/opentelemetry/sdk/metrics/aggregation/drop_aggregation.h:22
sdk::metrics::InstrumentType::kObservableCounter
@ kObservableCounter