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

[WIP] Implement Aggregation Storage #1198

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# include <vector>
# include "opentelemetry/_metrics/instrument.h"
# include "opentelemetry/sdk/_metrics/aggregator/aggregator.h"
# include "opentelemetry/sdk/metrics/"
# include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class InstrumentMonotonicityAwareAggregation
class Aggregation
{
public:
virtual void Aggregate(long value, const PointAttributes &attributes = {}) noexcept = 0;
virtual void Aggregate(long value) noexcept = 0;

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

virtual PointType Collect() noexcept = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class DropAggregation : public Aggregation
public:
DropAggregation() = default;

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

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

PointType Collect() noexcept override { return DropPointData(); }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class LongHistogramAggregation : public Aggregation
public:
LongHistogramAggregation();

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

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

PointType Collect() noexcept override;

Expand All @@ -52,9 +52,9 @@ class DoubleHistogramAggregation : public Aggregation
public:
DoubleHistogramAggregation();

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

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

PointType Collect() noexcept override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class LongLastValueAggregation : public Aggregation
public:
LongLastValueAggregation();

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

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

PointType Collect() noexcept override;

Expand All @@ -35,9 +35,9 @@ class DoubleLastValueAggregation : public Aggregation
public:
DoubleLastValueAggregation();

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

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

PointType Collect() noexcept override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class LongSumAggregation : public Aggregation, InstrumentMonotonicityAwareAggreg
public:
LongSumAggregation(bool is_monotonic);

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

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

PointType Collect() noexcept override;

Expand All @@ -50,9 +50,9 @@ class DoubleSumAggregation : public Aggregation, InstrumentMonotonicityAwareAggr
public:
DoubleSumAggregation(bool is_monotonic);

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

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

PointType Collect() noexcept override;

Expand Down
5 changes: 2 additions & 3 deletions sdk/include/opentelemetry/sdk/metrics/data/metric_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ namespace sdk
namespace metrics
{

using PointAttributes = opentelemetry::sdk::common::AttributeMap;
using PointType = opentelemetry::nostd::
using PointType = opentelemetry::nostd::
variant<SumPointData, HistogramPointData, LastValuePointData, DropPointData>;

class MetricData
{
public:
opentelemetry::sdk::resource::Resource *resource_;
opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary *instrumentation_library_;
PointAttributes attributes_;
MetricAttributes attributes_;
InstrumentDescriptor instrument_descriptor;
PointType point_data_;
};
Expand Down
8 changes: 1 addition & 7 deletions sdk/include/opentelemetry/sdk/metrics/data/point_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef ENABLE_METRICS_PREVIEW
# include "opentelemetry/common/timestamp.h"
# include "opentelemetry/nostd/variant.h"
# include "opentelemetry/sdk/metrics/instruments.h"
# include "opentelemetry/version.h"

# include <vector>
Expand All @@ -18,13 +19,6 @@ namespace metrics
using ValueType = nostd::variant<long, double>;
using ListType = nostd::variant<std::vector<long>, std::vector<double>>;

enum class AggregationTemporarily
{
kUnspecified,
kDelta,
kCummulative
};

class SumPointData
{
public:
Expand Down
21 changes: 21 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
#pragma once
#ifndef ENABLE_METRICS_PREVIEW
# include "opentelemetry/nostd/string_view.h"
# include "opentelemetry/sdk/common/attribute_utils.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace metrics
{

typedef opentelemetry::sdk::common::OrderedAttributeMap MetricAttributes;

enum class InstrumentType
{
kCounter,
Expand All @@ -27,6 +32,22 @@ enum class InstrumentValueType
kDouble
};

enum class AggregationType
{
kDefault,
kDrop,
kLastValue,
kSum,
kHistogram
};

enum class AggregationTemporarily
{
kUnspecified,
kDelta,
kCummulative
};

struct InstrumentDescriptor
{
std::string name_;
Expand Down
73 changes: 73 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once
#ifndef ENABLE_METRICS_PREVIEW
# include "opentelemetry/common/key_value_iterable_view.h"
# include "opentelemetry/sdk/metrics/data/metric_data.h"
# include "opentelemetry/sdk/metrics/instruments.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace metrics
{

/* Represent the storage from which to collect the metrics */

class MetricStorage
{
public:
/* collect the metrics from this storage */
virtual bool Collect(AggregationTemporarily aggregation_temporarily,
nostd::function_ref<bool(MetricData)> callback) noexcept = 0;
};

class WritableMetricStorage
{
public:
virtual void RecordLong(long value) noexcept = 0;

virtual void RecordLong(long value,
const opentelemetry::common::KeyValueIterable &attributes) noexcept = 0;

virtual void RecordDouble(double value) noexcept = 0;

virtual void RecordDouble(double value,
const opentelemetry::common::KeyValueIterable &attributes) noexcept = 0;
};

class NoopMetricStorage : public MetricStorage
{
public:
bool Collect(AggregationTemporarily aggregation_temporarily,
nostd::function_ref<bool(MetricData)> callback) noexcept override
{
MetricData metric_data;
if (callback(metric_data))
{
return true;
}
return false;
}
};

class NoopWritableMetricStorage : public WritableMetricStorage
{
public:
void RecordLong(long value) noexcept = 0;

void RecordLong(long value,
const opentelemetry::common::KeyValueIterable &attributes) noexcept override
{}

void RecordDouble(double value) noexcept override {}

void RecordDouble(double value,
const opentelemetry::common::KeyValueIterable &attributes) noexcept override
{}
};

} // namespace metrics
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
#endif
Loading