You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "lordgamez (via GitHub)" <gi...@apache.org> on 2025/01/28 14:18:32 UTC
[PR] MINIFICPP-2502 Add processorBulletins C2 metric node to FlowInformation [nifi-minifi-cpp]
lordgamez opened a new pull request, #1920:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1920
https://issues.apache.org/jira/browse/MINIFICPP-2502
Depends on https://github.com/apache/nifi-minifi-cpp/pull/1918
-------------------------------
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 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-2502 Add processorBulletins C2 metric node to FlowInformation [nifi-minifi-cpp]
Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm closed pull request #1920: MINIFICPP-2502 Add processorBulletins C2 metric node to FlowInformation
URL: https://github.com/apache/nifi-minifi-cpp/pull/1920
--
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-2502 Add processorBulletins C2 metric node to FlowInformation [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #1920:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1920#discussion_r1963297288
##########
minifi-api/include/minifi-cpp/core/logging/Logger.h:
##########
@@ -124,7 +126,8 @@ class Logger {
if (!should_log(level)) {
return;
}
- log_string(level, stringify(std::move(fmt), map_args(std::forward<Args>(args))...));
+ auto message = stringify(std::move(fmt), map_args(std::forward<Args>(args))...);
+ log_string(level, message);
Review Comment:
In a previous iteration it was used in multiple functions, it was left this way by mistake after it was changed, fixed in https://github.com/apache/nifi-minifi-cpp/pull/1920/commits/37c777f93422e963bfe1e159d4f589107084a239
--
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-2502 Add processorBulletins C2 metric node to FlowInformation [nifi-minifi-cpp]
Posted by "szaszm (via GitHub)" <gi...@apache.org>.
szaszm commented on code in PR #1920:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1920#discussion_r1954764926
##########
libminifi/include/core/logging/LoggerBase.h:
##########
@@ -109,6 +140,7 @@ class LoggerBase : public Logger {
private:
std::atomic<int> max_log_size_{LOG_BUFFER_SIZE};
+ std::vector<std::function<void(LOG_LEVEL level, const std::string&)>> log_callbacks_;
Review Comment:
do we need multiple callbacks? If not, I'd say keep it simple and only have one.
##########
minifi-api/include/minifi-cpp/core/logging/Logger.h:
##########
@@ -124,7 +126,8 @@ class Logger {
if (!should_log(level)) {
return;
}
- log_string(level, stringify(std::move(fmt), map_args(std::forward<Args>(args))...));
+ auto message = stringify(std::move(fmt), map_args(std::forward<Args>(args))...);
+ log_string(level, message);
Review Comment:
why this change? it pessimizes the code by forcing another copy
##########
libminifi/include/core/logging/LoggerBase.h:
##########
@@ -80,6 +80,36 @@ inline LOG_LEVEL mapFromSpdLogLevel(spdlog::level::level_enum level) {
throw std::invalid_argument(fmt::format("Invalid spdlog::level::level_enum {}", magic_enum::enum_underlying(level)));
}
+inline std::string mapLogLevelToString(LOG_LEVEL level) {
+ switch (level) {
+ case trace: return "TRACE";
+ case debug: return "DEBUG";
+ case info: return "INFO";
+ case warn: return "WARN";
+ case err: return "ERROR";
+ case critical: return "CRITICAL";
+ case off: return "OFF";
+ }
+ throw std::invalid_argument(fmt::format("Invalid LOG_LEVEL {}", magic_enum::enum_underlying(level)));
+}
+
+inline LOG_LEVEL mapStringToLogLevel(const std::string& level_str) {
+ if (level_str == "TRACE") {
+ return trace;
+ } else if (level_str == "DEBUG") {
+ return debug;
+ } else if (level_str == "INFO") {
+ return info;
+ } else if (level_str == "WARN") {
+ return warn;
+ } else if (level_str == "ERROR") {
+ return err;
+ } else if (level_str == "CRITICAL") {
+ return critical;
+ }
+ throw std::invalid_argument(fmt::format("Invalid LOG_LEVEL {}", level_str));
+}
Review Comment:
This mapping is already defined elsewhere, check LogUtils.h (and maybe rename it if you have a better idea)
--
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-2502 Add processorBulletins C2 metric node to FlowInformation [nifi-minifi-cpp]
Posted by "fgerlits (via GitHub)" <gi...@apache.org>.
fgerlits commented on code in PR #1920:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1920#discussion_r2081865848
##########
libminifi/src/core/state/nodes/FlowInformation.cpp:
##########
@@ -99,6 +102,30 @@ std::vector<SerializedResponseNode> FlowInformation::serialize() {
serialized.push_back(processorsStatusesNode);
}
+ if (bulletin_store_) {
+ SerializedResponseNode processorBulletinsNode{.name = "processorBulletins", .array = true, .collapsible = false};
+ auto bulletins = bulletin_store_->getBulletins(5min);
+ for (const auto& bulletin : bulletins) {
+ processorBulletinsNode.children.push_back({
+ .name = std::to_string(bulletin.id),
+ .collapsible = false,
+ .children = {
+ {.name = "id", .value = bulletin.id},
+ {.name = "timestamp", .value = utils::timeutils::getNiFiDateTimeFormat(std::chrono::time_point_cast<std::chrono::seconds>(bulletin.timestamp))},
Review Comment:
Are we required to truncate timestamps to seconds? Including milliseconds could be useful.
##########
libminifi/include/core/ProcessorConfig.h:
##########
@@ -47,16 +41,11 @@ struct ProcessorConfig {
std::string schedulingPeriod;
std::string penalizationPeriod;
std::string yieldPeriod;
+ std::string bulletinLevel;
Review Comment:
There is another `ProcessorConfig.h`, at `minifi-api/include/minifi-cpp/core/ProcessorConfig.h`. Do we need to add `bulletinLevel` there, too? TBH it's not completely clear to me why we have two of these...
##########
libminifi/src/core/ProcessGroup.cpp:
##########
@@ -485,4 +487,15 @@ ParameterContext* ProcessGroup::getParameterContext() const {
return parameter_context_;
}
+std::string ProcessGroup::buildGroupPath() const {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ std::string path = name_;
+ auto parent = parent_process_group_;
+ while (parent != nullptr) {
+ path.insert(0, parent->getName() + " / ");
Review Comment:
Do we really want to put spaces around the '/'? There aren't any in the path example in BulletinStoreTests.cpp.
##########
libminifi/src/core/BulletinStore.cpp:
##########
@@ -0,0 +1,76 @@
+/**
+ *
+ * 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 "core/BulletinStore.h"
+
+#include "core/logging/LoggerBase.h"
+
+namespace org::apache::nifi::minifi::core {
+
+BulletinStore::BulletinStore(const Configure &configure) {
+ auto max_bulletin_count_str = configure.get(Configuration::nifi_c2_flow_info_processor_bulletin_limit);
+ if (!max_bulletin_count_str) {
+ logger_->log_debug("Bulletin limit not set, using default value of {}", DEFAULT_BULLETIN_COUNT);
+ max_bulletin_count_ = DEFAULT_BULLETIN_COUNT;
+ return;
+ }
+ try {
+ max_bulletin_count_ = std::stoul(*max_bulletin_count_str);
+ } catch(const std::exception&) {
+ logger_->log_warn("Invalid value for bulletin limit, using default value of {}", DEFAULT_BULLETIN_COUNT);
+ max_bulletin_count_ = DEFAULT_BULLETIN_COUNT;
+ }
+}
+
+void BulletinStore::addProcessorBulletin(const core::Processor& processor, core::logging::LOG_LEVEL log_level, const std::string& message) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ Bulletin bulletin;
+ bulletin.id = id_counter++;
+ bulletin.timestamp = std::chrono::system_clock::now();
+ bulletin.level = core::logging::mapLogLevelToString(log_level);
+ bulletin.category = "Log Message";
+ bulletin.message = message;
+ bulletin.group_id = processor.getProcessGroupUUIDStr();
+ bulletin.group_name = processor.getProcessGroupName();
+ bulletin.group_path = processor.getProcessGroupPath();
+ bulletin.source_id = processor.getUUIDStr();
+ bulletin.source_name = processor.getName();
+ if (bulletins_.size() >= max_bulletin_count_) {
+ bulletins_.pop_front();
+ }
+ bulletins_.push_back(std::move(bulletin));
+}
+
+std::deque<Bulletin> BulletinStore::getBulletins(std::optional<std::chrono::system_clock::duration> time_interval_to_include) const {
+ std::lock_guard<std::mutex> lock(mutex_);
+ if (!time_interval_to_include) {
+ return bulletins_;
+ }
+ for (auto it = bulletins_.begin(); it != bulletins_.end(); ++it) {
+ if (std::chrono::system_clock::now() - it->timestamp <= *time_interval_to_include) {
+ return {it, bulletins_.end()};
+ }
+ }
Review Comment:
This arithmetic is difficult for my brain to parse; I would prefer something like this:
```suggestion
const auto timestamp_cutoff = std::chrono::system_clock::now() - *time_interval_to_include;
for (auto it = bulletins_.begin(); it != bulletins_.end(); ++it) {
if (it->timestamp >= timestamp_cutoff) {
return {it, bulletins_.end()};
}
}
```
##########
libminifi/test/unit/BulletinStoreTests.cpp:
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * 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 "unit/TestBase.h"
+#include "unit/Catch.h"
+#include "core/BulletinStore.h"
+#include "properties/Configure.h"
+#include "unit/DummyProcessor.h"
+
+using namespace std::literals::chrono_literals;
+
+namespace org::apache::nifi::minifi::test {
+
+class BulletinStoreTestAccessor {
+ public:
+ static std::deque<core::Bulletin>& getBulletins(core::BulletinStore& store) {
+ return store.bulletins_;
+ }
+};
+
+std::unique_ptr<core::Processor> createDummyProcessor() {
+ auto processor = std::make_unique<DummyProcessor>("DummyProcessor", minifi::utils::Identifier::parse("4d7fa7e6-2459-46dd-b2ba-61517239edf5").value());
+ processor->setProcessGroupUUIDStr("68fa9ae4-b9fc-4873-b0d9-edab59fdb0c2");
+ processor->setProcessGroupName("sub_group");
+ processor->setProcessGroupPath("root/sub_group");
+ return processor;
+}
+
+TEST_CASE("Create BulletinStore with default max size of 1000", "[bulletinStore]") {
+ ConfigureImpl configuration;
+ SECTION("No limit is configured") {}
+ SECTION("Invalid value is configured") {
+ configuration.set(Configure::nifi_c2_flow_info_processor_bulletin_limit, "invalid");
+ }
+ core::BulletinStore bulletin_store(configuration);
+ REQUIRE(bulletin_store.getMaxBulletinCount() == 1000);
+}
+
+TEST_CASE("Create BulletinStore with custom max size of 10000", "[bulletinStore]") {
+ ConfigureImpl configuration;
+ configuration.set(Configure::nifi_c2_flow_info_processor_bulletin_limit, "10000");
+ core::BulletinStore bulletin_store(configuration);
+ REQUIRE(bulletin_store.getMaxBulletinCount() == 10000);
+}
+
+TEST_CASE("Remove oldest entries when limit is reached", "[bulletinStore]") {
+ ConfigureImpl configuration;
+ configuration.set(Configure::nifi_c2_flow_info_processor_bulletin_limit, "2");
+ core::BulletinStore bulletin_store(configuration);
+ auto processor = createDummyProcessor();
+ for (size_t i = 0; i < 3; ++i) {
+ bulletin_store.addProcessorBulletin(*processor, logging::LOG_LEVEL::warn, "Warning message");
+ }
+ auto bulletins = bulletin_store.getBulletins();
+ REQUIRE(bulletins.size() == 2);
+ REQUIRE(bulletins[0].id == 2);
+ REQUIRE(bulletins[1].id == 3);
+ REQUIRE(bulletins[0].message == "Warning message");
+}
+
+TEST_CASE("Return all bulletins when no time interval is defined or all entries are part of the time interval", "[bulletinStore]") {
Review Comment:
Nitpicking, but this test doesn't really test the "... or all entries are part of the time interval" part. I'm OK with either expanding the test or changing the test description, but they should be in sync.
--
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-2502 Add processorBulletins C2 metric node to FlowInformation [nifi-minifi-cpp]
Posted by "lordgamez (via GitHub)" <gi...@apache.org>.
lordgamez commented on code in PR #1920:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1920#discussion_r1963270369
##########
libminifi/include/core/logging/LoggerBase.h:
##########
@@ -80,6 +80,36 @@ inline LOG_LEVEL mapFromSpdLogLevel(spdlog::level::level_enum level) {
throw std::invalid_argument(fmt::format("Invalid spdlog::level::level_enum {}", magic_enum::enum_underlying(level)));
}
+inline std::string mapLogLevelToString(LOG_LEVEL level) {
+ switch (level) {
+ case trace: return "TRACE";
+ case debug: return "DEBUG";
+ case info: return "INFO";
+ case warn: return "WARN";
+ case err: return "ERROR";
+ case critical: return "CRITICAL";
+ case off: return "OFF";
+ }
+ throw std::invalid_argument(fmt::format("Invalid LOG_LEVEL {}", magic_enum::enum_underlying(level)));
+}
+
+inline LOG_LEVEL mapStringToLogLevel(const std::string& level_str) {
+ if (level_str == "TRACE") {
+ return trace;
+ } else if (level_str == "DEBUG") {
+ return debug;
+ } else if (level_str == "INFO") {
+ return info;
+ } else if (level_str == "WARN") {
+ return warn;
+ } else if (level_str == "ERROR") {
+ return err;
+ } else if (level_str == "CRITICAL") {
+ return critical;
+ }
+ throw std::invalid_argument(fmt::format("Invalid LOG_LEVEL {}", level_str));
+}
Review Comment:
As I checked LogUtils.h only contains mappings for the `enum class LogLevelOption`, but not for the `enum LOG_LEVEL`. As I remember we had a brief discussion about standardizing log level representation last year as we have different log level representations in different classes all around the project, but that should be done in a separate PR.
--
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