fgerlits commented on code in PR #1987:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1987#discussion_r2545397972


##########
core-framework/src/utils/file/FileUtils.cpp:
##########
@@ -71,6 +71,33 @@ bool contains(const std::filesystem::path& file_path, 
std::string_view text_to_s
   return std::search(view.begin(), view.end(), searcher) != view.end();
 }
 
+// finds a string of length at most @max_length with a given @prefix
+std::optional<std::string> find(const std::filesystem::path& file_path, 
std::string_view prefix, size_t max_length) {

Review Comment:
   I would prefer this function to take an `istream` argument instead of a 
`path`. Or it could be broken up into two functions, where the one with a 
`path` argument calls the one with an `istream` argument.
   
   Also, it (at least the version with an `istream` argument, if broken up) 
should be unit tested, as the logic is quite complex.



##########
extensions/standard-processors/tests/integration/InvokeHTTPTests.cpp:
##########
@@ -388,8 +388,8 @@ TEST_CASE("Data transfer speed parsing") {
   CHECK(processors::invoke_http::parseDataTransferSpeed("10 kB/s") == 10_KiB);
   CHECK(processors::invoke_http::parseDataTransferSpeed("20 MB/s") == 20_MiB);
   CHECK(processors::invoke_http::parseDataTransferSpeed("19 TB/s") == 19_TiB);
-  CHECK(processors::invoke_http::parseDataTransferSpeed("1KBinvalidsuffix") == 
nonstd::make_unexpected(make_error_code(core::ParsingErrorCode::GeneralParsingError)));
-  CHECK(processors::invoke_http::parseDataTransferSpeed("1KB") == 
nonstd::make_unexpected(make_error_code(core::ParsingErrorCode::GeneralParsingError)));
+  
CHECK(processors::invoke_http::parseDataTransferSpeed("1KBinvalidsuffix").error().message()
 == "GeneralParsingError");
+  
CHECK(processors::invoke_http::parseDataTransferSpeed("1KB").error().message() 
== "GeneralParsingError");

Review Comment:
   Can we keep the old version? Now, if the return value of 
`parseDataTransferSpeed` is not an error, we get undefined behavior from 
`.error()` instead of (as before) a well-defined test failure.



##########
extensions/llamacpp/tests/RunLlamaCppInferenceTests.cpp:
##########
@@ -224,13 +227,14 @@ TEST_CASE("Invalid values for optional double type 
properties throw exception")
     property_name = processors::RunLlamaCppInference::MinP.name;
   }
 
-  
REQUIRE_THROWS_WITH(controller.trigger(minifi::test::InputFlowFileData{.content 
= "42", .attributes = {}}),
-      fmt::format("Expected parsable float from RunLlamaCppInference::{}, but 
got GeneralParsingError (Parsing Error:0)", property_name));
+  REQUIRE_THROWS(controller.trigger(minifi::test::InputFlowFileData{.content = 
"42", .attributes = {}}));
+  CHECK(minifi::test::utils::verifyLogLinePresenceInPollTime(1s,
+      fmt::format("Expected parsable float from RunLlamaCppInference::{}, but 
got GeneralParsingError (Parsing Error:0)", property_name)));
 }
-
+//

Review Comment:
   nitpicking, but this `//` shouldn't be here



##########
libminifi/include/utils/CProcessor.h:
##########
@@ -0,0 +1,176 @@
+/**
+* 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.
+ */
+
+#pragma once
+
+#include <string>
+
+#include "minifi-cpp/core/Annotation.h"
+#include "core/ProcessorMetrics.h"
+#include "minifi-c/minifi-c.h"
+#include "minifi-cpp/agent/agent_docs.h"
+#include "minifi-cpp/core/ProcessContext.h"
+#include "minifi-cpp/core/ProcessorApi.h"
+#include "minifi-cpp/core/ProcessorDescriptor.h"
+#include "minifi-cpp/core/ProcessorMetadata.h"
+
+namespace org::apache::nifi::minifi::utils {
+
+class CProcessor;
+
+class CProcessorMetricsWrapper : public 
minifi::core::ProcessorMetricsExtension {
+ public:
+  explicit CProcessorMetricsWrapper(const CProcessor& source_processor)
+      : source_processor_(source_processor) {
+  }
+
+  std::vector<minifi::state::response::SerializedResponseNode> serialize() 
override;
+
+  std::vector<minifi::state::PublishedMetric> calculateMetrics() override;
+
+ private:
+  const CProcessor& source_processor_;
+};
+
+struct CProcessorClassDescription {
+  std::string name;
+  std::vector<minifi::core::Property> class_properties;
+  std::vector<minifi::core::Relationship> class_relationships;
+  bool supports_dynamic_properties;
+  bool supports_dynamic_relationships;
+  minifi::core::annotation::Input input_requirement;
+  bool is_single_threaded;
+
+  MinifiProcessorCallbacks callbacks;
+};
+
+class CProcessor : public minifi::core::ProcessorApi {
+ public:
+  CProcessor(CProcessorClassDescription class_description, 
minifi::core::ProcessorMetadata metadata)
+      : class_description_(std::move(class_description)),
+        metrics_extension_(std::make_shared<CProcessorMetricsWrapper>(*this)) {
+    metadata_ = metadata;
+    MinifiProcessorMetadata c_metadata;
+    auto uuid_str = metadata.uuid.to_string();
+    c_metadata.uuid = MinifiStringView{.data = uuid_str.data(), .length = 
gsl::narrow<uint32_t>(uuid_str.length())};
+    c_metadata.name = MinifiStringView{.data = metadata.name.data(), .length = 
gsl::narrow<uint32_t>(metadata.name.length())};

Review Comment:
   two more `narrow()`s which can be removed



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to