-
Notifications
You must be signed in to change notification settings - Fork 440
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
prometheus exporter #1331
Merged
Merged
prometheus exporter #1331
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
44ef6fc
prometheus exporter
esigo 55ef85f
Merge branch 'main' into prometheus-exporter
esigo ed104a7
comments
esigo 021a1ee
Merge branch 'main' into prometheus-exporter
esigo abe26ce
Merge branch 'main' into prometheus-exporter
lalitb 4aeeea1
comments
esigo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We also need to modify the root CMakeLists.txt to build prometheus even if WITH_METRICS_PREVIEW is not enabled?
Also need to modify test CMakeLists.txt to build the tests only if WITH_METRICS_PREVIEW is enabled.
Also can we raise a github issue to add unit-tests so that we don't miss adding them?
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.
Thanks, fixed cmake and added a new issue #1349 for unit tests.