Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ namespace metrics
*/
struct PrometheusExporterOptions
{
// Lookup environment variables
PrometheusExporterOptions();

// No defaults
PrometheusExporterOptions(void *);

// The endpoint the Prometheus backend can collect metrics from
std::string url;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <memory>

#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_builder.h"
#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/registry.h"
#include "opentelemetry/sdk/metrics/metric_reader.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace metrics
{

class OPENTELEMETRY_EXPORT PrometheusPullBuilder
: public opentelemetry::sdk::configuration::PrometheusPullMetricExporterBuilder
{
public:
static void Register(opentelemetry::sdk::configuration::Registry *registry);

std::unique_ptr<opentelemetry::sdk::metrics::MetricReader> Build(
const opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *model)
const override;
};

} // namespace metrics
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
2 changes: 2 additions & 0 deletions exporters/prometheus/src/exporter_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ PrometheusExporterOptions::PrometheusExporterOptions()
without_type_suffix(GetPrometheusWithoutTypeSuffix())
{}

PrometheusExporterOptions::PrometheusExporterOptions(void *) : url("") {}

} // namespace metrics
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
49 changes: 49 additions & 0 deletions exporters/prometheus/src/prometheus_pull_builder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <memory>
#include <string>
#include <utility>

#include "opentelemetry/exporters/prometheus/exporter_factory.h"
#include "opentelemetry/exporters/prometheus/exporter_options.h"
#include "opentelemetry/exporters/prometheus/prometheus_pull_builder.h"
#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_builder.h"
#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h"
#include "opentelemetry/sdk/configuration/registry.h"
#include "opentelemetry/sdk/metrics/metric_reader.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace metrics
{

void PrometheusPullBuilder::Register(opentelemetry::sdk::configuration::Registry *registry)
{
auto builder = std::make_unique<PrometheusPullBuilder>();
registry->SetPrometheusPullMetricExporterBuilder(std::move(builder));
}

std::unique_ptr<opentelemetry::sdk::metrics::MetricReader> PrometheusPullBuilder::Build(
const opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *model) const
{
opentelemetry::exporter::metrics::PrometheusExporterOptions options(nullptr);

std::string url(model->host);
url.append(":");
url.append(std::to_string(model->port));

options.url = url;
options.populate_target_info = true;
options.without_otel_scope = model->without_scope_info;
options.without_units = model->without_units;
options.without_type_suffix = model->without_type_suffix;

return PrometheusExporterFactory::Create(options);
}

} // namespace metrics
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
Loading