You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/08/10 15:50:20 UTC

[GitHub] [nifi-minifi-cpp] arpadboda opened a new pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

arpadboda opened a new pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867


   …rated by CWEL
   
   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:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [ ] 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 travis-ci 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.

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



[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867#discussion_r468472628



##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -624,6 +624,24 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
     const std::string& str_;
   };
 
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  std::string tzbias;
+  bool dst = false;
+  switch (ret) {
+  case TIME_ZONE_ID_UNKNOWN:
+    logger_->log_error("Failed to get timezone information!");
+    break;
+  case TIME_ZONE_ID_DAYLIGHT:
+    tzstr = std::wstring(tzinfo.DaylightName, 32);
+    dst = true;

Review comment:
       Good idea, thanks!




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

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



[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867#discussion_r476475183



##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.h
##########
@@ -101,6 +101,7 @@ class ConsumeWindowsEventLog : public core::Processor
   
 
 protected:
+  void refreshTimeZoneData();

Review comment:
       All the internally used functions of the class are protected currently, didn't really want to diverge as it doesn't hurt.




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

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



[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867#discussion_r476467202



##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.h
##########
@@ -138,6 +139,9 @@ class ConsumeWindowsEventLog : public core::Processor
   std::mutex onTriggerMutex_;
   std::unordered_map<std::string, std::string> xmlPercentageItemsResolutions_;
   HMODULE hMsobjsDll_{};
+
+  std::string timezone_name_;
+  std::string timezone_offset_;  // Represented as UTC offset in (H)H:MM format, like +2:00

Review comment:
       ```suggestion
     std::string timezone_offset_;  // Represented as UTC offset in (+|-)HH:MM format, like +02:00
   ```

##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -610,6 +612,36 @@ bool ConsumeWindowsEventLog::createEventRender(EVT_HANDLE hEvent, EventRender& e
   return true;
 }
 
+void ConsumeWindowsEventLog::refreshTimeZoneData() {
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  long tzbias = 0;
+  bool dst = false;
+  switch (ret) {
+    case TIME_ZONE_ID_UNKNOWN:
+      logger_->log_error("Failed to get timezone information!");
+      return;  // Don't update members in case we cannot get data
+    case TIME_ZONE_ID_DAYLIGHT:
+      tzstr = tzinfo.DaylightName;
+      dst = true;
+      // [[fallthrough]];
+    case TIME_ZONE_ID_STANDARD:
+      tzstr = tzstr.empty() ? tzinfo.StandardName : tzstr;  // Use standard timezome name in case there is no daylight name or in case it's not DST
+      tzbias = tzinfo.Bias + (dst ? tzinfo.DaylightBias : tzinfo.StandardBias);
+      break;
+  }
+
+  tzbias *= -1;  // WinApi specifies UTC = localtime + bias, but we need offset from UTC
+  std::stringstream tzoffset;
+  tzoffset << ((tzbias > 0) ? "+" : "") << (tzbias / 60) << ":" << std::setfill('0') << std::setw(2) << (std::abs(tzbias % 60));

Review comment:
       this prints UTC as "0:00" (which is OK, but "+00:00" is more standard) and UTC-0:30 as "0:30" (which is wrong -- this time zone doesn't really exist, but still)
   ```suggestion
     tzofset << (tzbias >= 0 ? '+' : '-') << std::setfill('0') << std::setw(2) << std::abs(tzbias) / 60
         << ":" << std::setfill('0') << std::setw(2) << std::abs(tzbias) % 60;
   ```

##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.h
##########
@@ -101,6 +101,7 @@ class ConsumeWindowsEventLog : public core::Processor
   
 
 protected:
+  void refreshTimeZoneData();

Review comment:
       why not private?




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

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



[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867#discussion_r476436535



##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -624,6 +624,24 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
     const std::string& str_;
   };
 
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  std::string tzbias;
+  bool dst = false;
+  switch (ret) {
+  case TIME_ZONE_ID_UNKNOWN:
+    logger_->log_error("Failed to get timezone information!");
+    break;
+  case TIME_ZONE_ID_DAYLIGHT:
+    tzstr = std::wstring(tzinfo.DaylightName, 32);
+    dst = true;
+  case TIME_ZONE_ID_STANDARD:
+    tzstr = tzstr.empty() ? std::wstring(tzinfo.StandardName, 32) : tzstr;  // Use standard timezome name in case there is no daylight name or in case it's not DST
+    tzbias = std::to_string(tzinfo.Bias + (dst ? tzinfo.DaylightBias : 0));

Review comment:
       Done

##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -635,6 +653,8 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
       }
     }
     session.putAttribute(flowFile, FlowAttributeKey(MIME_TYPE), "application/xml");
+    session.putAttribute(flowFile, "Timezone name", wel::to_string(tzstr.c_str()));
+    session.putAttribute(flowFile, "Timezone bias", tzbias);

Review comment:
       Done




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

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



[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867#discussion_r468404494



##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -624,6 +624,24 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
     const std::string& str_;
   };
 
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  std::string tzbias;
+  bool dst = false;
+  switch (ret) {
+  case TIME_ZONE_ID_UNKNOWN:
+    logger_->log_error("Failed to get timezone information!");
+    break;
+  case TIME_ZONE_ID_DAYLIGHT:
+    tzstr = std::wstring(tzinfo.DaylightName, 32);
+    dst = true;
+  case TIME_ZONE_ID_STANDARD:
+    tzstr = tzstr.empty() ? std::wstring(tzinfo.StandardName, 32) : tzstr;  // Use standard timezome name in case there is no daylight name or in case it's not DST
+    tzbias = std::to_string(tzinfo.Bias + (dst ? tzinfo.DaylightBias : 0));
+    break;
+  }

Review comment:
       lines 627-643 are quite self-contained, they could be in a separate function

##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -624,6 +624,24 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
     const std::string& str_;
   };
 
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  std::string tzbias;
+  bool dst = false;
+  switch (ret) {
+  case TIME_ZONE_ID_UNKNOWN:
+    logger_->log_error("Failed to get timezone information!");
+    break;
+  case TIME_ZONE_ID_DAYLIGHT:
+    tzstr = std::wstring(tzinfo.DaylightName, 32);
+    dst = true;
+  case TIME_ZONE_ID_STANDARD:
+    tzstr = tzstr.empty() ? std::wstring(tzinfo.StandardName, 32) : tzstr;  // Use standard timezome name in case there is no daylight name or in case it's not DST
+    tzbias = std::to_string(tzinfo.Bias + (dst ? tzinfo.DaylightBias : 0));

Review comment:
       The time zone offset is usually formatted as e.g. `+01:00` and `-05:00`; printing it as `60` and `-300` might confuse users.




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

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



[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867#discussion_r476465535



##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -610,6 +612,36 @@ bool ConsumeWindowsEventLog::createEventRender(EVT_HANDLE hEvent, EventRender& e
   return true;
 }
 
+void ConsumeWindowsEventLog::refreshTimeZoneData() {
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  long tzbias = 0;
+  bool dst = false;
+  switch (ret) {
+    case TIME_ZONE_ID_UNKNOWN:
+      logger_->log_error("Failed to get timezone information!");
+      return;  // Don't update members in case we cannot get data
+    case TIME_ZONE_ID_DAYLIGHT:
+      tzstr = tzinfo.DaylightName;
+      dst = true;
+      // [[fallthrough]];
+    case TIME_ZONE_ID_STANDARD:
+      tzstr = tzstr.empty() ? tzinfo.StandardName : tzstr;  // Use standard timezome name in case there is no daylight name or in case it's not DST
+      tzbias = tzinfo.Bias + (dst ? tzinfo.DaylightBias : tzinfo.StandardBias);
+      break;
+  }
+
+  tzbias *= -1;  // WinApi specifies UTC = localtime + bias, but we need offset from UTC
+  std::stringstream tzoffset;
+  tzoffset << ((tzbias > 0) ? "+" : "") << (tzbias / 60) << ":" << std::setfill('0') << std::setw(2) << (std::abs(tzbias % 60));

Review comment:
       this prints UTC as "0:00" (which is OK, but "+00:00" is more standard) and UTC-0:30 as "0:30" (which is wrong -- this time zone doesn't really exist, but still)
   ```suggestion
     tzoffset << (tzbias >= 0 ? '+' : '-') << std::setfill('0') << std::setw(2) << std::abs(tzbias) / 60
         << ":" << std::setfill('0') << std::setw(2) << std::abs(tzbias) % 60;
   ```




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

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



[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867#discussion_r468475216



##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -624,6 +624,24 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
     const std::string& str_;
   };
 
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  std::string tzbias;
+  bool dst = false;
+  switch (ret) {
+  case TIME_ZONE_ID_UNKNOWN:
+    logger_->log_error("Failed to get timezone information!");
+    break;
+  case TIME_ZONE_ID_DAYLIGHT:
+    tzstr = std::wstring(tzinfo.DaylightName, 32);
+    dst = true;
+  case TIME_ZONE_ID_STANDARD:
+    tzstr = tzstr.empty() ? std::wstring(tzinfo.StandardName, 32) : tzstr;  // Use standard timezome name in case there is no daylight name or in case it's not DST
+    tzbias = std::to_string(tzinfo.Bias + (dst ? tzinfo.DaylightBias : 0));

Review comment:
       Agreed, good spot, thanks!




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

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



[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867#discussion_r468403837



##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -624,6 +624,24 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
     const std::string& str_;
   };
 
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  std::string tzbias;
+  bool dst = false;
+  switch (ret) {
+  case TIME_ZONE_ID_UNKNOWN:
+    logger_->log_error("Failed to get timezone information!");
+    break;
+  case TIME_ZONE_ID_DAYLIGHT:
+    tzstr = std::wstring(tzinfo.DaylightName, 32);
+    dst = true;

Review comment:
       I would put a `// [[fallthrough]];` comment after this line (and remove the `//` when we upgrade to c++17)

##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -635,6 +653,8 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
       }
     }
     session.putAttribute(flowFile, FlowAttributeKey(MIME_TYPE), "application/xml");
+    session.putAttribute(flowFile, "Timezone name", wel::to_string(tzstr.c_str()));
+    session.putAttribute(flowFile, "Timezone bias", tzbias);

Review comment:
       I would call this "Timezone offset".  I think "bias" and "daylight bias" are Microsoft coinages for the two components of the offset, but here we are printing their sum.

##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -624,6 +624,24 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
     const std::string& str_;
   };
 
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  std::string tzbias;
+  bool dst = false;
+  switch (ret) {
+  case TIME_ZONE_ID_UNKNOWN:
+    logger_->log_error("Failed to get timezone information!");
+    break;
+  case TIME_ZONE_ID_DAYLIGHT:
+    tzstr = std::wstring(tzinfo.DaylightName, 32);
+    dst = true;
+  case TIME_ZONE_ID_STANDARD:
+    tzstr = tzstr.empty() ? std::wstring(tzinfo.StandardName, 32) : tzstr;  // Use standard timezome name in case there is no daylight name or in case it's not DST
+    tzbias = std::to_string(tzinfo.Bias + (dst ? tzinfo.DaylightBias : 0));

Review comment:
       It may just be a fancy alias for zero, but `DYNAMIC_TIME_ZONE_INFORMATION` has a `StandardBias` field.  So this could be written nicer (and possibly safer) as `dst ? tzinfo.DaylightBias : tzinfo.StandardBias`




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

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



[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867#discussion_r476436906



##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -624,6 +624,24 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
     const std::string& str_;
   };
 
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  std::string tzbias;
+  bool dst = false;
+  switch (ret) {
+  case TIME_ZONE_ID_UNKNOWN:
+    logger_->log_error("Failed to get timezone information!");
+    break;
+  case TIME_ZONE_ID_DAYLIGHT:
+    tzstr = std::wstring(tzinfo.DaylightName, 32);
+    dst = true;
+  case TIME_ZONE_ID_STANDARD:
+    tzstr = tzstr.empty() ? std::wstring(tzinfo.StandardName, 32) : tzstr;  // Use standard timezome name in case there is no daylight name or in case it's not DST
+    tzbias = std::to_string(tzinfo.Bias + (dst ? tzinfo.DaylightBias : 0));
+    break;
+  }

Review comment:
       Moved and made a bit smarter to only do it once per onTrigger calls, not per event. 




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

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



[GitHub] [nifi-minifi-cpp] szaszm closed pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
szaszm closed pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867


   


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

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



[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #867: MINIFICPP-1327 - Add timezone information as attribute to flowfiles c…

Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #867:
URL: https://github.com/apache/nifi-minifi-cpp/pull/867#discussion_r468284137



##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -624,6 +624,24 @@ void ConsumeWindowsEventLog::putEventRenderFlowFileToSession(const EventRender&
     const std::string& str_;
   };
 
+  DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
+  auto ret = GetDynamicTimeZoneInformation(&tzinfo);
+  std::wstring tzstr;
+  std::string tzbias;
+  bool dst = false;
+  switch (ret) {
+  case TIME_ZONE_ID_UNKNOWN:
+    logger_->log_error("Failed to get timezone information!");
+    break;
+  case TIME_ZONE_ID_DAYLIGHT:
+    tzstr = std::wstring(tzinfo.DaylightName, 32);
+    dst = true;
+  case TIME_ZONE_ID_STANDARD:
+    tzstr = tzstr.empty() ? std::wstring(tzinfo.StandardName, 32) : tzstr;  // Use standard timezome name in case there is no daylight name or in case it's not DST

Review comment:
       Using the `const CharT*` + `size_t` constructor means that the resulting string will always be of the specified length and may include null characters and other garbage. I think this is not what you wanted here.




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

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