You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "szaszm (via GitHub)" <gi...@apache.org> on 2023/05/15 11:08:40 UTC

[GitHub] [nifi-minifi-cpp] szaszm commented on a diff in pull request #1532: MINIFICPP-2076 Implement logging metrics publisher

szaszm commented on code in PR #1532:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1532#discussion_r1193618193


##########
libminifi/src/core/state/MetricsPublisherStore.cpp:
##########
@@ -42,9 +42,9 @@ void MetricsPublisherStore::initialize(core::controller::ControllerServiceProvid
     addMetricsPublisher(c2::CONTROLLER_SOCKET_METRICS_PUBLISHER, std::move(controller_socket_metrics_publisher));
   }
 
-  std::shared_ptr metrics_publisher = minifi::state::createMetricsPublisher(configuration_, response_node_loader_);
-  if (metrics_publisher) {
-    addMetricsPublisher(minifi::Configure::nifi_metrics_publisher_class, std::move(metrics_publisher));
+  for (auto&& publisher : minifi::state::createMetricsPublishers(configuration_, response_node_loader_)) {
+    auto name = publisher->getName();
+    addMetricsPublisher(name, std::move(publisher));

Review Comment:
   Consider pass-by-value and move for the name.
   
   Can we change `addMetricsPublisher` to take a `unique_ptr` instead of a `shared_ptr`? The store should probably not share ownership of the metrics publishers.



##########
libminifi/include/core/state/Value.h:
##########
@@ -558,13 +558,14 @@ struct SerializedResponseNode {
     return value.empty() && children.empty();
   }
 
+  template<typename Writer = rapidjson::Writer<rapidjson::StringBuffer>>

Review Comment:
   This won't work with the definition still in the .cpp file.



##########
libminifi/test/unit/LogMetricsPublisherTests.cpp:
##########
@@ -0,0 +1,209 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 <memory>
+#include <thread>
+
+#include "../TestBase.h"
+#include "../Catch.h"
+#include "core/state/LogMetricsPublisher.h"
+#include "core/state/nodes/ResponseNodeLoader.h"
+#include "core/RepositoryFactory.h"
+#include "utils/IntegrationTestUtils.h"
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::test {
+
+class LogPublisherTestFixture {
+ public:
+  LogPublisherTestFixture()
+    : configuration_(std::make_shared<Configure>()),
+      provenance_repo_(core::createRepository("provenancerepository", "provenancerepository")),
+      flow_file_repo_(core::createRepository("flowfilerepository", "flowfilerepository")),
+      response_node_loader_(std::make_shared<state::response::ResponseNodeLoader>(configuration_, provenance_repo_, flow_file_repo_, nullptr)),
+      publisher_("LogMetricsPublisher") {
+  }
+
+ protected:
+  std::shared_ptr<Configure> configuration_;
+  std::shared_ptr<core::Repository> provenance_repo_;
+  std::shared_ptr<core::Repository> flow_file_repo_;
+  std::shared_ptr<state::response::ResponseNodeLoader> response_node_loader_;
+  minifi::state::LogMetricsPublisher publisher_;
+};
+
+TEST_CASE_METHOD(LogPublisherTestFixture, "Logging interval property is mandatory", "[LogMetricsPublisher]") {
+  LogTestController::getInstance().setTrace<minifi::state::LogMetricsPublisher>();
+  SECTION("No logging interval is set") {
+    REQUIRE_THROWS_WITH(publisher_.initialize(configuration_, response_node_loader_), "General Operation: Metrics logging interval not configured for log metrics publisher!");
+  }
+  SECTION("Logging interval is set to 2 seconds") {
+    configuration_->set(minifi::Configuration::nifi_metrics_publisher_log_metrics_logging_interval, "2s");
+    using org::apache::nifi::minifi::utils::verifyLogLinePresenceInPollTime;
+    publisher_.initialize(configuration_, response_node_loader_);
+    REQUIRE(verifyLogLinePresenceInPollTime(5s, "Metric logging interval is set to 2000 milliseconds"));
+  }
+}
+
+TEST_CASE_METHOD(LogPublisherTestFixture, "Verify empty metrics if no valid metrics are defined", "[LogMetricsPublisher]") {
+  LogTestController::getInstance().setTrace<minifi::state::LogMetricsPublisher>();
+  configuration_->set(minifi::Configuration::nifi_metrics_publisher_log_metrics_logging_interval, "100ms");
+  SECTION("No metrics are defined") {}
+  SECTION("Only invalid metrics are defined") {
+    configuration_->set(Configure::nifi_metrics_publisher_metrics, "InvalidMetric,NotValidMetricNode");
+  }
+  publisher_.initialize(configuration_, response_node_loader_);
+  publisher_.loadMetricNodes();
+  using org::apache::nifi::minifi::utils::verifyLogLinePresenceInPollTime;
+  std::string expected_log = R"([info] {
+    "LogMetrics": {}
+})";
+  REQUIRE(verifyLogLinePresenceInPollTime(5s, expected_log));

Review Comment:
   If there is nothing useful to log, then we shouldn't log.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org