Skip to content
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

feat(otel): release GCM exporter #14693

Merged
merged 2 commits into from
Sep 10, 2024
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 @@ -114,8 +114,7 @@ TEST(MonitoringExporter, Basic) {
auto project = Project(project_id);
auto conn = monitoring_v3::MakeMetricServiceConnection();
auto client = monitoring_v3::MetricServiceClient(conn);
auto exporter =
otel_internal::MakeMonitoringExporter(project, std::move(conn));
auto exporter = MakeMonitoringExporter(project, std::move(conn));
InstallExporter(std::move(exporter), task_id);

// Perform work which creates telemetry. An export should happen.
Expand Down
11 changes: 6 additions & 5 deletions google/cloud/opentelemetry/monitoring_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace google {
namespace cloud {
namespace otel_internal {
namespace otel {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

Expand Down Expand Up @@ -73,14 +73,15 @@ class MonitoringExporter final
opentelemetry::sdk::metrics::ResourceMetrics const& data) {
auto result = opentelemetry::sdk::common::ExportResult::kSuccess;

auto tss = ToTimeSeries(data, formatter_);
auto tss = otel_internal::ToTimeSeries(data, formatter_);
if (tss.empty()) {
GCP_LOG(INFO) << "Cloud Monitoring Export skipped. No data.";
// Return early to save the littlest bit of processing.
return result;
}
auto mr = ToMonitoredResource(data, mr_proto_);
auto requests = ToRequests(project_.FullName(), mr, std::move(tss));
auto mr = otel_internal::ToMonitoredResource(data, mr_proto_);
auto requests =
otel_internal::ToRequests(project_.FullName(), mr, std::move(tss));
for (auto& request : requests) {
auto status = use_service_time_series_
? client_.CreateServiceTimeSeries(request)
Expand Down Expand Up @@ -121,6 +122,6 @@ MakeMonitoringExporter(
}

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace otel_internal
} // namespace otel
} // namespace cloud
} // namespace google
4 changes: 2 additions & 2 deletions google/cloud/opentelemetry/monitoring_exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace google {
namespace cloud {
namespace otel_internal {
namespace otel {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ MakeMonitoringExporter(
Options options = {});

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace otel_internal
} // namespace otel
} // namespace cloud
} // namespace google

Expand Down
34 changes: 17 additions & 17 deletions google/cloud/opentelemetry/monitoring_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ TEST(MonitoringExporter, ExportSuccess) {
return Status();
});

auto exporter = otel_internal::MakeMonitoringExporter(Project("test-project"),
std::move(mock));
auto exporter =
MakeMonitoringExporter(Project("test-project"), std::move(mock));
auto const expected_time_series_count = kMaxTimeSeriesPerRequest + 1;
auto data = MakeResourceMetrics(expected_time_series_count);
auto result = exporter->Export(data);
Expand All @@ -121,8 +121,8 @@ TEST(MonitoringExporter, ExportSkippedIfNoTimeSeries) {
std::make_shared<monitoring_v3_mocks::MockMetricServiceConnection>();
EXPECT_CALL(*mock, CreateTimeSeries).Times(0);

auto exporter = otel_internal::MakeMonitoringExporter(Project("test-project"),
std::move(mock));
auto exporter =
MakeMonitoringExporter(Project("test-project"), std::move(mock));
auto data = MakeResourceMetrics(/*expected_time_series_count=*/0);
auto result = exporter->Export(data);
EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess);
Expand Down Expand Up @@ -161,8 +161,8 @@ TEST(MonitoringExporter, ExportFailure) {
return internal::PermissionDeniedError("nope");
});

auto exporter = otel_internal::MakeMonitoringExporter(Project("test-project"),
std::move(mock));
auto exporter =
MakeMonitoringExporter(Project("test-project"), std::move(mock));
auto const expected_time_series_count = 2 * kMaxTimeSeriesPerRequest + 1;
auto data = MakeResourceMetrics(expected_time_series_count);
auto result = exporter->Export(data);
Expand Down Expand Up @@ -203,8 +203,8 @@ TEST(MonitoringExporter, ExportFailureWithInvalidArgument) {
return Status();
});

auto exporter = otel_internal::MakeMonitoringExporter(Project("test-project"),
std::move(mock));
auto exporter =
MakeMonitoringExporter(Project("test-project"), std::move(mock));
auto const expected_time_series_count = 2 * kMaxTimeSeriesPerRequest + 1;
auto data = MakeResourceMetrics(expected_time_series_count);
auto result = exporter->Export(data);
Expand All @@ -230,10 +230,10 @@ TEST(MonitoringExporter, CustomFormatter) {
return Status();
});

auto options = Options{}.set<otel_internal::MetricNameFormatterOption>(
auto options = Options{}.set<MetricNameFormatterOption>(
[](std::string const& s) { return "custom.googleapis.com/" + s; });
auto exporter = otel_internal::MakeMonitoringExporter(
Project("test-project"), std::move(mock), options);
auto exporter =
MakeMonitoringExporter(Project("test-project"), std::move(mock), options);
auto data = MakeResourceMetrics(/*expected_time_series_count=*/2);
auto result = exporter->Export(data);
EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess);
Expand All @@ -256,9 +256,9 @@ TEST(MonitoringExporter, CustomMonitoredResource) {
google::api::MonitoredResource custom;
custom.set_type("gcs_client");

auto options = Options{}.set<otel_internal::MonitoredResourceOption>(custom);
auto exporter = otel_internal::MakeMonitoringExporter(
Project("test-project"), std::move(mock), options);
auto options = Options{}.set<MonitoredResourceOption>(custom);
auto exporter =
MakeMonitoringExporter(Project("test-project"), std::move(mock), options);
auto data = MakeResourceMetrics(/*expected_time_series_count=*/2);
auto result = exporter->Export(data);
EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess);
Expand All @@ -275,9 +275,9 @@ TEST(MonitoringExporter, CreateServiceTimeSeries) {
return Status();
});

auto options = Options{}.set<otel_internal::ServiceTimeSeriesOption>(true);
auto exporter = otel_internal::MakeMonitoringExporter(
Project("test-project"), std::move(mock), options);
auto options = Options{}.set<ServiceTimeSeriesOption>(true);
auto exporter =
MakeMonitoringExporter(Project("test-project"), std::move(mock), options);
auto data = MakeResourceMetrics(/*expected_time_series_count=*/2);
auto result = exporter->Export(data);
EXPECT_EQ(result, opentelemetry::sdk::common::ExportResult::kSuccess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ absl::optional<ExporterConfig> MakeMeterProviderConfig(
void EnableGrpcMetricsImpl(ExporterConfig config) {
if (!ExporterRegistry::Singleton().Register(config.authority)) return;

auto exporter = otel_internal::MakeMonitoringExporter(
auto exporter = otel::MakeMonitoringExporter(
std::move(config.project),
monitoring_v3::MakeMetricServiceConnection(
std::move(config.exporter_connection_options)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,9 @@ TEST(GrpcMetricsExporter, EnabledResourceProject) {
auto config = MakeMeterProviderConfig(FullResource(), TestOptions());
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->project, Project("project-id-resource"));
EXPECT_TRUE(
config->exporter_options.has<otel_internal::MonitoredResourceOption>());
EXPECT_TRUE(
config->exporter_options.has<otel_internal::MetricNameFormatterOption>());
EXPECT_TRUE(
config->exporter_options.get<otel_internal::ServiceTimeSeriesOption>());
EXPECT_TRUE(config->exporter_options.has<otel::MonitoredResourceOption>());
EXPECT_TRUE(config->exporter_options.has<otel::MetricNameFormatterOption>());
EXPECT_TRUE(config->exporter_options.get<otel::ServiceTimeSeriesOption>());
EXPECT_GT(config->reader_options.export_interval_millis,
std::chrono::milliseconds(0));
EXPECT_GT(config->reader_options.export_timeout_millis,
Expand All @@ -88,12 +85,9 @@ TEST(GrpcMetricsExporter, EnabledOptionsProject) {
TestOptions().set<storage::ProjectIdOption>("project-id-option"));
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->project, Project("project-id-option"));
EXPECT_TRUE(
config->exporter_options.has<otel_internal::MonitoredResourceOption>());
EXPECT_TRUE(
config->exporter_options.has<otel_internal::MetricNameFormatterOption>());
EXPECT_TRUE(
config->exporter_options.get<otel_internal::ServiceTimeSeriesOption>());
EXPECT_TRUE(config->exporter_options.has<otel::MonitoredResourceOption>());
EXPECT_TRUE(config->exporter_options.has<otel::MetricNameFormatterOption>());
EXPECT_TRUE(config->exporter_options.get<otel::ServiceTimeSeriesOption>());
EXPECT_GT(config->reader_options.export_interval_millis,
std::chrono::milliseconds(0));
EXPECT_GT(config->reader_options.export_timeout_millis,
Expand All @@ -107,12 +101,9 @@ TEST(GrpcMetricsExporter, EnabledWithTimeout) {
std::chrono::seconds(45)));
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->project, Project("project-id-resource"));
EXPECT_TRUE(
config->exporter_options.has<otel_internal::MonitoredResourceOption>());
EXPECT_TRUE(
config->exporter_options.has<otel_internal::MetricNameFormatterOption>());
EXPECT_TRUE(
config->exporter_options.get<otel_internal::ServiceTimeSeriesOption>());
EXPECT_TRUE(config->exporter_options.has<otel::MonitoredResourceOption>());
EXPECT_TRUE(config->exporter_options.has<otel::MetricNameFormatterOption>());
EXPECT_TRUE(config->exporter_options.get<otel::ServiceTimeSeriesOption>());
EXPECT_EQ(config->reader_options.export_interval_millis,
std::chrono::seconds(45));
EXPECT_GT(config->reader_options.export_timeout_millis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ Options MetricsExporterOptions(
labels["api"] = "GRPC";

return Options{}
.set<otel_internal::ServiceTimeSeriesOption>(true)
.set<otel_internal::MetricNameFormatterOption>([](std::string s) {
.set<otel::ServiceTimeSeriesOption>(true)
.set<otel::MetricNameFormatterOption>([](std::string s) {
std::replace(s.begin(), s.end(), '.', '/');
return "storage.googleapis.com/client/" + std::move(s);
})
.set<otel_internal::MonitoredResourceOption>(
std::move(monitored_resource));
.set<otel::MonitoredResourceOption>(std::move(monitored_resource));
}

Options MetricsExporterConnectionOptions(Options const& options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ TEST(MetricsExporterOptions, MonitoredResource) {
{"host.id", "test-host-id"},
}));

EXPECT_TRUE(actual.has<otel_internal::MonitoredResourceOption>());
auto mr = actual.get<otel_internal::MonitoredResourceOption>();
EXPECT_TRUE(actual.has<otel::MonitoredResourceOption>());
auto mr = actual.get<otel::MonitoredResourceOption>();
auto labels = mr.labels();
// The `instance_id` label has unpredictable values,
EXPECT_THAT(labels, Contains(Pair("instance_id", MatchesInstanceId())));
Expand All @@ -164,8 +164,8 @@ TEST(MetricsExporterOptions, DefaultMonitoredResource) {
Project("test-project"),
opentelemetry::sdk::resource::Resource::Create({}));

EXPECT_TRUE(actual.has<otel_internal::MonitoredResourceOption>());
auto mr = actual.get<otel_internal::MonitoredResourceOption>();
EXPECT_TRUE(actual.has<otel::MonitoredResourceOption>());
auto mr = actual.get<otel::MonitoredResourceOption>();
auto labels = mr.labels();
// The `instance_id` label has unpredictable values,
EXPECT_THAT(labels, Contains(Pair("instance_id", MatchesInstanceId())));
Expand Down
Loading