forked from open-telemetry/opentelemetry-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added hard-copy of https://github.com/open-telemetry/opentelemetry-cp…
…p-contrib/tree/main/exporters/prometheus (the push exporter) in this repo
- Loading branch information
1 parent
26033a1
commit f42c42c
Showing
12 changed files
with
1,040 additions
and
6 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
131 changes: 131 additions & 0 deletions
131
exporters/prometheus/include/opentelemetry/exporters/prometheus/push_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,131 @@ | ||
// Copyright 2023, OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#ifndef WIN32_LEAN_AND_MEAN | ||
# define WIN32_LEAN_AND_MEAN | ||
#endif | ||
|
||
#ifndef NOMINMAX | ||
# define NOMINMAX | ||
#endif | ||
|
||
#ifdef _WIN32 | ||
# include <io.h> // NOLINT | ||
# include <winsock2.h> // NOLINT | ||
#else | ||
# include <unistd.h> // NOLINT | ||
#endif | ||
|
||
#include <chrono> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "opentelemetry/version.h" | ||
#include "prometheus/gateway.h" | ||
|
||
#include "opentelemetry/exporters/prometheus/exporter_utils.h" | ||
#include "opentelemetry/exporters/prometheus/push_exporter_options.h" | ||
#include "opentelemetry/nostd/span.h" | ||
#include "opentelemetry/sdk/common/env_variables.h" | ||
#include "opentelemetry/sdk/metrics/push_metric_exporter.h" | ||
|
||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace exporter | ||
{ | ||
namespace metrics | ||
{ | ||
|
||
class PrometheusPushCollector; | ||
|
||
class PrometheusPushExporter : public ::opentelemetry::sdk::metrics::PushMetricExporter | ||
{ | ||
public: | ||
/** | ||
* Constructor - binds an exposer and collector to the exporter | ||
* @param options: options for an exposer that exposes | ||
* an HTTP endpoint for the exporter to connect to | ||
*/ | ||
explicit PrometheusPushExporter(const PrometheusPushExporterOptions &options); | ||
|
||
/** | ||
* Get the AggregationTemporality for Prometheus exporter | ||
* | ||
* @return AggregationTemporality | ||
*/ | ||
::opentelemetry::sdk::metrics::AggregationTemporality GetAggregationTemporality( | ||
::opentelemetry::sdk::metrics::InstrumentType instrument_type) const noexcept override; | ||
|
||
/** | ||
* 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 | ||
*/ | ||
::opentelemetry::sdk::common::ExportResult Export( | ||
const ::opentelemetry::sdk::metrics::ResourceMetrics &data) noexcept override; | ||
|
||
/** | ||
* Force flush the exporter. | ||
*/ | ||
bool ForceFlush( | ||
std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) 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. | ||
*/ | ||
bool Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override; | ||
|
||
/** | ||
* Gets the maximum size of the collection. | ||
* | ||
* @return max collection size | ||
*/ | ||
std::size_t GetMaxCollectionSize() const noexcept; | ||
|
||
/** | ||
* @return: Gets the shutdown status of the exporter | ||
*/ | ||
bool IsShutdown() const; | ||
|
||
private: | ||
// The configuration options associated with this exporter. | ||
const PrometheusPushExporterOptions options_; | ||
/** | ||
* exporter shutdown status | ||
*/ | ||
bool is_shutdown_; | ||
|
||
/** | ||
* Pointer to a | ||
* PrometheusCollector instance | ||
*/ | ||
std::shared_ptr<PrometheusPushCollector> collector_; | ||
|
||
/** | ||
* Pointer to an | ||
* Gateway instance | ||
*/ | ||
std::unique_ptr<::prometheus::Gateway> gateway_; | ||
|
||
/** | ||
* friend class for testing | ||
*/ | ||
friend class PrometheusPushExporterTest; | ||
|
||
/** | ||
* PrometheusPushExporter constructor with no parameters | ||
* Used for testing only | ||
*/ | ||
PrometheusPushExporter(); | ||
}; | ||
|
||
} // namespace metrics | ||
} // namespace exporter | ||
OPENTELEMETRY_END_NAMESPACE |
34 changes: 34 additions & 0 deletions
34
exporters/prometheus/include/opentelemetry/exporters/prometheus/push_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,34 @@ | ||
// Copyright 2023, OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "opentelemetry/version.h" | ||
#include "opentelemetry/sdk/metrics/push_metric_exporter.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace exporter | ||
{ | ||
namespace metrics | ||
{ | ||
|
||
struct PrometheusPushExporterOptions; | ||
|
||
/** | ||
* Factory class for PrometheusExporter. | ||
*/ | ||
class PrometheusPushExporterFactory | ||
{ | ||
public: | ||
/** | ||
* Create a PrometheusExporter using the given options. | ||
*/ | ||
static std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> Create( | ||
const PrometheusPushExporterOptions &options); | ||
}; | ||
|
||
} // namespace metrics | ||
} // namespace exporter | ||
OPENTELEMETRY_END_NAMESPACE |
37 changes: 37 additions & 0 deletions
37
exporters/prometheus/include/opentelemetry/exporters/prometheus/push_exporter_options.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,37 @@ | ||
// Copyright 2023, OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace exporter | ||
{ | ||
namespace metrics | ||
{ | ||
|
||
/** | ||
* Struct to hold Prometheus exporter options. | ||
*/ | ||
struct PrometheusPushExporterOptions | ||
{ | ||
std::string host; | ||
std::string port; | ||
std::string jobname; | ||
std::unordered_map<std::string, std::string> labels; | ||
std::string username; | ||
std::string password; | ||
|
||
std::size_t max_collection_size = 2000; | ||
|
||
inline PrometheusPushExporterOptions() noexcept {} | ||
}; | ||
|
||
} // namespace metrics | ||
} // namespace exporter | ||
OPENTELEMETRY_END_NAMESPACE |
Oops, something went wrong.