You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "fgerlits (via GitHub)" <gi...@apache.org> on 2025/08/12 17:12:27 UTC

[PR] MINIFICPP-2589 Refactor ConsumeWindowsEventLog [nifi-minifi-cpp]

fgerlits opened a new pull request, #2007:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2007

   https://issues.apache.org/jira/browse/MINIFICPP-2589
   
   * lots of renaming stuff
   * use magic_enum instead of hand-rolled enum parsing
   * some inlining / pulling out of methods
   * unify the printing of Windows error messages using fmt::format
   
   etc
   
   ---
   
   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [x] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
   
   - [x] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the LICENSE file?
   - [ ] If applicable, have you updated the NOTICE file?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
   


-- 
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


Re: [PR] MINIFICPP-2589 Refactor ConsumeWindowsEventLog [nifi-minifi-cpp]

Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #2007:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2007#discussion_r2304969249


##########
extensions/windows-event-log/ConsumeWindowsEventLog.cpp:
##########
@@ -95,14 +97,36 @@ void ConsumeWindowsEventLog::initialize() {
   setSupportedRelationships(Relationships);
 }
 
-bool ConsumeWindowsEventLog::insertHeaderName(wel::METADATA_NAMES &header, const std::string &key, const std::string & value) {
-  wel::METADATA name = wel::WindowsEventLogMetadata::getMetadataFromString(key);
+wel::HeaderNames ConsumeWindowsEventLog::createHeaderNames(const std::optional<std::string>& event_header_property) const {
+  if (!event_header_property) { return {}; }
+
+  wel::HeaderNames header_names;
+
+  const auto insert_header_name = [&header_names](const std::string& key, const std::string& value) {
+    if (auto metadata = magic_enum::enum_cast<wel::Metadata>(key); metadata) {
+      header_names.emplace_back(*metadata, value);
+      return true;
+    }
+    return false;
+  };
 
-  if (name != wel::METADATA::UNKNOWN) {
-    header.emplace_back(std::make_pair(name, value));
-    return true;
+  auto key_value_pairs = utils::string::split(*event_header_property, ",");
+  for (const auto& key_value_pair : key_value_pairs) {
+    auto key_value = utils::string::split(key_value_pair, "=");
+    if (key_value.size() == 2) {
+      auto key = utils::string::trim(key_value.at(0));
+      auto value = utils::string::trim(key_value.at(1));

Review Comment:
   done: f59b9a5750162c96cc9d23edd6e5bc4a74daae99



-- 
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


Re: [PR] MINIFICPP-2589 Refactor ConsumeWindowsEventLog [nifi-minifi-cpp]

Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #2007:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2007#discussion_r2304969249


##########
extensions/windows-event-log/ConsumeWindowsEventLog.cpp:
##########
@@ -95,14 +97,36 @@ void ConsumeWindowsEventLog::initialize() {
   setSupportedRelationships(Relationships);
 }
 
-bool ConsumeWindowsEventLog::insertHeaderName(wel::METADATA_NAMES &header, const std::string &key, const std::string & value) {
-  wel::METADATA name = wel::WindowsEventLogMetadata::getMetadataFromString(key);
+wel::HeaderNames ConsumeWindowsEventLog::createHeaderNames(const std::optional<std::string>& event_header_property) const {
+  if (!event_header_property) { return {}; }
+
+  wel::HeaderNames header_names;
+
+  const auto insert_header_name = [&header_names](const std::string& key, const std::string& value) {
+    if (auto metadata = magic_enum::enum_cast<wel::Metadata>(key); metadata) {
+      header_names.emplace_back(*metadata, value);
+      return true;
+    }
+    return false;
+  };
 
-  if (name != wel::METADATA::UNKNOWN) {
-    header.emplace_back(std::make_pair(name, value));
-    return true;
+  auto key_value_pairs = utils::string::split(*event_header_property, ",");
+  for (const auto& key_value_pair : key_value_pairs) {
+    auto key_value = utils::string::split(key_value_pair, "=");
+    if (key_value.size() == 2) {
+      auto key = utils::string::trim(key_value.at(0));
+      auto value = utils::string::trim(key_value.at(1));

Review Comment:
   done: 7c023eaea16bfa3356b61c5e897a7d0fdf19b585



-- 
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


Re: [PR] MINIFICPP-2589 Refactor ConsumeWindowsEventLog [nifi-minifi-cpp]

Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #2007:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2007#discussion_r2304913325


##########
extensions/windows-event-log/ConsumeWindowsEventLog.cpp:
##########
@@ -54,9 +50,16 @@
 
 using namespace std::literals::chrono_literals;
 
-namespace org::apache::nifi::minifi::processors {
+namespace {
+struct TimeDiff {
+  auto operator()() const {
+    return std::chrono::steady_clock::now() - time_;
+  }
+  const decltype(std::chrono::steady_clock::now()) time_ = std::chrono::steady_clock::now();
+};

Review Comment:
   done, with a small modification (I changed the outer lambda to a function): a10684bfcdaf1a55a37cf83d480203ef7b70f264



-- 
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


Re: [PR] MINIFICPP-2589 Refactor ConsumeWindowsEventLog [nifi-minifi-cpp]

Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm closed pull request #2007: MINIFICPP-2589 Refactor ConsumeWindowsEventLog
URL: https://github.com/apache/nifi-minifi-cpp/pull/2007


-- 
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


Re: [PR] MINIFICPP-2589 Refactor ConsumeWindowsEventLog [nifi-minifi-cpp]

Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm commented on code in PR #2007:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2007#discussion_r2282748470


##########
extensions/windows-event-log/ConsumeWindowsEventLog.cpp:
##########
@@ -54,9 +50,16 @@
 
 using namespace std::literals::chrono_literals;
 
-namespace org::apache::nifi::minifi::processors {
+namespace {
+struct TimeDiff {
+  auto operator()() const {
+    return std::chrono::steady_clock::now() - time_;
+  }
+  const decltype(std::chrono::steady_clock::now()) time_ = std::chrono::steady_clock::now();
+};

Review Comment:
   I'd do it like this, but you don't need to change it if you don't like it. I started thinking because I found the decltype thing weird.
   ```suggestion
   const auto start_timer = [] {
     return [start_time = std::chrono::steady_clock::now()] {
       return std::chrono::steady_clock::now() - start_time;
     };
   };
   ```



##########
extensions/windows-event-log/ConsumeWindowsEventLog.cpp:
##########
@@ -95,14 +97,36 @@ void ConsumeWindowsEventLog::initialize() {
   setSupportedRelationships(Relationships);
 }
 
-bool ConsumeWindowsEventLog::insertHeaderName(wel::METADATA_NAMES &header, const std::string &key, const std::string & value) {
-  wel::METADATA name = wel::WindowsEventLogMetadata::getMetadataFromString(key);
+wel::HeaderNames ConsumeWindowsEventLog::createHeaderNames(const std::optional<std::string>& event_header_property) const {
+  if (!event_header_property) { return {}; }
+
+  wel::HeaderNames header_names;
+
+  const auto insert_header_name = [&header_names](const std::string& key, const std::string& value) {
+    if (auto metadata = magic_enum::enum_cast<wel::Metadata>(key); metadata) {
+      header_names.emplace_back(*metadata, value);
+      return true;
+    }
+    return false;
+  };
 
-  if (name != wel::METADATA::UNKNOWN) {
-    header.emplace_back(std::make_pair(name, value));
-    return true;
+  auto key_value_pairs = utils::string::split(*event_header_property, ",");
+  for (const auto& key_value_pair : key_value_pairs) {
+    auto key_value = utils::string::split(key_value_pair, "=");
+    if (key_value.size() == 2) {
+      auto key = utils::string::trim(key_value.at(0));
+      auto value = utils::string::trim(key_value.at(1));

Review Comment:
   I see lots of temporary string allocations and deallocations, I think we should minimize those. std::string_view and working with views could be one way.



-- 
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