-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1405
- Loading branch information
Showing
11 changed files
with
564 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_data.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <map> | ||
#include <memory> | ||
#include <string> | ||
#include <tuple> | ||
|
||
#include "opentelemetry/exporters/memory/in_memory_data.h" | ||
#include "opentelemetry/sdk/metrics/data/metric_data.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
struct ResourceMetrics; | ||
} | ||
} // namespace sdk | ||
namespace exporter | ||
{ | ||
namespace memory | ||
{ | ||
|
||
/// The abstract base class for types used to store in-memory data backing an | ||
/// InMemoryMetricExporter. | ||
class InMemoryMetricData | ||
{ | ||
public: | ||
InMemoryMetricData(){}; | ||
InMemoryMetricData(const InMemoryMetricData &) = delete; | ||
InMemoryMetricData(InMemoryMetricData &&) = delete; | ||
InMemoryMetricData &operator=(const InMemoryMetricData &) = delete; | ||
InMemoryMetricData &operator=(InMemoryMetricData &&) = delete; | ||
|
||
virtual ~InMemoryMetricData() = default; | ||
|
||
virtual void Add(std::unique_ptr<sdk::metrics::ResourceMetrics> resource_metrics) = 0; | ||
}; | ||
|
||
/// An implementation of InMemoryMetricData that stores full-fidelity data points in a circular | ||
/// buffer. This allows tests to inspect every aspect of exported data, in exchange for a somewhat | ||
/// cumbersome API. | ||
class CircularBufferInMemoryMetricData final : public InMemoryMetricData, | ||
public InMemoryData<sdk::metrics::ResourceMetrics> | ||
{ | ||
public: | ||
explicit CircularBufferInMemoryMetricData(size_t buffer_size); | ||
void Add(std::unique_ptr<sdk::metrics::ResourceMetrics> resource_metrics) override; | ||
}; | ||
|
||
/// An implementation of InMemoryMetricData that stores only the most recent data point in each time | ||
/// series, and allows convenient lookups of time series. This makes simple tests easier to write. | ||
class SimpleAggregateInMemoryMetricData final : public InMemoryMetricData | ||
{ | ||
public: | ||
using AttributeToPoint = std::map<opentelemetry::sdk::metrics::PointAttributes, | ||
opentelemetry::sdk::metrics::PointType>; | ||
|
||
void Add(std::unique_ptr<sdk::metrics::ResourceMetrics> resource_metrics) override; | ||
const AttributeToPoint &Get(const std::string &scope, const std::string &metric); | ||
void Clear(); | ||
|
||
private: | ||
std::map<std::tuple<std::string, std::string>, AttributeToPoint> data_; | ||
}; | ||
|
||
} // namespace memory | ||
} // namespace exporter | ||
OPENTELEMETRY_END_NAMESPACE |
56 changes: 56 additions & 0 deletions
56
exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_exporter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <atomic> | ||
#include <vector> | ||
|
||
#include "opentelemetry/sdk/metrics/export/metric_producer.h" | ||
#include "opentelemetry/sdk/metrics/instruments.h" | ||
#include "opentelemetry/sdk/metrics/push_metric_exporter.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace exporter | ||
{ | ||
namespace memory | ||
{ | ||
|
||
class InMemoryMetricData; | ||
|
||
/// A Push Metric Exporter which accumulates metrics data in memory and allows it to be inspected. | ||
/// It is not thread-safe. | ||
class InMemoryMetricExporter final : public sdk::metrics::PushMetricExporter | ||
{ | ||
using AggregationTemporalityMap = | ||
std::map<sdk::metrics::InstrumentType, sdk::metrics::AggregationTemporality>; | ||
|
||
public: | ||
/// @param buffer_size a required value that sets the size of the CircularBuffer | ||
/// @param temporality Output temporality as a function of instrument kind. | ||
InMemoryMetricExporter(const std::shared_ptr<InMemoryMetricData> &data, | ||
const sdk::metrics::AggregationTemporalitySelector &temporality); | ||
|
||
InMemoryMetricExporter(const InMemoryMetricExporter &) = delete; | ||
InMemoryMetricExporter(const InMemoryMetricExporter &&) = delete; | ||
void operator=(const InMemoryMetricExporter &) = delete; | ||
void operator=(const InMemoryMetricExporter &&) = delete; | ||
~InMemoryMetricExporter() override = default; | ||
|
||
sdk::common::ExportResult Export(const sdk::metrics::ResourceMetrics &data) noexcept override; | ||
sdk::metrics::AggregationTemporality GetAggregationTemporality( | ||
sdk::metrics::InstrumentType instrument_type) const noexcept override; | ||
bool ForceFlush( | ||
std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override; | ||
bool Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override; | ||
|
||
private: | ||
std::shared_ptr<InMemoryMetricData> data_; | ||
std::atomic<bool> is_shutdown_{false}; | ||
sdk::metrics::AggregationTemporalitySelector temporality_; | ||
}; | ||
|
||
} // namespace memory | ||
} // namespace exporter | ||
OPENTELEMETRY_END_NAMESPACE |
44 changes: 44 additions & 0 deletions
44
exporters/memory/include/opentelemetry/exporters/memory/in_memory_metric_exporter_factory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "opentelemetry/sdk/metrics/instruments.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdk | ||
{ | ||
namespace metrics | ||
{ | ||
class PushMetricExporter; | ||
} // namespace metrics | ||
} // namespace sdk | ||
namespace exporter | ||
{ | ||
namespace memory | ||
{ | ||
class InMemoryMetricData; | ||
|
||
/// A factory for InMemoryMetricExporter | ||
class InMemoryMetricExporterFactory | ||
{ | ||
public: | ||
/// Create a InMemoryMetricExporter with a default buffer size and aggregation | ||
/// temporality selector. | ||
/// @param [out] data the InMemoryMetricData the exporter will write to, | ||
/// for the caller to inspect | ||
/// @param [in] buffer_size number of entries to save in the circular buffer | ||
/// @param [in] temporality output temporality as a function of instrument kind | ||
static std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> Create( | ||
const std::shared_ptr<InMemoryMetricData> &data, | ||
const sdk::metrics::AggregationTemporalitySelector &temporality); | ||
|
||
static std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> Create( | ||
const std::shared_ptr<InMemoryMetricData> &data); | ||
}; | ||
} // namespace memory | ||
} // namespace exporter | ||
OPENTELEMETRY_END_NAMESPACE |
Oops, something went wrong.