Skip to content

Commit

Permalink
Merge branch 'main' into fix_breaking_getmeter_2033
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Sep 26, 2023
2 parents 1ac42b6 + a4961c4 commit a53ff4e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ The C++ [OpenTelemetry](https://opentelemetry.io/) client.

## Project Status

| Signal | Status | Project |
| ------- | ----------------------- | ------------------------------------------------------------------------ |
| Traces | Public Release | N/A |
| Metrics | Public Release | N/A |
| Logs | Public Release | N/A |
**Stable** across all 3 signals i.e. `Logs`, `Metrics`, and `Traces`.

See [Spec Compliance
Matrix](https://github.com/open-telemetry/opentelemetry-specification/blob/main/spec-compliance-matrix.md)
to understand which portions of the specification has been implemented in this
repo.

## Supported C++ Versions

Expand Down Expand Up @@ -119,8 +120,6 @@ Maintainer/Approver/Triager](https://github.com/open-telemetry/community/blob/ma

## Release Schedule

Refer to [project status](#project-status) for current status of the project.

See the [release
notes](https://github.com/open-telemetry/opentelemetry-cpp/releases) for
existing releases.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ class PrometheusExporterUtils
const std::vector<double> &boundaries,
const std::vector<uint64_t> &counts,
::prometheus::ClientMetric *metric);

// For testing
friend class SanitizeNameTester;
};
} // namespace metrics
} // namespace exporter
Expand Down
48 changes: 26 additions & 22 deletions exporters/prometheus/test/exporter_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@ namespace prometheus_client = ::prometheus;

OPENTELEMETRY_BEGIN_NAMESPACE

namespace exporter
{
namespace metrics
{
class SanitizeNameTester
{
public:
static std::string sanitize(std::string name)
{
return PrometheusExporterUtils::SanitizeNames(name);
}
};
} // namespace metrics
} // namespace exporter

template <typename T>
void assert_basic(prometheus_client::MetricFamily &metric,
const std::string &sanitized_name,
Expand Down Expand Up @@ -153,14 +138,33 @@ TEST(PrometheusExporterUtils, TranslateToPrometheusHistogramNormal)
assert_histogram(metric, std::list<double>{10.1, 20.2, 30.2}, {200, 300, 400, 500});
}

TEST(PrometheusExporterUtils, SanitizeName)
class SanitizeNameTest : public ::testing::Test
{
Resource resource_ = Resource::Create({});
nostd::unique_ptr<InstrumentationScope> instrumentation_scope_ =
InstrumentationScope::Create("library_name", "1.2.0");

protected:
void CheckSanitation(const std::string &original, const std::string &sanitized)
{
metric_sdk::InstrumentDescriptor instrument_descriptor_{
original, "description", "unit", metric_sdk::InstrumentType::kCounter,
metric_sdk::InstrumentValueType::kDouble};
std::vector<prometheus::MetricFamily> result = PrometheusExporterUtils::TranslateToPrometheus(
{&resource_,
{{instrumentation_scope_.get(), {{instrument_descriptor_, {}, {}, {}, {{{}, {}}}}}}}});
EXPECT_EQ(result.begin()->name, sanitized + "_unit");
}
};

TEST_F(SanitizeNameTest, All)
{
ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name"), "name");
ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?"), "name_");
ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name???"), "name_");
ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?__"), "name_");
ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?__name"), "name_name");
ASSERT_EQ(exporter::metrics::SanitizeNameTester::sanitize("name?__name:"), "name_name:");
CheckSanitation("name", "name");
CheckSanitation("name?", "name_");
CheckSanitation("name???", "name_");
CheckSanitation("name?__", "name_");
CheckSanitation("name?__name", "name_name");
CheckSanitation("name?__name:", "name_name:");
}

class AttributeCollisionTest : public ::testing::Test
Expand Down
7 changes: 4 additions & 3 deletions sdk/src/metrics/meter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ std::unique_ptr<SyncWritableMetricStorage> Meter::RegisterSyncMetricStorage(
auto ctx = meter_context_.lock();
if (!ctx)
{
OTEL_INTERNAL_LOG_ERROR("[Meter::RegisterMetricStorage] - Error during finding matching views."
<< "The metric context is invalid");
OTEL_INTERNAL_LOG_ERROR(
"[Meter::RegisterSyncMetricStorage] - Error during finding matching views."
<< "The metric context is invalid");
return nullptr;
}
auto view_registry = ctx->GetViewRegistry();
Expand Down Expand Up @@ -335,7 +336,7 @@ std::unique_ptr<SyncWritableMetricStorage> Meter::RegisterSyncMetricStorage(
if (!success)
{
OTEL_INTERNAL_LOG_ERROR(
"[Meter::RegisterMetricStorage] - Error during finding matching views."
"[Meter::RegisterSyncMetricStorage] - Error during finding matching views."
<< "Some of the matching view configurations mayn't be used for metric collection");
}
return storages;
Expand Down

0 comments on commit a53ff4e

Please sign in to comment.