From 38f811aa78db5eaf6421cff2e8d4aae234f6fb3f Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Thu, 6 Aug 2020 18:31:41 -0700 Subject: [PATCH 01/15] Add PrometheusExporter header, source, and test files --- .../prometheus/prometheus_exporter.h | 92 +++++++++ .../prometheus/src/prometheus_exporter.cc | 91 +++++++++ .../test/prometheus_exporter_test.cc | 193 ++++++++++++++++++ 3 files changed, 376 insertions(+) create mode 100644 exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter.h create mode 100644 exporters/prometheus/src/prometheus_exporter.cc create mode 100644 exporters/prometheus/test/prometheus_exporter_test.cc diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter.h new file mode 100644 index 0000000000..48ef6e7a5c --- /dev/null +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter.h @@ -0,0 +1,92 @@ +#pragma once + +#include +#include +#include + +#include "opentelemetry/sdk/metrics/exporter.h" +#include "opentelemetry/sdk/metrics/record.h" +#include "opentelemetry/version.h" +#include "prometheus/exposer.h" +#include "prometheus_collector.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 exporter +{ +namespace prometheus +{ +class PrometheusExporter : public sdk::metrics::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::metrics::ExportResult Export(const std::vector &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 &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 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 diff --git a/exporters/prometheus/src/prometheus_exporter.cc b/exporters/prometheus/src/prometheus_exporter.cc new file mode 100644 index 0000000000..ee38925294 --- /dev/null +++ b/exporters/prometheus/src/prometheus_exporter.cc @@ -0,0 +1,91 @@ +#include "opentelemetry/exporters/prometheus/prometheus_exporter.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace prometheus +{ +/** + * 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::PrometheusExporter(std::string &address) : is_shutdown_(false) +{ + exposer_ = std::unique_ptr<::prometheus::Exposer>(new ::prometheus::Exposer{address}); + collector_ = std::shared_ptr(new PrometheusCollector); + + exposer_->RegisterCollectable(collector_); +} + +/** + * PrometheusExporter constructor with no parameters + * Used for testing only + */ +PrometheusExporter::PrometheusExporter() : is_shutdown_(false) +{ + exposer_ = nullptr; + collector_ = std::unique_ptr(new PrometheusCollector); +} + +/** + * 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::metrics::ExportResult PrometheusExporter::Export( + const std::vector &records) noexcept +{ + if (is_shutdown_) + { + return sdk::metrics::ExportResult::kFailure; + } + else if (records.empty()) + { + return sdk::metrics::ExportResult::kFailureInvalidArgument; + } + else if (collector_->GetCollection().size() + records.size() > collector_->GetMaxCollectionSize()) + { + return sdk::metrics::ExportResult::kFailureFull; + } + else + { + collector_->AddMetricData(records); + return sdk::metrics::ExportResult::kSuccess; + } +} + +/** + * 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 PrometheusExporter::Shutdown() noexcept +{ + is_shutdown_ = true; + + collector_->GetCollection().clear(); +} + +/** + * @return: returns a shared_ptr to + * the PrometheusCollector instance + */ +std::shared_ptr &PrometheusExporter::GetCollector() +{ + return collector_; +} + +/** + * @return: Gets the shutdown status of the exporter + */ +bool PrometheusExporter::IsShutdown() const +{ + return is_shutdown_; +} + +} // namespace prometheus +} // namespace exporter +OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/prometheus/test/prometheus_exporter_test.cc b/exporters/prometheus/test/prometheus_exporter_test.cc new file mode 100644 index 0000000000..0b541308a1 --- /dev/null +++ b/exporters/prometheus/test/prometheus_exporter_test.cc @@ -0,0 +1,193 @@ +#include +#include + +#include "opentelemetry/exporters/prometheus/prometheus_collector.h" +#include "opentelemetry/exporters/prometheus/prometheus_exporter.h" +#include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h" +#include "opentelemetry/version.h" + +/** + * PrometheusExporterTest is a friend class of PrometheusExporter. + * It has access to a private constructor that does not take in + * an exposer as an argument, and instead takes no arguments; this + * private constructor is only to be used here for testing + */ +class opentelemetry::exporter::prometheus::PrometheusExporterTest +{ +public: + opentelemetry::exporter::prometheus::PrometheusExporter GetExporter() + { + return opentelemetry::exporter::prometheus::PrometheusExporter(); + } +}; + +using opentelemetry::exporter::prometheus::PrometheusCollector; +using opentelemetry::exporter::prometheus::PrometheusExporter; +using opentelemetry::exporter::prometheus::PrometheusExporterTest; +using opentelemetry::sdk::metrics::CounterAggregator; +using opentelemetry::sdk::metrics::Record; +using opentelemetry::sdk::metrics::ExportResult; + +/** + * Helper function to create a collection of records taken from + * a counter aggregator + */ +std::vector CreateRecords(int num) +{ + + std::vector records; + + for (int i = 0; i < num; i++) + { + std::string name = "record-" + std::to_string(i); + std::string description = "record-" + std::to_string(i); + std::string labels = "record-" + std::to_string(i) + "-label-1.0"; + auto aggregator = std::shared_ptr>( + new opentelemetry::sdk::metrics::CounterAggregator( + opentelemetry::metrics::InstrumentKind::Counter)); + aggregator->update(10); + aggregator->checkpoint(); + + Record r{name, description, labels, aggregator}; + records.push_back(r); + } + return records; +} + +/** + * When a PrometheusExporter is initialized, + * isShutdown should be false. + */ +TEST(PrometheusExporter, InitializeConstructorIsNotShutdown) +{ + PrometheusExporterTest p; + PrometheusExporter exporter = p.GetExporter(); + + // Asserts that the exporter is not shutdown. + ASSERT_TRUE(!exporter.IsShutdown()); +} + +/** + * The shutdown() function should set the isShutdown field to true. + */ +TEST(PrometheusExporter, ShutdownSetsIsShutdownToTrue) +{ + PrometheusExporterTest p; + PrometheusExporter exporter = p.GetExporter(); + + // exporter shuold not be shutdown by default + ASSERT_TRUE(!exporter.IsShutdown()); + + exporter.Shutdown(); + + // the exporter shuold be shutdown + ASSERT_TRUE(exporter.IsShutdown()); + + // shutdown function should be idempotent + exporter.Shutdown(); + ASSERT_TRUE(exporter.IsShutdown()); +} + +/** + * The Export() function should return SUCCESS = 0 + * when data is exported successfully. + */ +TEST(PrometheusExporter, ExportSuccessfully) +{ + PrometheusExporterTest p; + PrometheusExporter exporter = p.GetExporter(); + + int num_records = 2; + + std::vector records = CreateRecords(num_records); + + auto res = exporter.Export(records); + + // result should be SUCCESS = 0 + ExportResult code = ExportResult::kSuccess; + ASSERT_EQ(res, code); +} + +/** + * If the exporter is shutdown, it cannot process + * any more export requests and returns FAILURE_ALREADY_SHUTDOWN = 4. + */ +TEST(PrometheusExporter, ExporterIsShutdown) +{ + PrometheusExporterTest p; + PrometheusExporter exporter = p.GetExporter(); + + int num_records = 1; + + std::vector records = CreateRecords(num_records); + + exporter.Shutdown(); + + // send export request after shutdown + auto res = exporter.Export(records); + + // result code should be FAILURE_ALREADY_SHUTDOWN = 4 + ExportResult code = ExportResult::kFailure; + ASSERT_EQ(res, code); +} + +/** + * The Export() function should return + * FAILURE_FULL_COLLECTION = 1 when the collection is full, + * or when the collection is not full but does not have enough + * space to hold the batch data. + */ +TEST(PrometheusExporter, CollectionNotEnoughSpace) +{ + PrometheusExporterTest p; + PrometheusExporter exporter = p.GetExporter(); + + int num_records = 2; + + // prepare two collections of records to export, + // one close to max size and another one that, when added + // to the first, will exceed the size of the collection + + int max_collection_size = exporter.GetCollector()->GetMaxCollectionSize(); + + std::vector full_records = CreateRecords(max_collection_size - 1); + std::vector records = CreateRecords(num_records); + + // send export request to fill the + // collection in the collector + auto res = exporter.Export(full_records); + + // the result code should be SUCCESS = 0 + ExportResult code = ExportResult::kSuccess; + ASSERT_EQ(res, code); + + // send export request that does not complete + // due to not enough space in the collection + res = exporter.Export(records); + + // the result code should be FAILURE_FULL_COLLECTION = 1 + code = ExportResult::kFailureFull; + ASSERT_EQ(res, code); +} + +/** + * The Export() function should return + * FAILURE_INVALID_ARGUMENT = 3 when an empty collection + * of records is passed to the Export() function. + */ +TEST(PrometheusExporter, InvalidArgumentWhenPassedEmptyRecordCollection) +{ + PrometheusExporterTest p; + PrometheusExporter exporter = p.GetExporter(); + + // Initializes an empty colelction of records + std::vector records; + + // send export request to fill the + // collection in the collector + auto res = exporter.Export(records); + + // the result code should be FAILURE_INVALID_ARGUMENT = 3 + ExportResult code = ExportResult::kFailureInvalidArgument; + ASSERT_EQ(res, code); +} From 140efcde01008490e2e28961e708e3e5495a093f Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Fri, 7 Aug 2020 10:51:36 -0700 Subject: [PATCH 02/15] CI formatting, added copyright headers --- .../prometheus/prometheus_exporter.h | 33 ++++++++++++++----- .../prometheus/src/prometheus_exporter.cc | 20 +++++++++-- .../test/prometheus_exporter_test.cc | 18 +++++++++- 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter.h b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter.h index 48ef6e7a5c..82e6be0d6a 100644 --- a/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter.h +++ b/exporters/prometheus/include/opentelemetry/exporters/prometheus/prometheus_exporter.h @@ -1,3 +1,19 @@ +/* + * 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 #include @@ -36,15 +52,16 @@ class PrometheusExporter : public sdk::metrics::MetricsExporter * @param records: a collection of records to export * @return: returns a ReturnCode detailing a success, or type of failure */ - sdk::metrics::ExportResult Export(const std::vector &records) noexcept override; + sdk::metrics::ExportResult Export( + const std::vector &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. - */ + /** + * 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; /** diff --git a/exporters/prometheus/src/prometheus_exporter.cc b/exporters/prometheus/src/prometheus_exporter.cc index ee38925294..116b736029 100644 --- a/exporters/prometheus/src/prometheus_exporter.cc +++ b/exporters/prometheus/src/prometheus_exporter.cc @@ -1,3 +1,19 @@ +/* + * 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. + */ + #include "opentelemetry/exporters/prometheus/prometheus_exporter.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -57,9 +73,9 @@ sdk::metrics::ExportResult PrometheusExporter::Export( /** * Shuts down the exporter and does cleanup. - * Since Prometheus is a pull based interface, + * Since Prometheus is a pull based interface, * we cannot serve data remaining in the intermediate - * collection to to client an HTTP request being sent, + * collection to to client an HTTP request being sent, * so we flush the data. */ void PrometheusExporter::Shutdown() noexcept diff --git a/exporters/prometheus/test/prometheus_exporter_test.cc b/exporters/prometheus/test/prometheus_exporter_test.cc index 0b541308a1..6358d25cf7 100644 --- a/exporters/prometheus/test/prometheus_exporter_test.cc +++ b/exporters/prometheus/test/prometheus_exporter_test.cc @@ -1,3 +1,19 @@ +/* + * 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. + */ + #include #include @@ -25,8 +41,8 @@ using opentelemetry::exporter::prometheus::PrometheusCollector; using opentelemetry::exporter::prometheus::PrometheusExporter; using opentelemetry::exporter::prometheus::PrometheusExporterTest; using opentelemetry::sdk::metrics::CounterAggregator; -using opentelemetry::sdk::metrics::Record; using opentelemetry::sdk::metrics::ExportResult; +using opentelemetry::sdk::metrics::Record; /** * Helper function to create a collection of records taken from From feb7126b514ef97bd155114412aac8e8fe64f29c Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Tue, 18 Aug 2020 10:53:50 -0700 Subject: [PATCH 03/15] Added build files --- exporters/prometheus/BUILD | 48 ++++++++++++++++++++++++ exporters/prometheus/CMakeLists.txt | 23 ++++++++++++ exporters/prometheus/test/CMakeLists.txt | 8 ++++ 3 files changed, 79 insertions(+) create mode 100644 exporters/prometheus/BUILD create mode 100644 exporters/prometheus/CMakeLists.txt create mode 100644 exporters/prometheus/test/CMakeLists.txt diff --git a/exporters/prometheus/BUILD b/exporters/prometheus/BUILD new file mode 100644 index 0000000000..f3cf46100a --- /dev/null +++ b/exporters/prometheus/BUILD @@ -0,0 +1,48 @@ +# Copyright 2020, 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. + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "prometheus_exporter", + srcs = [ + "src/prometheus_exporter.cc", + ], + hdrs = [ + "include/opentelemetry/exporters/prometheus/prometheus_collector.h", + "include/opentelemetry/exporters/prometheus/prometheus_exporter.h", + "include/opentelemetry/exporters/prometheus/prometheus_exporter_utils.h", + ], + strip_include_prefix = "include", + deps = [ + "//api", + "//sdk:headers", + "@com_github_jupp0r_prometheus_cpp//core", + "@com_github_jupp0r_prometheus_cpp//pull", + ], +) + +cc_test( + name = "prometheus_exporter_test", + srcs = [ + "test/prometheus_exporter_test.cc", + ], + deps = [ + ":prometheus_collector", + ":prometheus_exporter", + "@com_github_jupp0r_prometheus_cpp//core", + "@com_github_jupp0r_prometheus_cpp//pull", + "@com_google_googletest//:gtest_main", + ], +) \ No newline at end of file diff --git a/exporters/prometheus/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt new file mode 100644 index 0000000000..3004fd0951 --- /dev/null +++ b/exporters/prometheus/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright 2020, 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. + +include_directories(include) + +find_package(prometheus-cpp CONFIG REQUIRED) +add_library( + prometheus_exporter src/prometheus_exporter.cc) + +if (BUILD_TESTING) + add_subdirectory(test) +endif () \ No newline at end of file diff --git a/exporters/prometheus/test/CMakeLists.txt b/exporters/prometheus/test/CMakeLists.txt new file mode 100644 index 0000000000..bfd5e2e2f6 --- /dev/null +++ b/exporters/prometheus/test/CMakeLists.txt @@ -0,0 +1,8 @@ +foreach (testname prometheus_exporter_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries( + ${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + prometheus_exporter prometheus-cpp::pull) + gtest_add_tests(TARGET ${testname} TEST_PREFIX exporter. TEST_LIST ${testname}) +endforeach () + From 5d6fc7e731553c9f9ee6c61f82b19e837f512a63 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Wed, 19 Aug 2020 11:30:50 -0700 Subject: [PATCH 04/15] modified comments to reflect removal of ReturnCodes class, removal of kFailureTimeout --- .../test/prometheus_exporter_test.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/exporters/prometheus/test/prometheus_exporter_test.cc b/exporters/prometheus/test/prometheus_exporter_test.cc index 6358d25cf7..0656a16a9b 100644 --- a/exporters/prometheus/test/prometheus_exporter_test.cc +++ b/exporters/prometheus/test/prometheus_exporter_test.cc @@ -105,7 +105,7 @@ TEST(PrometheusExporter, ShutdownSetsIsShutdownToTrue) } /** - * The Export() function should return SUCCESS = 0 + * The Export() function should return kSuccess = 0 * when data is exported successfully. */ TEST(PrometheusExporter, ExportSuccessfully) @@ -119,14 +119,14 @@ TEST(PrometheusExporter, ExportSuccessfully) auto res = exporter.Export(records); - // result should be SUCCESS = 0 + // result should be kSuccess = 0 ExportResult code = ExportResult::kSuccess; ASSERT_EQ(res, code); } /** * If the exporter is shutdown, it cannot process - * any more export requests and returns FAILURE_ALREADY_SHUTDOWN = 4. + * any more export requests and returns kFailure = 1. */ TEST(PrometheusExporter, ExporterIsShutdown) { @@ -142,14 +142,14 @@ TEST(PrometheusExporter, ExporterIsShutdown) // send export request after shutdown auto res = exporter.Export(records); - // result code should be FAILURE_ALREADY_SHUTDOWN = 4 + // result code should be kFailure = 1 ExportResult code = ExportResult::kFailure; ASSERT_EQ(res, code); } /** * The Export() function should return - * FAILURE_FULL_COLLECTION = 1 when the collection is full, + * kFailureFull = 2 when the collection is full, * or when the collection is not full but does not have enough * space to hold the batch data. */ @@ -173,7 +173,7 @@ TEST(PrometheusExporter, CollectionNotEnoughSpace) // collection in the collector auto res = exporter.Export(full_records); - // the result code should be SUCCESS = 0 + // the result code should be kSuccess = 0 ExportResult code = ExportResult::kSuccess; ASSERT_EQ(res, code); @@ -181,14 +181,14 @@ TEST(PrometheusExporter, CollectionNotEnoughSpace) // due to not enough space in the collection res = exporter.Export(records); - // the result code should be FAILURE_FULL_COLLECTION = 1 + // the result code should be kFailureFull = 2 code = ExportResult::kFailureFull; ASSERT_EQ(res, code); } /** * The Export() function should return - * FAILURE_INVALID_ARGUMENT = 3 when an empty collection + * kFailureInvalidArgument = 3 when an empty collection * of records is passed to the Export() function. */ TEST(PrometheusExporter, InvalidArgumentWhenPassedEmptyRecordCollection) @@ -203,7 +203,7 @@ TEST(PrometheusExporter, InvalidArgumentWhenPassedEmptyRecordCollection) // collection in the collector auto res = exporter.Export(records); - // the result code should be FAILURE_INVALID_ARGUMENT = 3 + // the result code should be kFailureInvalidArgument = 3 ExportResult code = ExportResult::kFailureInvalidArgument; ASSERT_EQ(res, code); } From 32880b0075c236f9b4b6e79f909bb5fdd8483b17 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Fri, 28 Aug 2020 17:30:36 -0700 Subject: [PATCH 05/15] minor change to structure of friend class --- .../test/prometheus_exporter_test.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/exporters/prometheus/test/prometheus_exporter_test.cc b/exporters/prometheus/test/prometheus_exporter_test.cc index 0656a16a9b..9e6c638a94 100644 --- a/exporters/prometheus/test/prometheus_exporter_test.cc +++ b/exporters/prometheus/test/prometheus_exporter_test.cc @@ -28,14 +28,22 @@ * an exposer as an argument, and instead takes no arguments; this * private constructor is only to be used here for testing */ -class opentelemetry::exporter::prometheus::PrometheusExporterTest +OPENTELEMETRY_BEGIN_NAMESPACE +namespace exporter +{ +namespace prometheus +{ +class PrometheusExporterTest // : public ::testing::Test { public: - opentelemetry::exporter::prometheus::PrometheusExporter GetExporter() - { - return opentelemetry::exporter::prometheus::PrometheusExporter(); - } + PrometheusExporter GetExporter() + { + return PrometheusExporter(); + } }; +} +} +OPENTELEMETRY_END_NAMESPACE using opentelemetry::exporter::prometheus::PrometheusCollector; using opentelemetry::exporter::prometheus::PrometheusExporter; From 94af70dda0e430b654180e65afccdde2397d98a9 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Mon, 31 Aug 2020 09:55:40 -0700 Subject: [PATCH 06/15] removed assignment of exposer_ to nullptr in testing constructor --- exporters/prometheus/src/prometheus_exporter.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/exporters/prometheus/src/prometheus_exporter.cc b/exporters/prometheus/src/prometheus_exporter.cc index 116b736029..32014fb98d 100644 --- a/exporters/prometheus/src/prometheus_exporter.cc +++ b/exporters/prometheus/src/prometheus_exporter.cc @@ -40,7 +40,6 @@ PrometheusExporter::PrometheusExporter(std::string &address) : is_shutdown_(fals */ PrometheusExporter::PrometheusExporter() : is_shutdown_(false) { - exposer_ = nullptr; collector_ = std::unique_ptr(new PrometheusCollector); } From 367d6a31c35171bf785f649b854abd7520550395 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Wed, 2 Sep 2020 11:35:44 -0700 Subject: [PATCH 07/15] removed usage of release9.0 of Prometheus --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index e97686b0b7..5da359a719 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -49,7 +49,7 @@ elif [[ "$1" == "cmake.exporter.prometheus.test" ]]; then cd third_party git clone https://github.com/jupp0r/prometheus-cpp cd prometheus-cpp - git checkout v0.9.0 + # git checkout v0.9.0 git submodule init git submodule update mkdir _build && cd _build From a5e2cfb8cee212e10e285155237360f5c7ff1edf Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Wed, 2 Sep 2020 12:11:06 -0700 Subject: [PATCH 08/15] BUILD file changes --- exporters/prometheus/BUILD | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/exporters/prometheus/BUILD b/exporters/prometheus/BUILD index 850ca2ed48..238c62a6de 100644 --- a/exporters/prometheus/BUILD +++ b/exporters/prometheus/BUILD @@ -26,6 +26,7 @@ cc_library( ], strip_include_prefix = "include", deps = [ + ":prometheus_collector", "//api", "//sdk:headers", "@com_github_jupp0r_prometheus_cpp//core", @@ -73,10 +74,7 @@ cc_test( "test/prometheus_exporter_test.cc", ], deps = [ - ":prometheus_collector", ":prometheus_exporter", - "@com_github_jupp0r_prometheus_cpp//core", - "@com_github_jupp0r_prometheus_cpp//pull", "@com_google_googletest//:gtest_main", ], ) From 6bbb0510f3baefda2c9f0cf68ca6e84e8eb0fe86 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Wed, 2 Sep 2020 12:43:57 -0700 Subject: [PATCH 09/15] changed Prometheus client back to 9.0 --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 5da359a719..e97686b0b7 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -49,7 +49,7 @@ elif [[ "$1" == "cmake.exporter.prometheus.test" ]]; then cd third_party git clone https://github.com/jupp0r/prometheus-cpp cd prometheus-cpp - # git checkout v0.9.0 + git checkout v0.9.0 git submodule init git submodule update mkdir _build && cd _build From d3d44f3c362a05ec22df32e8c7ab52f8853036a7 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Wed, 2 Sep 2020 14:47:34 -0700 Subject: [PATCH 10/15] removed a test for debugging --- exporters/prometheus/test/prometheus_exporter_test.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exporters/prometheus/test/prometheus_exporter_test.cc b/exporters/prometheus/test/prometheus_exporter_test.cc index 9e6c638a94..5476dba1e9 100644 --- a/exporters/prometheus/test/prometheus_exporter_test.cc +++ b/exporters/prometheus/test/prometheus_exporter_test.cc @@ -84,11 +84,11 @@ std::vector CreateRecords(int num) */ TEST(PrometheusExporter, InitializeConstructorIsNotShutdown) { - PrometheusExporterTest p; - PrometheusExporter exporter = p.GetExporter(); + // PrometheusExporterTest p; + // PrometheusExporter exporter = p.GetExporter(); - // Asserts that the exporter is not shutdown. - ASSERT_TRUE(!exporter.IsShutdown()); + // // Asserts that the exporter is not shutdown. + // ASSERT_TRUE(!exporter.IsShutdown()); } /** From 8dc5cb11ca7cf5bdb3d08b28dbeb28e7f5fea130 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Wed, 2 Sep 2020 15:00:35 -0700 Subject: [PATCH 11/15] Revert "removed a test for debugging" This reverts commit d3d44f3c362a05ec22df32e8c7ab52f8853036a7. --- exporters/prometheus/test/prometheus_exporter_test.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exporters/prometheus/test/prometheus_exporter_test.cc b/exporters/prometheus/test/prometheus_exporter_test.cc index 5476dba1e9..9e6c638a94 100644 --- a/exporters/prometheus/test/prometheus_exporter_test.cc +++ b/exporters/prometheus/test/prometheus_exporter_test.cc @@ -84,11 +84,11 @@ std::vector CreateRecords(int num) */ TEST(PrometheusExporter, InitializeConstructorIsNotShutdown) { - // PrometheusExporterTest p; - // PrometheusExporter exporter = p.GetExporter(); + PrometheusExporterTest p; + PrometheusExporter exporter = p.GetExporter(); - // // Asserts that the exporter is not shutdown. - // ASSERT_TRUE(!exporter.IsShutdown()); + // Asserts that the exporter is not shutdown. + ASSERT_TRUE(!exporter.IsShutdown()); } /** From 94f78c8f604befc1bb907d5a6447d65675a9d108 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Wed, 2 Sep 2020 16:16:31 -0700 Subject: [PATCH 12/15] format --- exporters/prometheus/CMakeLists.txt | 6 +++--- exporters/prometheus/test/CMakeLists.txt | 3 ++- exporters/prometheus/test/prometheus_exporter_test.cc | 11 ++++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/exporters/prometheus/CMakeLists.txt b/exporters/prometheus/CMakeLists.txt index fa0a3e9a8f..337527de12 100644 --- a/exporters/prometheus/CMakeLists.txt +++ b/exporters/prometheus/CMakeLists.txt @@ -16,9 +16,9 @@ include_directories(include) find_package(prometheus-cpp CONFIG REQUIRED) -add_library(prometheus_exporter src/prometheus_exporter.cc - src/prometheus_collector.cc - src/prometheus_exporter_utils.cc) +add_library( + prometheus_exporter src/prometheus_exporter.cc src/prometheus_collector.cc + src/prometheus_exporter_utils.cc) if(BUILD_TESTING) add_subdirectory(test) diff --git a/exporters/prometheus/test/CMakeLists.txt b/exporters/prometheus/test/CMakeLists.txt index 2b324608f9..a0280b4e15 100644 --- a/exporters/prometheus/test/CMakeLists.txt +++ b/exporters/prometheus/test/CMakeLists.txt @@ -1,4 +1,5 @@ -foreach(testname prometheus_exporter_test prometheus_collector_test prometheus_exporter_utils_test) +foreach(testname prometheus_exporter_test prometheus_collector_test + prometheus_exporter_utils_test) add_executable(${testname} "${testname}.cc") target_link_libraries( ${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} diff --git a/exporters/prometheus/test/prometheus_exporter_test.cc b/exporters/prometheus/test/prometheus_exporter_test.cc index 9e6c638a94..f2e1626603 100644 --- a/exporters/prometheus/test/prometheus_exporter_test.cc +++ b/exporters/prometheus/test/prometheus_exporter_test.cc @@ -33,16 +33,13 @@ namespace exporter { namespace prometheus { -class PrometheusExporterTest // : public ::testing::Test +class PrometheusExporterTest // : public ::testing::Test { public: - PrometheusExporter GetExporter() - { - return PrometheusExporter(); - } + PrometheusExporter GetExporter() { return PrometheusExporter(); } }; -} -} +} // namespace prometheus +} // namespace exporter OPENTELEMETRY_END_NAMESPACE using opentelemetry::exporter::prometheus::PrometheusCollector; From 5938aa8fe68f24e830a3d511456cff18382cca78 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Thu, 3 Sep 2020 09:49:57 -0700 Subject: [PATCH 13/15] added MAKE_EXE_LINKER_FLAGS cmake link option --- ci/do_ci.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index e97686b0b7..77611ba8ad 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -63,6 +63,7 @@ elif [[ "$1" == "cmake.exporter.prometheus.test" ]]; then cmake -DCMAKE_BUILD_TYPE=Debug \ -DWITH_PROMETHEUS=ON \ -DCMAKE_CXX_FLAGS="-Werror" \ + MAKE_EXE_LINKER_FLAGS="-lpthread" \ "${SRC_DIR}" make make test From dc28f848e2052d3433ff159312fa7f8e2ffa4e62 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Thu, 3 Sep 2020 10:04:07 -0700 Subject: [PATCH 14/15] added -D to flag --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 77611ba8ad..87eea78c40 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -63,7 +63,7 @@ elif [[ "$1" == "cmake.exporter.prometheus.test" ]]; then cmake -DCMAKE_BUILD_TYPE=Debug \ -DWITH_PROMETHEUS=ON \ -DCMAKE_CXX_FLAGS="-Werror" \ - MAKE_EXE_LINKER_FLAGS="-lpthread" \ + -DMAKE_EXE_LINKER_FLAGS="-lpthread" \ "${SRC_DIR}" make make test From 75e23e56af9b7d6050bbe74d71db8655d30f1c14 Mon Sep 17 00:00:00 2001 From: erichsueh3 Date: Thu, 3 Sep 2020 10:14:44 -0700 Subject: [PATCH 15/15] changed -DMAKE_EXE_LINKER_FLAGS to -DCMAKE_EXE_LINKER_FLAGS --- ci/do_ci.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 87eea78c40..4d68b22125 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -63,7 +63,7 @@ elif [[ "$1" == "cmake.exporter.prometheus.test" ]]; then cmake -DCMAKE_BUILD_TYPE=Debug \ -DWITH_PROMETHEUS=ON \ -DCMAKE_CXX_FLAGS="-Werror" \ - -DMAKE_EXE_LINKER_FLAGS="-lpthread" \ + -DCMAKE_EXE_LINKER_FLAGS="-lpthread" \ "${SRC_DIR}" make make test