-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
991 additions
and
41 deletions.
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
87 changes: 87 additions & 0 deletions
87
exporters/prometheus/include/opentelemetry/exporters/prometheus/collector.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,87 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
|
||
# include <memory> | ||
# include <mutex> | ||
# include <vector> | ||
|
||
# include <prometheus/collectable.h> | ||
# include <prometheus/metric_family.h> | ||
# include "opentelemetry/exporters/prometheus/exporter_utils.h" | ||
|
||
namespace prometheus_client = ::prometheus; | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace exporter | ||
{ | ||
namespace metrics | ||
{ | ||
/** | ||
* The Prometheus Collector maintains the intermediate collection in Prometheus Exporter | ||
*/ | ||
class PrometheusCollector : public prometheus_client::Collectable | ||
{ | ||
public: | ||
/** | ||
* Default Constructor. | ||
* | ||
* This constructor initializes the collection for metrics to export | ||
* in this class with default capacity | ||
*/ | ||
explicit PrometheusCollector(size_t max_collection_size = 2048); | ||
|
||
/** | ||
* Collects all metrics data from metricsToCollect collection. | ||
* | ||
* @return all metrics in the metricsToCollect snapshot | ||
*/ | ||
std::vector<prometheus_client::MetricFamily> Collect() const override; | ||
|
||
/** | ||
* This function is called by export() function and add the collection of | ||
* records to the metricsToCollect collection | ||
* | ||
* @param records a collection of records to add to the metricsToCollect collection | ||
*/ | ||
void AddMetricData(const sdk::metrics::ResourceMetrics &data); | ||
|
||
/** | ||
* Get the current collection in the collector. | ||
* | ||
* @return the current metricsToCollect collection | ||
*/ | ||
std::vector<std::unique_ptr<sdk::metrics::ResourceMetrics>> &GetCollection(); | ||
|
||
/** | ||
* Gets the maximum size of the collection. | ||
* | ||
* @return max collection size | ||
*/ | ||
int GetMaxCollectionSize() const; | ||
|
||
private: | ||
/** | ||
* Collection of metrics data from the export() function, and to be export | ||
* to user when they send a pull request. This collection is a pointer | ||
* to a collection so Collect() is able to clear the collection, even | ||
* though it is a const function. | ||
*/ | ||
mutable std::vector<std::unique_ptr<sdk::metrics::ResourceMetrics>> metrics_to_collect_; | ||
|
||
/** | ||
* Maximum size of the metricsToCollect collection. | ||
*/ | ||
size_t max_collection_size_; | ||
|
||
/* | ||
* Lock when operating the metricsToCollect collection | ||
*/ | ||
mutable std::mutex collection_lock_; | ||
}; | ||
} // namespace metrics | ||
} // namespace exporter | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif |
Oops, something went wrong.
e6fb935
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BM_BaselineBuffer/4
14097092.151641846
ns/iter6500868.797302246
ns/iter2.17
This comment was automatically generated by workflow using github-action-benchmark.