-
Notifications
You must be signed in to change notification settings - Fork 446
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
Add Prometheus Exporter #1031
Add Prometheus Exporter #1031
Changes from 73 commits
38f811a
140efcd
feb7126
5d6fc7e
845d6f1
32880b0
61783a7
b8d8f5a
94af70d
550bb7f
367d6a3
a5e2cfb
6bbb051
d3d44f3
8dc5cb1
94f78c8
5938aa8
dc28f84
75e23e5
f9a4dda
0a5fb81
2251d49
81d1c1c
b85f648
2f480c0
99ca914
605e42f
87e4223
c83723d
4ef1e90
9e8dcdb
ba7bb88
8267094
81db277
e3ad09c
99572e0
a22933e
5055c68
5023d44
347caa6
8e7abd3
0195f4b
1cb72fe
8a463b2
d1fc9d4
673f1bb
825373f
b4df355
f96756e
9fccc94
d7d7010
9085479
e0c974a
f1aadef
b33edf9
69de0e8
fd32df6
f7da657
2986e8c
bc872ed
1859eca
80c811b
398256d
3d424d2
5e3b456
f54b772
6ca2e10
032bfb9
4d4f0ef
ef20e67
908e19d
f6f5c8b
4648358
5f2744a
bdd2a7b
ba8e877
5052fd5
abc06b7
d1c226e
a6f3315
6c0e4d3
c93caf7
8ff4d7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,6 @@ BAZEL_STARTUP_OPTIONS="--output_user_root=$HOME/.cache/bazel" | |
export CTEST_OUTPUT_ON_FAILURE=1 | ||
|
||
if [[ "$1" == "cmake.test" ]]; then | ||
install_prometheus_cpp_client | ||
cd "${BUILD_DIR}" | ||
rm -rf * | ||
cmake -DCMAKE_BUILD_TYPE=Debug \ | ||
|
@@ -85,6 +84,7 @@ elif [[ "$1" == "cmake.c++20.stl.test" ]]; then | |
make test | ||
exit 0 | ||
elif [[ "$1" == "cmake.legacy.test" ]]; then | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove this empty line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
cd "${BUILD_DIR}" | ||
rm -rf * | ||
export BUILD_ROOT="${BUILD_DIR}" | ||
|
@@ -93,6 +93,7 @@ elif [[ "$1" == "cmake.legacy.test" ]]; then | |
cmake -DCMAKE_BUILD_TYPE=Debug \ | ||
-DCMAKE_CXX_FLAGS="-Werror" \ | ||
-DCMAKE_CXX_STANDARD=11 \ | ||
-DCMAKE_EXE_LINKER_FLAGS="-lpthread" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was not needed. cleaned |
||
"${SRC_DIR}" | ||
make | ||
make test | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify the copyright header as below? // Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
#ifdef ENABLE_METRICS_PREVIEW | ||
# include <memory> | ||
# include <string> | ||
# include <vector> | ||
|
||
# include "opentelemetry/exporters/prometheus/prometheus_collector.h" | ||
# include "opentelemetry/sdk/metrics/exporter.h" | ||
# include "opentelemetry/sdk/metrics/record.h" | ||
# include "opentelemetry/version.h" | ||
# include "prometheus/exposer.h" | ||
|
||
/** | ||
* This class is an implementation of the MetricsExporter interface and | ||
* exports Prometheus metrics data. Functions in this class should be | ||
* called by the Controller in our data pipeline. | ||
*/ | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace sdkmetrics = opentelemetry::sdk::metrics; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: not recommended to use the namespace alias in the header file, as it becomes part of public API. It's been used all over the code right now and #1008 should be fixing it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
namespace exporter | ||
{ | ||
namespace prometheus | ||
{ | ||
class PrometheusExporter : public sdkmetrics::MetricsExporter | ||
{ | ||
public: | ||
/** | ||
* Constructor - binds an exposer and collector to the exporter | ||
* @param address: an address for an exposer that exposes | ||
* an HTTP endpoint for the exporter to connect to | ||
*/ | ||
PrometheusExporter(std::string &address); | ||
|
||
/** | ||
* Exports a batch of Metric Records. | ||
* @param records: a collection of records to export | ||
* @return: returns a ReturnCode detailing a success, or type of failure | ||
*/ | ||
sdk::common::ExportResult Export( | ||
const std::vector<sdkmetrics::Record> &records) noexcept override; | ||
|
||
/** | ||
* Shuts down the exporter and does cleanup. | ||
* Since Prometheus is a pull based interface, | ||
* we cannot serve data remaining in the intermediate | ||
* collection to to client an HTTP request being sent, | ||
* so we flush the data. | ||
*/ | ||
void Shutdown() noexcept; | ||
|
||
/** | ||
* @return: returns a shared_ptr to | ||
* the PrometheusCollector instance | ||
*/ | ||
std::shared_ptr<PrometheusCollector> &GetCollector(); | ||
|
||
/** | ||
* @return: Gets the shutdown status of the exporter | ||
*/ | ||
bool IsShutdown() const; | ||
|
||
private: | ||
/** | ||
* exporter shutdown status | ||
*/ | ||
bool is_shutdown_; | ||
|
||
/** | ||
* Pointer to a | ||
* PrometheusCollector instance | ||
*/ | ||
std::shared_ptr<PrometheusCollector> collector_; | ||
|
||
/** | ||
* Pointer to an | ||
* Exposer instance | ||
*/ | ||
std::unique_ptr<::prometheus::Exposer> exposer_; | ||
|
||
/** | ||
* friend class for testing | ||
*/ | ||
friend class PrometheusExporterTest; | ||
|
||
/** | ||
* PrometheusExporter constructor with no parameters | ||
* Used for testing only | ||
*/ | ||
PrometheusExporter(); | ||
}; | ||
} // namespace prometheus | ||
} // namespace exporter | ||
OPENTELEMETRY_END_NAMESPACE | ||
#endif // ENABLE_METRICS_PREVIEW |
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.
This should be put into the above section for "Unreleased".
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.
done